Skip to content

Instantly share code, notes, and snippets.

@rovangju
Created April 3, 2013 19:53
Show Gist options
  • Select an option

  • Save rovangju/5304663 to your computer and use it in GitHub Desktop.

Select an option

Save rovangju/5304663 to your computer and use it in GitHub Desktop.
phergie - PHP IRC bot init.d script
#! /bin/sh
### BEGIN INIT INFO
# Provides: bot-phergie
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs $network $named
# Should-Stop: $local_fs $network $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Phergie PHP IRC bot init.d script
# Description: Use to manage the Phergie IRC bot.
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
BOTPATH=/opt/irc-bot-phergie
USER=jenkins
GROUP=nogroup
PIDFILE=/var/run/bot-phergie.pid
NAME=bot-phergie
DESC=bot-phergie
DAEMON=$BOTPATH/phergie.php
if [ ! -x "$BOTPATH" ]; then
echo "Botpath invalid..."
exit 1
fi
. /lib/lsb/init-functions
case $1 in
status)
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "$NAME" && status="0" || status="$?"
else
log_daemon_msg "$NAME not running"
log_end_msg 0
fi
;;
start)
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "$NAME" && status="0" || status="$?"
if [ $status = "0" ]; then
exit;
fi
fi
log_daemon_msg "Starting $NAME"
if start-stop-daemon --start --chuid $USER:$GROUP --chdir $BOTPATH --background --make-pidfile --oknodo --pidfile $PIDFILE --exec $DAEMON ; then
log_end_msg 0
else
log_end_msg 1
fi
;;
stop)
if [ ! -e $PIDFILE ]; then
log_daemon_msg "$NAME not running (no pidfile)"
log_end_msg 1
exit
fi
log_daemon_msg "Stopping $NAME"
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE && status="0" || status="$?"
rm -f $PIDFILE
log_end_msg $?
;;
restart)
$0 stop && sleep 2 && $0 start
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 2
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment