Skip to content

Instantly share code, notes, and snippets.

@jamiecobbett
Created September 30, 2009 13:46
Show Gist options
  • Save jamiecobbett/198102 to your computer and use it in GitHub Desktop.
Save jamiecobbett/198102 to your computer and use it in GitHub Desktop.
Shell script to daemonise a ruby process
#!/bin/sh
#
# Script: app_ctl
# Description: Starts and stops a Ruby script
#
die()
{
echo "$*"
exit 1
}
APP_PID=./app.pid
case $1 in
start)
if [ -f "$APP_PID" -a ! -f /proc/`cat $APP_PID` ]
then
echo "App is already running"
exit 1;
fi
nohup ruby ./app.rb &
echo $! > $APP_PID
;;
stop) if [ ! -f "$APP_PID" ]
then
echo "App is not running (no PID file)"
else
kill `cat $APP_PID`
rm -f $APP_PID
fi
;;
status) ;;
*) echo "Usage: `basename $0` {-start|-stop|-status}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment