Page 1 of 1

[Solved]Debian - sabnzbdplus only runs when manually started

Posted: May 24th, 2013, 5:20 pm
by milomak
So I am running the below on a stable system

Code: Select all

# apt-cache policy sabnzbdplus
sabnzbdplus:
  Installed: 0.6.15-1
  Candidate: 0.6.15-1
  Version table:
 *** 0.6.15-1 0
        500 http://debian.mirror.ac.za/debian/ stable/contrib amd64 Packages
        100 /var/lib/dpkg/status
When the system boots, it shows the service starts with an ok. yet when i run ps aux | grep sabnzb, it shows it is not running.

the service is listed as follows

Code: Select all

# ls -la /etc/{rc?.d,init.d,default}/*sabnzbdplus
-rw-r--r-- 1 root root  760 May 20 23:57 /etc/default/sabnzbdplus
-rwxr-xr-x 1 root root 3498 Dec  8  2011 /etc/init.d/sabnzbdplus
lrwxrwxrwx 1 root root   21 May 20 23:52 /etc/rc0.d/K01sabnzbdplus -> ../init.d/sabnzbdplus
lrwxrwxrwx 1 root root   21 May 20 23:52 /etc/rc1.d/K01sabnzbdplus -> ../init.d/sabnzbdplus
lrwxrwxrwx 1 root root   21 May 20 23:52 /etc/rc2.d/S11sabnzbdplus -> ../init.d/sabnzbdplus
lrwxrwxrwx 1 root root   21 May 20 23:52 /etc/rc3.d/S11sabnzbdplus -> ../init.d/sabnzbdplus
lrwxrwxrwx 1 root root   21 May 20 23:52 /etc/rc4.d/S11sabnzbdplus -> ../init.d/sabnzbdplus
lrwxrwxrwx 1 root root   21 May 20 23:52 /etc/rc5.d/S11sabnzbdplus -> ../init.d/sabnzbdplus
lrwxrwxrwx 1 root root   21 May 20 23:52 /etc/rc6.d/K01sabnzbdplus -> ../init.d/sabnzbdplus
and then as root, when i run /etc/init.d/sabnzbdplus start the daemon starts.

i also have a crontab that checks if sabnzbplus is running

Code: Select all

*/5 * * * * /usr/local/bin/check-sabnzb >> /root/check-sabnzb.log
some output from the log file shows

Code: Select all

Starting SABnzbd+ binary newsgrabber: failed!
Starting SABnzbd+ binary newsgrabber: failed!
Starting SABnzbd+ binary newsgrabber: failed!
yet when i run the same crontab entry manually the daemon starts.

you may also have noticed above that the start-level is 11. which happens to be before network manager. but no matter what i try, i am unable to change the start level

Code: Select all

# update-rc.d sabnzbdplus start 20 2 3 4 5 stop 01 0 1 6
update-rc.d: using dependency based boot sequencing
# ls -la /etc/{rc?.d,init.d,default}/*sabnzbdplus
-rw-r--r-- 1 root root  760 May 20 23:57 /etc/default/sabnzbdplus
-rwxr-xr-x 1 root root 3498 Dec  8  2011 /etc/init.d/sabnzbdplus
lrwxrwxrwx 1 root root   21 May 20 23:52 /etc/rc0.d/K01sabnzbdplus -> ../init.d/sabnzbdplus
lrwxrwxrwx 1 root root   21 May 20 23:52 /etc/rc1.d/K01sabnzbdplus -> ../init.d/sabnzbdplus
lrwxrwxrwx 1 root root   21 May 20 23:52 /etc/rc2.d/S11sabnzbdplus -> ../init.d/sabnzbdplus
lrwxrwxrwx 1 root root   21 May 20 23:52 /etc/rc3.d/S11sabnzbdplus -> ../init.d/sabnzbdplus
lrwxrwxrwx 1 root root   21 May 20 23:52 /etc/rc4.d/S11sabnzbdplus -> ../init.d/sabnzbdplus
lrwxrwxrwx 1 root root   21 May 20 23:52 /etc/rc5.d/S11sabnzbdplus -> ../init.d/sabnzbdplus
lrwxrwxrwx 1 root root   21 May 20 23:52 /etc/rc6.d/K01sabnzbdplus -> ../init.d/sabnzbdplus
what am i missing here?

Re: Debian - sabnzbdplus only runs when manually started

Posted: May 24th, 2013, 5:24 pm
by milomak
Here is the init.d script

Code: Select all

# cat /etc/init.d/sabnzbdplus 
#!/bin/sh
#
# Copyright (C) 2008-2011 by JCF Ploemen <[email protected]>
# released under GPL, version 2 or later

################################################
#                                              #
#  TO CONFIGURE EDIT /etc/default/sabnzbdplus  #
#                                              #
################################################

### BEGIN INIT INFO
# Provides:          sabnzbdplus
# Required-Start:    $local_fs $network $remote_fs
# Required-Stop:     $local_fs $network $remote_fs
# Should-Start:      NetworkManager
# Should-Stop:       NetworkManager
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: SABnzbd+ binary newsgrabber
# Description:       SABnzbd+ is a web-based binary newsgrabber with nzb
#                    support, designed to download files from Usenet.
#                    This script provides that functionality as a system
#                    service, starting the program on boot.
### END INIT INFO

DAEMON=/usr/bin/sabnzbdplus
SETTINGS=/etc/default/sabnzbdplus

([ -x $DAEMON ] && [ -r $SETTINGS ]) || exit 0

DESC="SABnzbd+ binary newsgrabber"
DEFOPTS="--daemon"
PYTHONEXEC="^$(sed -n '1s/^#\!\([a-z0-9\.\/]\+\)\(.*\)/\1(\2)?/p' $DAEMON)"
PIDFILE=/var/run/sabnzbdplus.pid
SETTINGS_LOADED=FALSE

# these are only accepted from the settings file
unset USER CONFIG HOST PORT EXTRAOPTS

. /lib/lsb/init-functions

check_retval() {
        if [ $? -eq 0 ]; then
                log_end_msg 0
                return 0
        else
                log_end_msg 1
                exit 1
        fi
}

is_running() {
        # returns 0 when running, 1 otherwise
        PID="$(pgrep -f -x -u ${USER%:*} "$PYTHONEXEC $DAEMON $DEFOPTS.*")"
        RET=$?
        [ $RET -gt 1 ] && exit 1 || return $RET
}

load_settings() {
        if [ $SETTINGS_LOADED != "TRUE" ]; then
                . $SETTINGS

                [ -z "$USER" ] && {
                        log_warning_msg "$DESC: not configured, aborting. See $SETTINGS";
                        return 1; }
                [ -z "${USER%:*}" ] && exit 1

                OPTIONS="$DEFOPTS"
                [ -n "$CONFIG" ] && OPTIONS="$OPTIONS --config-file $CONFIG"
                [ -n "$HOST" ] && SERVER="$HOST" || SERVER=
                [ -n "$PORT" ] && SERVER="$SERVER:$PORT"
                [ -n "$SERVER" ] && OPTIONS="$OPTIONS --server $SERVER"
                [ -n "$EXTRAOPTS" ] && OPTIONS="$OPTIONS $EXTRAOPTS"
                SETTINGS_LOADED=TRUE
        fi
        return 0
}

start_sab() {
        load_settings || exit 0
        if ! is_running; then
                log_daemon_msg "Starting $DESC"
                start-stop-daemon --quiet --chuid $USER --start --exec $DAEMON -- $OPTIONS
                check_retval
                # create a pidfile; we don't use it but some monitoring app likes to have one
                [ -w $(dirname $PIDFILE) ] && \
                        pgrep -f -x -n -u ${USER%:*} "$PYTHONEXEC $DAEMON $OPTIONS" > $PIDFILE
        else
                log_success_msg "$DESC: already running (pid $PID)"
        fi
}

stop_sab() {
        load_settings || exit 0
        if is_running; then
                TMPFILE="$(mktemp --tmpdir sabnzbdplus.XXXXXXXXXX)"
                [ $? -eq 0 ] || exit 1
                trap '[ -f "$TMPFILE" ] && rm -f "$TMPFILE"' EXIT
                echo "$PID" > "$TMPFILE"
                log_daemon_msg "Stopping $DESC"
                start-stop-daemon --stop --user ${USER%:*} --pidfile "$TMPFILE" --retry 30
                check_retval
        else
                log_success_msg "$DESC: not running"
        fi
        [ -f $PIDFILE ] && rm -f $PIDFILE
}

case "$1" in
        start)
                start_sab
        ;;
        stop)
                stop_sab
        ;;
        force-reload|restart)
                stop_sab
                start_sab
        ;;
        status)
                load_settings || exit 4
                if is_running; then
                        log_success_msg "$DESC: running (pid $PID)"
                else
                        log_success_msg "$DESC: not running"
                        [ -f $PIDFILE ] && exit 1 || exit 3
                fi
        ;;
        *)
                log_failure_msg "Usage: $0 {start|stop|restart|force-reload|status}"
                exit 3
        ;;
esac

exit 0

Re: Debian - sabnzbdplus only runs when manually started

Posted: May 24th, 2013, 7:04 pm
by jcfp
Such are the niceties of dependency based booting. Backup the init script, then try replacing it with the one found here (or edit the existing one in place - the relevant changes are in the INIT INFO part). After that:

Code: Select all

sudo update-rc.d sabnzbdplus remove
sudo update-rc.d sabnzbdplus defaults
This should move the service to somewhat later in the startup sequence. If it doesn't, try changing to "Required-Start: $all" and then repeat above commands.

The failure to start from cron is most likely related to differences in the environment provided by init, your shell, and crontab. Nothing I can fix or prevent.

Re: Debian - sabnzbdplus only runs when manually started

Posted: May 25th, 2013, 11:08 am
by milomak
thanks. that init script has done the trick.

as for the script called by cron, it just runs a check to see if sabnzbdplus is running

Code: Select all

# cat /usr/local/bin/check-sabnzb 
#!/bin/bash
if ! pgrep sabnzbdplus; then
/etc/init.d/sabnzbdplus start
fi
will see what happens with the new init script

Re: Debian - sabnzbdplus only runs when manually started

Posted: May 25th, 2013, 11:52 am
by jcfp
I don't expect it to behave any different with cron. Maybe using 'invoke-rc.d' in your check-sabnzb script instead of calling the init script directly helps.