I simply cannot find out why SABnzbd will start without a fuss after a restart of my server and when the service gets stopped it won’t start again until I reboot. Weird thing is though, if I just run SABnzbd.py it will run without any problems, it just won’t start via the init script. Most likely there’s some garbage leftover somewhere but I just cannot find it so I wrote a quick and dirty new init script. I might improve on it somewhat, I could for example create the /var/run/ sub-directory if it doesn’t exist but I wrote this on the crapper and I just wiped (too much information?) so it will have to do for now. So without further ado, here it is;

#!/bin/bash
#
### BEGIN INIT INFO
# Provides:          SABnzbd
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts SABnzbd
# Description:       starts SABnzbd
### END INIT INFO

user="kodi"
conf="~$user/.sabnzbd/sabnzbd.ini"
prog="SABnzbd"
bin="/usr/bin/SABnzbd"
pid="/var/run/sabnzbd/sabnzbd.pid"
pidpath="/var/run/sabnzbd/"
options=" --daemon --config-file $conf --pidfile $pid"
run="$bin $options"

start () {
  echo -n $"Starting $prog..."
  echo
  if [ ! -d $pidpath ]; then
    mkdir -p $pidpath
    chown $user: $pidpath
  fi
  su $user -c "$run"
}

stop () {
  echo -n $"Shutting down $prog..."
  echo
  kill -TERM `cat $pid`
  rm -f $pid
}

status () {
  if [[ -f $pid ]]; then
    if ps -p $(cat $pid) > /dev/null; then
      echo "$prog is running."
    fi
  else
    echo "$prog is not running."
  fi
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status
    ;;
  restart)
    stop
    start
    ;;
  *)
    echo $"Usage: $0 {start|stop|status|restart}"
    exit 2
esac
New init script for SABnzbd on CentOS