Skip to content

Instantly share code, notes, and snippets.

@sasha-id
Created August 11, 2012 02:33
Show Gist options
  • Save sasha-id/3320101 to your computer and use it in GitHub Desktop.
Save sasha-id/3320101 to your computer and use it in GitHub Desktop.
bluepill init.d script for non-privileged user
#!/bin/sh
### BEGIN INIT INFO
# Provides: bluepill
# Required-Start: $local_fs $remote_fs $network $syslog $time
# Required-Stop: $local_fs $remote_fs $network $syslog
# 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
set -e
. /lib/lsb/init-functions
# here comes default config
USER=XXXXXXX
RAILS_ENV=production
APP_NAME=XXXXXXXX
APP_ROOT=/u/apps/$APP_NAME
CMD="sudo -i -u $USER -- sh -c 'cd $APP_ROOT/current && RAILS_ENV=$RAILS_ENV bundle exec bluepill --no-privileged -c $APP_ROOT/shared -l $APP_ROOT/shared/log/bluepill.log"
case "$1" in
start)
echo -n "Starting bluepill for user $USER"
eval "$CMD load $APP_ROOT/current/config/bluepill.rb'"
;;
stop)
echo "Shutting down monitored processes"
eval "$CMD stop'"
echo "Shutting down bluepill daemon"
eval "$CMD quit'"
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
$0 start
;;
status)
eval "$CMD status'"
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment