PKGBUILDs/aur/sabnzbd/sabnzbd.init

73 lines
1.5 KiB
Plaintext
Raw Normal View History

2011-05-17 22:02:46 +00:00
#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
. /etc/conf.d/sabnzbd
2012-01-04 19:16:02 +00:00
PID="$(pgrep -f -u "${SABNZBD_USER}" SABnzbd.py)"
2011-10-23 19:30:03 +00:00
case "${1}" in
2011-05-17 22:02:46 +00:00
start)
stat_busy "Starting SABnzbd"
2011-10-23 19:30:03 +00:00
2012-01-04 19:16:02 +00:00
if [ -f /run/daemons/sabnzbd ]; then
echo -n "Sabnzbd is already running as a daemon! If you are certain it is not running, remove /run/daemons/sabnzbd."
2011-10-23 19:30:03 +00:00
stat_fail
2011-05-17 22:02:46 +00:00
else
2012-01-04 19:16:02 +00:00
su - "${SABNZBD_USER}" -c "python2 ${SABNZBD_DIR}/SABnzbd.py ${SABNZBD_ARGS}" -s /bin/sh
2011-10-23 19:30:03 +00:00
if [ "${?}" -gt 0 ]; then
stat_fail
2012-01-04 19:16:02 +00:00
exit 1
2011-10-23 19:30:03 +00:00
else
add_daemon sabnzbd
stat_done
fi
2011-05-17 22:02:46 +00:00
fi
;;
stop)
stat_busy "Stopping SABnzbd"
2011-10-23 19:30:03 +00:00
curl -f "${SABNZBD_PROTOCOL}://${SABNZBD_USPW}${SABNZBD_IP}:${SABNZBD_PORT}/sabnzbd/api?mode=shutdown&apikey=${SABNZBD_KEY}" &> /dev/null
2012-01-04 19:16:02 +00:00
if [ "${?}" -gt 0 ]; then
stat_fail
exit 1
else
rm_daemon sabnzbd
stat_done
fi
;;
force-stop)
stat_busy "Stopping SABnzbd (forced)"
[ -n "${PID}" ]; kill "${PID}" &> /dev/null
2011-10-23 19:30:03 +00:00
if [ "${?}" -gt 0 ]; then
stat_fail
2012-01-04 19:16:02 +00:00
exit 1
2011-05-17 22:02:46 +00:00
else
2012-01-04 19:16:02 +00:00
[ -f /run/daemons/sabnzbd ]; rm -f /run/daemons/sabnzbd &> /dev/null
2011-10-23 19:30:03 +00:00
rm_daemon sabnzbd
stat_done
2011-05-17 22:02:46 +00:00
fi
;;
restart)
2011-10-23 19:30:03 +00:00
"${0}" stop
2011-05-17 22:02:46 +00:00
sleep 1
2011-10-23 19:30:03 +00:00
"${0}" start
2011-05-17 22:02:46 +00:00
;;
2012-01-04 19:16:02 +00:00
force-restart)
"${0}" force-stop
sleep 1
"${0}" start
;;
status)
stat_busy "Checking SABnzbd status";
ck_status sabnzbd
;;
2011-05-17 22:02:46 +00:00
*)
2012-01-04 19:16:02 +00:00
echo "usage: ${0} {start|stop|restart|force-stop|force-restart|status}"
2011-05-17 22:02:46 +00:00
esac
2012-01-04 19:16:02 +00:00
2011-05-17 22:02:46 +00:00
exit 0