Arch Linux Sick Beard init script

Sick Beard is a nice open source PVR for newsgroup users which keeps track of your favourite TV shows. The website is located here. The source is available at github.

I noticed that there are a lot of strange init script examples out there to start and stop Sick Beard as a daemon under Linux. For Arch Linux I found multiple that use sudo to start and wget or curl to stop the program using the HTTP interface. Why would you possibly want to do that in the first place?

If you take a quick look in the executable Python script you’ll notice that Sick Beard provides a way to start as a daemon and also the option to create a PID file exists. With those two command line switches and the knowledge that the program is able to handle signals I decided it would be nice to write my own Sick Beard init script for Arch Linux.

This is the daemon configuration script, it is located under: /etc/conf.d/sickbeard.conf.

SB_PYTHON="/usr/bin/python2"
SB_BIN="/opt/sickbeard/Sick-Beard/SickBeard.py"
SB_USER="user"
SB_PORT="8081"
SB_CONF="/opt/sickbeard/Sick-Beard/config.ini"
SB_PIDFILE="/var/run/user/sickbeard.pid"

As you see I save the PID file under the /var/run/user/ directory. It should always be discouraged to run daemons as root user. However when you are running a daemon as regular user, make sure you have correct permission to the directory for storing the PID file. You’ll likely lack permission for storing the PID file in the /var/run/ directory (since that directory is owned by root). So if you create a subdirectory and change the ownership to the designated user you’ll have a nice placeholder for your daemons.

This is the init script for the daemon, it is located under: /etc/rc.d/sickbeard

#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions
. /etc/conf.d/sickbeard.conf

case "$1" in
start)
stat_busy "Starting Sick-Beard"

if [ -f $SB_PIDFILE ]; then
stat_fail
PID=`cat $SB_PIDFILE`
echo "Sick-Beard is already running: $PID"
else

su - $SB_USER -c "$SB_PYTHON $SB_BIN -q -d --config $SB_CONF --port $SB_PORT --pidfile $SB_PIDFILE" -s /bin/sh
if [ $? -gt 0 ]; then
stat_fail
else
add_daemon sickbeard
stat_done
fi
fi
;;
stop)
stat_busy "Stopping Sick-Beard"

if [ -f $SB_PIDFILE ]; then
PID=`cat $SB_PIDFILE`
kill -TERM $PID
rm_daemon sickbeard
stat_done
else
stat_fail
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
exit 0

When setting the executable permissions for this script you should be ready to go!

# /etc/rc.d/sickbeard start
:: Starting Sick-Beard [PASS]

You can start Sick Beard at boot time by adding it to the /etc/rc.conf file under the following section (ommit the dots):

DAEMONS=(... sickbeard ...)

This entry was posted in Arch Linux, Linux. Bookmark the permalink.

7 Responses to Arch Linux Sick Beard init script

  1. Nathan Hoad says:

    This is literally the first sane init script I’ve seen for Sickbeard. The Arch Linux one you mentioned still uses curl to shutdown Sickbeard, and it’s horrible. If you issue a restart, it tries to kill it via curl but doesn’t block, and immediately starts another Sickbeard instance. This results in two instances running at the same time, with the second one guaranteed to crash while the first shuts down.

    You should send this through to the maintainer of the sickbeard-git package on the AUR.

    Thanks heaps for this. Great work!

  2. Adam says:

    do you mind if i submit this (with some changes) to a sickbeard fork that works with torrents? here is the link: https://github.com/mr-orange/Sick-Beard

  3. Craig says:

    Thanks for this. Works like a charm. I’m not a linux guy at all, but with WinSCP and this, I pulled it off in 5 minutes. Happy!

  4. nikhil says:

    getting this error :(

    rc.d start sickbeard
    :: Starting Sick-Beard [BUSY]
    su: user user does not exist
    [FAIL]

    • bart says:

      Hi Nikhil,

      I guess you didn’t alter the configuration file: /etc/conf.d/sickbeard.conf

      In this configuration file, you’ll need to replace “user” setting (SB_USER=”user”) with the user of choice on your machine.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>