Skip to content

Instantly share code, notes, and snippets.

@komasaru
Created September 19, 2013 08:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komasaru/6620560 to your computer and use it in GitHub Desktop.
Save komasaru/6620560 to your computer and use it in GitHub Desktop.
Shell script to start a daemon.
#!/bin/sh
NAME="[ TEST DAEMON ]"
PID="./test_daemon.pid"
CMD="ruby test_daemon.rb"
start()
{
if [ -e $PID ]; then
echo "$NAME already started"
exit 1
fi
echo "$NAME START!"
$CMD
}
stop()
{
if [ ! -e $PID ]; then
echo "$NAME not started"
exit 1
fi
echo "$NAME STOP!"
kill -INT `cat ${PID}`
rm $PID
}
restart()
{
stop
sleep 2
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Syntax Error: release [start|stop|restart]"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment