Created
May 29, 2012 00:53
-
-
Save Neil-Smithline/2821946 to your computer and use it in GitHub Desktop.
Quickie /etc/init.d script to get a daemon running.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
### BEGIN INIT INFO | |
# Provides: bitlbee | |
# Required-Start: | |
# Required-Stop: | |
# Should-Start: | |
# Default-Start: S | |
# Default-Stop: | |
# Short-Description: Run Bitlbee IRC server/IM gateway. | |
### END INIT INFO | |
EXE=/usr/local/sbin/bitlbee | |
NAME=bitlbee | |
PIDFILE=/var/run/$NAME.pid | |
PIDARG="-P " # Must end with a space if it is required | |
ARGS="" | |
PATH=/sbin:/bin | |
. /lib/init/vars.sh | |
. /lib/lsb/init-functions | |
do_start () { | |
$EXE $PIDARG$PIDFILE $ARGS | |
echo "$NAME running (pid=$(cat $PIDFILE))" | |
} | |
do_stop () { | |
echo "Trying to kill $NAME (pid=$(cat $PIDFILE))" | |
kill $(cat $PIDFILE) | |
} | |
case "$1" in | |
start) | |
do_start | |
;; | |
stop) | |
do_stop | |
;; | |
restart) | |
do_stop | |
sleep 5 | |
do_start | |
;; | |
reload|force-reload) | |
echo "Error: argument '$1' not supported" >&2 | |
exit 3 | |
;; | |
*) | |
echo "Usage: $NAME [start|stop|restart]" >&2 | |
exit 3 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At least on Ubuntu, daemons are moving towards initctl(8) for daemon process management. But sometimes it is just easy to whip up a quick script to start your daemon. This is the script I use. It is configured for Bitlbee but the script has been designed to be easy to modify. You should only need to edit data in the first 16 lines (if you don't know what it does, don't touch it).
The only tricky part is that the script does not add a space between the
PIDFILE
and thePIDARG
command line switch to pass the PIDFILE in. This is so the script can handle new-style arguments such as--pidfile=
as well as old-style arguments such as-P
. If you need to use an old-style argument, be sure thatPIDFILE
ends with a space.