Skip to content

Instantly share code, notes, and snippets.

@natronics
Created March 5, 2014 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natronics/9375395 to your computer and use it in GitHub Desktop.
Save natronics/9375395 to your computer and use it in GitHub Desktop.
An /etc/init.d/ start-stop-daemon for managing https://github.com/zenirc/zenircbot
#!/bin/sh
### BEGIN INIT INFO
# Provides: zenirc
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts zenircbot
# Description: Starts zenircbot
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON="/usr/bin/nodejs"
NAME=zenirc
DESC=zenirc main bot
SCRIPT="bot.js"
# make this path to clone of <https://github.com/zenirc/zenircbot>
PROJECTPATH="/irc/zenircbot"
start_service () {
mkdir -p /var/run/$NAME
echo "starting $NAME"
start-stop-daemon --start --background --make-pidfile --pidfile /var/run/$NAME/$NAME.pid --chdir $PROJECTPATH --exec $DAEMON $PROJECTPATH/$SCRIPT
}
stop_service () {
echo "stopping $NAME"
start-stop-daemon --stop --quiet --pidfile /var/run/$NAME/$NAME.pid
}
case "$1" in
'start')
start_service
;;
'stop')
stop_service
;;
'restart')
stop_service
start_service
;;
*)
echo "Usage: $0 { start | stop | restart }"
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment