Skip to content

Instantly share code, notes, and snippets.

@OwlyCode
Last active August 29, 2015 13:57
Show Gist options
  • Save OwlyCode/9661213 to your computer and use it in GitHub Desktop.
Save OwlyCode/9661213 to your computer and use it in GitHub Desktop.
Behat-launcher daemon script
#! /bin/sh
# Based on http://www.bram.us/2013/11/11/run-a-php-script-as-a-servicedaemon-using-start-stop-daemon/
# Put this script into /etc/init.d/
# cp behat-launcher /etc/init.d/behat-launcher
#
# Make it executable :
# chmod 0755 /etc/init.d/behat-launcher
#
# Make it run at startup :
# sudo update-rc.d behat-launcher defaults
# Change this with the path to the behat-launcher php executable
BEHAT_LAUNCHER_BIN="/my/path/to/behat-launcher/behat-launcher"
# This is all preset for you
NAME=behat-launcher
DESC="Daemon for behat-launcher"
PIDFILE="/var/run/${NAME}.pid"
LOGFILE="/var/log/${NAME}.log"
DAEMON="/usr/bin/php"
DAEMON_OPTS="${BEHAT_LAUNCHER_BIN} run"
START_OPTS="--start --background --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON} ${DAEMON_OPTS}"
STOP_OPTS="--stop --pidfile ${PIDFILE}"
test -x $DAEMON || exit 0
set -e
case "$1" in
start)
echo -n "Starting ${DESC}: "
start-stop-daemon $START_OPTS >> $LOGFILE
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon $STOP_OPTS
echo "$NAME."
rm -f $PIDFILE
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon $STOP_OPTS
sleep 1
start-stop-daemon $START_OPTS >> $LOGFILE
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment