updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / sabnzbd / sabnzbd.init
bloba4ecb697eb42a234cebcb44e4c9f41321c05e066
1 #!/bin/bash
3 . /etc/rc.conf
4 . /etc/rc.d/functions
5 . /etc/conf.d/sabnzbd
7 PID="$(pgrep -f -u "${SABNZBD_USER}" SABnzbd.py)"
9 case "${1}" in
10 start)
11 stat_busy "Starting SABnzbd"
13 if [ -f /run/daemons/sabnzbd ]; then
14 echo -n "Sabnzbd is already running as a daemon! If you are certain it is not running, remove /run/daemons/sabnzbd."
15 stat_fail
16 else
17 su - "${SABNZBD_USER}" -c "python2 ${SABNZBD_DIR}/SABnzbd.py ${SABNZBD_ARGS}" -s /bin/sh
18 if [ "${?}" -gt 0 ]; then
19 stat_fail
20 exit 1
21 else
22 add_daemon sabnzbd
23 stat_done
27 stop)
28 stat_busy "Stopping SABnzbd"
30 curl -f "${SABNZBD_PROTOCOL}://${SABNZBD_USPW}${SABNZBD_IP}:${SABNZBD_PORT}/sabnzbd/api?mode=shutdown&apikey=${SABNZBD_KEY}" &> /dev/null
32 if [ "${?}" -gt 0 ]; then
33 stat_fail
34 exit 1
35 else
36 rm_daemon sabnzbd
37 stat_done
40 force-stop)
41 stat_busy "Stopping SABnzbd (forced)"
43 [ -n "${PID}" ]; kill "${PID}" &> /dev/null
45 if [ "${?}" -gt 0 ]; then
46 stat_fail
47 exit 1
48 else
49 [ -f /run/daemons/sabnzbd ]; rm -f /run/daemons/sabnzbd &> /dev/null
50 rm_daemon sabnzbd
51 stat_done
54 restart)
55 "${0}" stop
56 sleep 1
57 "${0}" start
59 force-restart)
60 "${0}" force-stop
61 sleep 1
62 "${0}" start
64 status)
65 stat_busy "Checking SABnzbd status";
66 ck_status sabnzbd
69 echo "usage: ${0} {start|stop|restart|force-stop|force-restart|status}"
70 esac
72 exit 0