Показать сообщение отдельно
Старый 22.02.2013, 03:02   #94
Kamik
Junior Member
 
Регистрация: 18.02.2013
Сообщений: 25
По умолчанию

код для запуска как демон.
положить в /etc/init.d/tsengine
дать права на запуск chmod +x /etc/init.d/tsengine
прописать в автозапуск update-rc.d tsengine defaults

Код:
#!/bin/sh

### BEGIN INIT INFO
# Provides:             acestreamengine
# Required-Start:       $local_fs $remote_fs
# Required-Stop:        $local_fs $remote_fs
# Should-Start:         $network
# Should-Stop:          $network
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Daemonized version of acestreamengine
# Description:          Starts the acestreamengine daemon
#
### END INIT INFO

#PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="ACEStream Engine Daemon" 
NAME1="acestreamengine-client-console" 
PIDFILE1=/var/run/$NAME1.pid
LOG1=/var/log/acestreamengine.log

. /lib/lsb/init-functions
# Start ACEstreamengine-client-console in daemon mode
start(){
 ACEENGINEPID=`ps aux | grep "$NAME1" | grep -v grep | awk '{print $2}'`
        echo $ACEENGINEPID
        if [ "x$ACEENGINEPID" = "x" ] && [ -f $PIDFILE1 ]; then
                echo "" >> $LOG1
                echo `date` " * No $NAME1 process found... but PID file left in $PIDFILE1" | tee -a $LOG1
                echo "Deleting PID!" | tee -a $LOG1
                echo "" >> $LOG1
                rm $PIDFILE1
        elif [ "x$ACEENGINEPID" != "x" ]; then
                echo `date` " * $NAME1 appears to be already running!" | tee -a $LOG1
                exit
        fi
        #su - root -c "$NAME1 &" 
        `$NAME1` &
        echo `date` " * Starting $NAME1..." | tee -a $LOG1
        ACEENGINEPID=`ps aux | grep "$NAME1" | grep -v grep | awk '{print $2}'`
        if [ "x$ACEENGINEPID" = "x" ]; then
                echo `date` " * $NAME1 failed to start!" | tee -a $LOG1
                exit
        fi
}
# Stop ACEstreamengine-client-console daemon
stop(){
        ACEENGINEPID=`ps aux | grep "$NAME1" | grep -v grep | awk '{print $2}'`
        echo $ACEENGINEPID
        if [ "x$ACEENGINEPID" != "x" ]; then
                kill -2 $ACEENGINEPID
                echo `date` " * Stopping $NAME1..." | tee -a $LOG1
                ACEENGINEPID=`ps aux | grep "$NAME1" | grep -v grep | awk '{print $2}'`
                if [ "x$ACEENGINEPID" != "x" ]; then
                        echo `date` " * $NAME1 stopped..." | tee -a $LOG1
                elif [ "x$ACEENGINEPID" = "x" ]; then
                        echo `date` " * $NAME1 failed to stop!" | tee -a $LOG1
                fi
        elif [ "x$ACEENGINEPID" = "x" ]; then
                echo `date` >> $LOG1
                echo "" >> $LOG1
                echo " * $NAME1 does not appear to be running!" | tee -a $LOG1
                exit
        fi
}
# Check if ACEstreamengine-client-console is running
status(){
        ACEENGINEPID=`ps aux | grep "$NAME1" | grep -v grep | awk '{print $2}'`
        if [ "x$ACEENGINEPID" = "x" ]; then
                echo " * $NAME1 is not running" 
        else
                echo " * $NAME1 is running" 
        fi
}
case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        status)
                status
                ;;
        restart|force-reload)
                stop
                start
                ;;
        *)
                echo "Usage: $0 {start|stop|restart|force-reload|status}" 
                exit 1
esac
Kamik вне форума   Ответить с цитированием