Startup Daemon

Get help with all aspects of SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
auskento
Moderator
Moderator
Posts: 77
Joined: January 21st, 2008, 8:45 pm
Location: Melbourne, AUS

Startup Daemon

Post 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.
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Startup Daemon

Post by shypike »

You aren't trying to use a restricted low port number (like 80) ?
auskento
Moderator
Moderator
Posts: 77
Joined: January 21st, 2008, 8:45 pm
Location: Melbourne, AUS

Re: Startup Daemon

Post by auskento »

No its set to run on port 9999
User avatar
jcfp
Release Testers
Release Testers
Posts: 1004
Joined: February 7th, 2008, 12:45 pm

Re: Startup Daemon

Post 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)
Last edited by jcfp on January 14th, 2010, 4:53 am, edited 1 time in total.
Post Reply