Skip to content

Instantly share code, notes, and snippets.

@stephenl03
Created August 3, 2017 19:02
Show Gist options
  • Save stephenl03/195af2a703b68b073ecaf7e7fc679dab to your computer and use it in GitHub Desktop.
Save stephenl03/195af2a703b68b073ecaf7e7fc679dab to your computer and use it in GitHub Desktop.
#!/bin/sh
#
### BEGIN INIT INFO
# Provides: nzbget
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start the nzbget processes
# Description: starts and stops nzbget
# Author: Stephen
# Version: 1.0
### END INIT INFO
NAME=nzbget
DESC=NZBGet
# User to run the daemon
NZBGET_USER=media
# Path to configfile
NZBGET_CONF=/home/media/nzbget/nzbget.conf
# nzbget executable
NZBGET_BIN=/usr/local/bin/nzbget
# Usually MainDir/nzbget.lock
# Check LockFile setting in your nzbget.conf
PID_FILE=/home/media/nzbget/downloads/nzbget.lock
#######################################################################
##
### NO MODIFICATIONS PAST THIS LINE
##
#######################################################################
RETVAL=0
. /etc/init.d/functions
PATH=${PATH}:/sbin
do_start()
{
if [ -f ${PID_FILE} ] && kill -0 $(cat ${PID_FILE}); then
echo 'Service already running' >&2
return 1
fi
logger -t $0 "Starting $DESC" "$NAME"
echo "Starting $DESC" "$NAME"
daemon --user=${NZBGET_USER} --pidfile=${PID_FILE} ${NZBGET_BIN} --daemon --configfile ${NZBGET_CONF}
RETVAL="$?"
echo
return "$RETVAL"
}
do_stop()
{
if [ ! -f "${PID_FILE}" ] || ! kill -0 $(cat "${PID_FILE}"); then
echo 'Service not running' >&2
return 1
fi
logger -t $0 "Stopping $DESC" "$NAME"
echo "Stopping $DESC" "$NAME"
killproc -p ${PID_FILE} ${NAME}
RETVAL="$?"
echo
[ $RETVAL -eq 0 ] && rm -f $lockfile
return "$RETVAL"
}
case "$1" in
start)
do_start
case "$?" in
0|1) logger -t $0 "$?" ;;
2) logger -t $0 "Error" ;;
esac
;;
stop)
do_stop
case "$?" in
0|1) logger -t $0 "$?" ;;
2) logger -t $0 "Error" ;;
esac
;;
restart)
echo "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) logger -t $0 "Success" ;;
1) logger -t $0 "Old process probably still running" ;;
*) logger -t $0 "Error" ;;
esac
;;
*)
# Failed to stop
loggger -t $0 1
;;
esac
;;
status)
status $NAME
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|status}" >&2
exit 3
;;
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment