Skip to content

Instantly share code, notes, and snippets.

@glebm
Forked from migrs/bluepill
Created August 3, 2012 23:43
Show Gist options
  • Save glebm/3252761 to your computer and use it in GitHub Desktop.
Save glebm/3252761 to your computer and use it in GitHub Desktop.
bluepill init script
#!/bin/sh
### BEGIN INIT INFO
# Provides: bluepill
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: bluepill daemon, providing process monitoring
# Description: bluepill is a monitoring tool. More info at http://github.com/arya/bluepill.
### END INIT INFO
# Check for missing binaries
BLUEPILL_BIN=`which bluepill`
test -x $BLUEPILL_BIN || { echo "$BLUEPILL_BIN not installed";
if [ "$1" = "stop" ]; then exit 0;
else exit 5; fi; }
bluepill () {
if [ -n "$2" ]; then
CONFIG=/etc/bluepill/$2.pill
if [ ! -e $CONFIG ]; then
CONFIG=/var/www/**/$2.pill
CONFIG=$CONFIG[0]
fi
if [ -e $CONFIG ]; then
if [ $1 = "load" ]; then
$BLUEPILL_BIN load $CONFIG
else
$BLUEPILL_BIN $2 $1
fi
else
echo "$CONFIG not found."
exit 1
fi
else
for CONFIG in /etc/bluepill/*.pill /var/www/**/*.pill; do
if [ -e $CONFIG ]; then
NAME=`basename $CONFIG .pill`
echo "== $NAME =="
if [ $1 = "load" ]; then
$BLUEPILL_BIN load $CONFIG
else
$BLUEPILL_BIN $NAME $1
fi
fi
done
fi
}
case $1 in
start)
echo "Starting bluepill:"
bluepill load $2
;;
stop)
echo "Shutting down bluepill:"
bluepill quit $2
;;
status)
bluepill status $2
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
$0 start
;;
*)
## If no parameters are given, print which are avaiable.
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment