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 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!
Hi Nathan,
I’ve submitted the script via AUR. Thanks for your reply!
– Bart
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
Hi Adam,
I don’t mind, feel free to submit it. Thanks for the link to the project.
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!
getting this error 🙁
rc.d start sickbeard
:: Starting Sick-Beard [BUSY]
su: user user does not exist
[FAIL]
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.