Apertium has moved from SourceForge to GitHub.
If you have any questions, please come and talk to us on #apertium on irc.freenode.net or contact the GitHub migration team.

Apertium-apy/Sysvinit issues

From Apertium
Jump to: navigation, search

Contents

[edit] What we want

An init script for apertium-apy that starts the and stops the daemon, and preferably logs its stdout and stderr.

[edit] The problems

[edit] Logging

Can't figure out how to log stdout or stderr with start-stop-daemon (if it's not possible I'll eat my hat, but I'm just can't find the appropriate information on how to do this)

[edit] Subprocesses are not being killed when the parent process is killed

The parent process pid is kept track of and sent a kill signal. However, the server thread(s) runs in its own pid(s), and these remain running even after the parent thread is killed. We found what we thought is a work-around, but it seems to just make sure the parent thread and other children are killed when one child is killed.

[edit] The current init script

#!/bin/bash
#
# bot initscript
#
# Last Updated: Oct 31, 2011
# Modified for Apertium on Jan 11, 2014
# If broken, yell at: firespeaker
#

### BEGIN INIT INFO
# Provides:             apy
# Required-Start:       $network
# Required-Stop:        $network
# Default-Start:        3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Apertium APY, Apertium API in Python
### END INIT INFO

SERVLET="servlet.py"
EXEC="/traductors/apertium-apy/"
ARGS="-l tools/turkic.db ../pairs"
USER="www-data"

start_apy() {
    start-stop-daemon -S -c $USER -p /var/run/$SERVLET.pid -m -d $EXEC -b -x $EXEC/$SERVLET -- $ARGS
    SUCCESS=$?
    if [ $SUCCESS -gt 0 ]; then
        echo "ERROR: Couldn't start $SERVLET"
    fi
    return $SUCCESS
}

stop_apy() {
    start-stop-daemon -K -p /var/run/$SERVLET.pid
    SUCCESS=$?
    if [ $SUCCESS -gt 0 ]; then
        echo "ERROR: Couldn't stop $SERVLET"
    fi
    return $SUCCESS
}

case "$1" in
    start)
        echo "Starting $SERVLET"
        start_apy
        ;;
    stop)
        echo "Stopping $SERVLET"
        stop_apy
        ;;
    restart)
        echo "Restarting $SERVLET"
        stop_apy
        if [ $? -gt 0 ]; then
            exit -1
        fi
        start_apy
        ;;
    force-reload)
        echo "Restarting $SERVLET"
        stop_apy
        if [ $? -gt 0 ]; then
            exit -1
        fi
        start_apy
        ;;
    status)
        if [ -e /var/run/$SERVLET.pid ]; then
            exit 0
        fi
        exit 3
        ;;
    *)
        echo "Usage: /etc/init.d/$SERVLET {start, stop, restart, force-reload, status}"
        exit 1
        ;;
esac

exit 0
Personal tools