Page 1 of 1

Startup Daemon

Posted: January 13th, 2010, 4:18 pm
by auskento
Hi,

I have been using a basic shell script to start SAB on my gentoo box, and am trying to change that to use the start-stop-daemon as I am wanting to use some PID tracking for monit.

Code: Select all

#!/sbin/runscript
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

opts="start stop"

depend() {
    need net
}

start() {
    ebegin "Starting SABnzbd+"
    if ! check_config ; then
        eend 1
        return 1
    fi

    start-stop-daemon --quiet --start -c ${SAB_USER}:${SAB_GROUP} \
        --exec /SABAlpha/SABnzbd.py -- -d -f ${INIFILE} &> /dev/null
    eend $?
}

stop() {
    ebegin "Stopping SABnzbd+"
        /usr/bin/wget -q --delete-after "http://${SAB_HOST}:${SAB_PORT}/sabnzbd/api?mode=shutdown"
    eend $?
}

check_config() {
    if [ ! -e ${SAB_CONFIGFILE} ] ; then
        eerror "ERROR: can't find ${SAB_CONFIGFILE}."
        return 1
    else
        return 0
    fi
}
I have created the configfile /etc/conf.d/sab with the variables listed above.

I cannot however get sab to start.  I always get a [!!] in the start up, but can't find any way of getting more information as to why it is failing.

My normal runscript, has been running as root (yes i know not a good idea) and I am wanting to change that too.
I have created a new user and group called sabnzbd, but I dont actually know how to get this part operational (hence why i was using root :P)

The really strange part of all this, is that sometimes SAB is running from a ps -ax, but if i do a /etc/init.d/sab stop, it says sab isnt running.

Re: Startup Daemon

Posted: January 13th, 2010, 4:39 pm
by shypike
You aren't trying to use a restricted low port number (like 80) ?

Re: Startup Daemon

Posted: January 13th, 2010, 5:26 pm
by auskento
No its set to run on port 9999

Re: Startup Daemon

Posted: January 14th, 2010, 4:49 am
by jcfp
auskento wrote:[...] trying to change that to use the start-stop-daemon as I am wanting to use some PID tracking for monit.
1) Careful: with -d, the program forks in order to run in the background while start-stop-daemon only sees the initial instance (=different pid). A possible workaround finds the pid using pgrep after start-stop-daemon returns successfully along the lines of:

Code: Select all

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
2) Better not devnull output in start() if you're trying to debug it.
3) Handle issues of running as non-root and using s-s-d one at a time, mixing those can easily get confusing.
4) When shutting down via s-s-daemon (not in the code you posted, I know), it may have trouble finding the correct instance if sab has been restarted from its interface (changes pid, may also change command line options and program name in /proc)