Created
September 30, 2009 13:46
-
-
Save jamiecobbett/198102 to your computer and use it in GitHub Desktop.
Shell script to daemonise a ruby process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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