Post Tue May 14, 2013 4:30 pm

Debian daemon startup script.

Hey I know there are a few threads on this issue, though they use a simple start up script that I used to use but have since migrated away from. My current script will start serviio on boot without a problem. The issue I am having is the script doesn't seem to close, this is not a huge problem as the server is headless, but when I need to console the server the startup script for serviio is still 'loading' and won't exit, even though serviio is up. I am also unable to get serviio to stop through it. It does not produce any errors, just nothing happens. Any help would be appreciated.


  Code:
admin@akakios:~$ cat /etc/init.d/serviiodaemon
# serviio as service at boot time
#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          networking
# Required-Start:
# Required-Stop:     $local_fs
# Should-Start:      ifupdown
# Should-Stop:       ifupdown
# Default-Start:     2 4 5
# Default-Stop:      0
# Short-Description: Raise network interfaces.
### END INIT INFO
running() {
    if [ "x$1" == "x" ]; then
          echo 0
          return 1
    fi

    PS=$(ps h -p $(echo $1 | sed -r 's/[\t \n]+/ -p /') | wc -l)
    echo $PS

    if [ $PS -gt 0 ]; then
          return 0
    else
          return 1
    fi
    }



SERVIIODAEMON_USERS="root"
start() {
    echo "Starting Serviio..."
    for dbuser in $SERVIIODAEMON_USERS; do
        start-stop-daemon -b -o -c $dbuser -S -x /opt/serviio/bin/serviio.sh
    done
}

#stop() {
#    echo "Stopping Serviio..."
#    for dbuser in $SERVIIODAEMON_USERS; do
#        start-stop-daemon -o -c $dbuser -K -x /opt/serviio/bin/serviio.sh stop
#    done
#}
stop() {
            echo "Stopping Serviio media server daemon" "$NAME"
            if [ -r "$PIDFILE" ]; then
                    PIDS=$(pstree -p $(<"$PIDFILE") | awk -F'[\(\)]' '/^[A-Za-z0-9]/ { print $2" "$4; }')
                    if running "$PIDS" > /dev/null; then
                            "${DAEMON}" "${DAEMON_STOP}"
                            for PID in $PIDS; do
                                    if running $PID > /dev/null; then
                                            kill -TERM $PID
                                    fi
                            done
                    fi
                    COUNTDOWN=$TIMEOUT
                    while let COUNTDOWN--; do
                            if ! running "$PIDS" > /dev/null; then
                                    break
                            fi
                            if [ $COUNTDOWN -eq 0 ]; then
                                    for PID in $PIDS; do
                                            if running $PID > /dev/null; then
                                                    kill -KILL $PID
                                            fi
                                    done
                            else
                                    echo -n .
                                    sleep 1
                            fi
                    done
            fi

            if running "$PIDS" > /dev/null; then
                    log_end_msg 1
            else
                    rm -f "$PIDFILE"
            fi
    }


status() {
    for dbuser in $SERVIIODAEMON_USERS; do
        dbpid=`pgrep -u $dbuser serviio`
        if [ -z $dbpid ] ; then
            echo "serviio for USER $dbuser: not running."
        else
            echo "serviio for USER $dbuser: running."
        fi
    done
}


case "$1" in
  start)
    start
    ;;
 
  stop)
    stop
    ;;

  restart|reload|force-reload)
    stop
    start
    ;;

  status)
    status
    ;;

  *)
    echo "Usage: /etc/init.d/serviiodaemon {start|stop|reload|force-reload|restart|status}"
    exit 1

esac

exit 0
admin@akakios:~$