Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- ### BEGIN INIT INFO
- # Provides: sabnzbd
- # Required-Start:
- # Required-Stop:
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- # Short-Description: starts instance of SABnzbd
- # Description: starts instance of SABnzbd using start-stop-daemon
- ### END INIT INFO
- if [[ ${EUID} -ne "0" ]]; then
- echo "You must be root to run this script..."
- exit 1;
- fi
- function get_pid {
- PID=$(ps aux | grep -v grep | grep SABnzbd.py | awk '{print $2;}')
- [[ -n ${PID} ]] && echo "${PID}" || echo "0"
- }
- function check_and_kill {
- PID=$(get_pid)
- if [[ "0" -ne ${PID} ]]; then
- echo "::Running SABnzbd found (${PID}), killing..."
- kill $PID
- fi
- }
- NAME=sabnzbd
- USER=sabnzbd
- GROUP=download
- PID_FILE=/var/sabnzbd/sabnzbd.pid
- SABNZBD_HOME=/usr/local/download/sabnzbd
- SABNZBD_OPTS="--daemon -f /var/sabnzbd/sabnzbd.ini"
- SABNZBD_BIN=${SABNZBD_HOME}/SABnzbd.py
- SABNZBD_START="start-stop-daemon -N 10 -I best-effort:6 --start --quiet --chuid ${USER}:${GROUP} --exec ${SABNZBD_BIN} -- ${SABNZBD_OPTS}"
- case "$1" in
- start)
- echo "Starting daemon: ${NAME}"
- [[ $(get_pid) -eq "0" ]] && $SABNZBD_START || echo "SABnzbd is already running..."
- ;;
- stop)
- echo "Stopping daemon: ${NAME}"
- check_and_kill
- ;;
- restart)
- echo "Restarting daemon: ${NAME}"
- check_and_kill
- $SABNZBD_START
- ;;
- *)
- echo "Usage: ${NAME} (start|stop|restart)"
- ;;
- esac
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement