Linux start/stop script for sabnzbd and episode butler

Got a program that plays well with SABnzbd? Share it here!
Post Reply
tret
Full Member
Full Member
Posts: 148
Joined: August 2nd, 2008, 2:07 pm

Linux start/stop script for sabnzbd and episode butler

Post by tret »

Hey guys, I put this together from information in the sabnzbd online manual and from episode butler forum threads... figured I would share. This script will both start and stop sabnzbd and episode butler properly during system startup/shutdown/reboot. I found that without properly shutting down sab and episode butler, their data can become damaged.

A couple of necessary steps:
1. The SABnzbd source has been moved to: /usr/share/SABnzbd
2. The Episode Butler source has been moved to: /home/username/.episodebutler
3. Set the variables: be sure to properly edit the variables in these scripts to match your setup (username, home dir, ip address:port, login, password, etc)

Once these things are in place, save the script to /etc/init.d/sabnzbd.sh
Make the script executable:

Code: Select all

sudo chmod +x /etc/init.d/sabnzbd.sh
Use update-rc.d to add the script to the startup/shutdown/reboot run levels (I have tested this on Ubuntu 8.10 and found that these run levels work well. It may vary by linux distro)

Code: Select all

sudo update-rc.d sabnzbd.sh start 30 2 3 4 5 . stop 14 0 1 6 .
That should do it, sab and episode butler should now start and stop automatically on startup/shutdown/reboot. You can manually start/stop by using these commands:

Code: Select all

/etc/init.d/sabnzbd.sh start
and

Code: Select all

/etc/init.d/sabnzbd.sh stop


This is for Pre SABnzbd 0.4.9 (No API Key Required)

Code: Select all

#! /bin/sh
### BEGIN INIT INFO
# Provides:          sabnzbd, episode butler
# Short-Description: start/stop sabnzbd and episode butler web interface
### END INIT INFO


USER="username"
HOME="/home/username"
SAB_IP="192.168.1.2:8081"
SAB_USER="login"
SAB_PASS="password"
BUTLER_IP="192.168.1.2:8082"
BUTLER_USER="login"
BUTLER_PASS="password"

case "$1" in
start)
  echo "Starting SABnzbd."
  /usr/bin/sudo -u $USER -H /usr/share/SABnzbd/SABnzbd.py -d -f $HOME/.sabnzbd/sabnzbd.ini
  sleep 2
  echo "Starting Episode Butler."
  /usr/bin/sudo -u $USER -H $HOME/.episodebutler/./episodebutler &
;;
stop)
  echo "Shutting down SABnzbd."
  /usr/bin/wget -q --delete-after "http://$SAB_IP/sabnzbd/api?mode=shutdown&ma_username=$SAB_USER&ma_password=$SAB_PASS"
  echo "Shutting down Episode Butler."
  /usr/bin/wget -q --delete-after --post-data=username=$BUTLER_USER\&password=$BUTLER_PASS "http://$BUTLER_IP/quit"
;;
*)
  echo "Usage: $0 {start|stop}"
  exit 1
esac

exit 0
This is for SABnzbd 0.4.9 or later (API Key Required)

Code: Select all

#! /bin/sh
### BEGIN INIT INFO
# Provides:          sabnzbd, episode butler
# Short-Description: start/stop sabnzbd and episode butler web interface
### END INIT INFO


USER="username"
HOME="/home/username"
SAB_IP="192.168.1.2:8081"
SAB_USER="login"
SAB_PASS="password"
SAB_APIKEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
BUTLER_IP="192.168.1.2:8082"
BUTLER_USER="login"
BUTLER_PASS="password"

case "$1" in
start)
  echo "Starting SABnzbd."
  /usr/bin/sudo -u $USER -H /usr/share/SABnzbd/SABnzbd.py -d -f $HOME/.sabnzbd/sabnzbd.ini
  sleep 2
  echo "Starting Episode Butler."
  /usr/bin/sudo -u $USER -H $HOME/.episodebutler/./episodebutler &
;;
stop)
  echo "Shutting down SABnzbd."
  /usr/bin/wget -q --delete-after "http://$SAB_IP/sabnzbd/api?mode=shutdown&ma_username=$SAB_USER&ma_password=$SAB_PASS&apikey=$SAB_APIKEY"
  echo "Shutting down Episode Butler."
  /usr/bin/wget -q --delete-after --post-data=username=$BUTLER_USER\&password=$BUTLER_PASS "http://$BUTLER_IP/quit"
;;
*)
  echo "Usage: $0 {start|stop}"
  exit 1
esac

exit 0
Good luck!
tret
Last edited by tret on April 17th, 2009, 11:21 am, edited 1 time in total.
User avatar
adaemox
Release Testers
Release Testers
Posts: 33
Joined: March 12th, 2009, 3:28 pm
Location: Cascadia

Re: Linux start/stop script for sabnzbd and episode butler

Post by adaemox »

I wanted to thank Tret for posting this script. I used a slightly modified version of it on a install/configuration guide for Episode Butler for Ubuntu 9.10.
http://www.ainer.org/?p=286
Adaemox

SABnzbd+, Episode Butler, VDPAU, and Sick Beard Tutorials @ http://www.ainer.org

Ubuntu and Firefox Information at http://www.ainer.org
User avatar
adaemox
Release Testers
Release Testers
Posts: 33
Joined: March 12th, 2009, 3:28 pm
Location: Cascadia

Re: Linux start/stop script for sabnzbd and episode butler

Post by adaemox »

I've modified this script to work with Sick Beard and used it on my Sick Beard guide here: http://www.ainer.org/?p=429.

Code: Select all

#! /bin/sh
### BEGIN SCRIPT INFO
# Provides: Episode Butler Start/Stop
# Copied by Ainer.org from http://forums.sabnzbd.org/index.php?topic=2013.0
# Written by Tret on April 17, 2009
# Modified by Ainer on March 26, 2010
# Modified by Ainer on March 31, 2010
### END SCRIPT INFO
 
USER="USERNAME"
HOME="/home/USERNAME"
SB_IP="localhost:8081"
SB_USER=""
SB_PASS=""
 
case "$1" in
start)
echo "Starting Sick Beard."
/usr/bin/sudo -u $USER -H python $HOME/.sickbeard/SickBeard.py &
;;
stop)
echo "Shutting down Sick Beard."
/usr/bin/wget -q –delete-after –post-data=username=$SB_USER\&password=$SB_PASS "http://$SB_IP/home/shutdown/"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
 
exit 0
Adaemox

SABnzbd+, Episode Butler, VDPAU, and Sick Beard Tutorials @ http://www.ainer.org

Ubuntu and Firefox Information at http://www.ainer.org
sliksoft
Newbie
Newbie
Posts: 1
Joined: May 7th, 2010, 9:19 pm

I've modified this script to work on ubuntu 10.04 server

Post by sliksoft »

;D I wanted to thank!!!!  Tret for posting this script. I used a slight modified version of it on Ubuntu 10.04 server !! ;D


This is for SABnzbd 0.5.2 (API Key Required)

Code: Select all

#! /bin/sh
### BEGIN INIT INFO
# Provides:          sabnzbd
# Short-Description: start/stop sabnzbd web interface
### END INIT INFO


USER="username"
HOME="/home/username"
SAB_IP="192.168.2.105:8080"
SAB_USER="login"
SAB_PASS="password"
SAB_APIKEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

case "$1" in
start)
  echo "Starting SABnzbd."
  /usr/bin/sudo -u $USER -H /usr/bin/sabnzbdplus -d -f $HOME/.sabnzbd/sabnzbd.ini
;;
stop)
  echo "Shutting down SABnzbd."
  /usr/bin/wget -q --delete-after "http://$SAB_IP/sabnzbd/api?mode=shutdown&ma_username=$SAB_USER&ma_password=$SAB_PASS&apikey=$SAB_APIKEY"
;;
*)
  echo "Usage: $0 {start|stop}"
  exit 1
esac

exit 0

save the script to /etc/init.d/sabnzbd.sh

Make the script executable:

Code: Select all

 sudo chmod +x /etc/init.d/sabnzbd.sh

Use update-rc.d to add the script to the startup/shutdown/reboot run levels

Code: Select all

sudo update-rc.d sabnzbd.sh start 30 2 3 4 5 . stop 14 0 1 6 .
manually start/stop sabanzbdplus

Code: Select all

/etc/init.d/sabnzbd.sh start

Code: Select all

 /etc/init.d/sabnzbd.sh stop 
 
philonimbus
Newbie
Newbie
Posts: 11
Joined: July 6th, 2008, 6:25 am

Re: Linux start/stop script for sabnzbd and episode butler

Post by philonimbus »

Hi,

Using mostly a netbook and traveling a lot, I'm used to starting Sabnzbd and Episode butler manually, depending on wireless network speed.

Is there any way to have this script working automatically on shutdown only ?
Post Reply