Skip to content

Instantly share code, notes, and snippets.

@ibdknox
Created August 4, 2011 06:13
Show Gist options
  • Save ibdknox/1124592 to your computer and use it in GitHub Desktop.
Save ibdknox/1124592 to your computer and use it in GitHub Desktop.
example daemon for lein processes
#!/bin/bash
name=webnoir
pidfile=/var/run/$name.pid
if [ -f "$pidfile" ]; then
pid=`cat $pidfile`
running=`ps p $pid |wc -l`
if [ $running -eq 1 ]; then
pid=
fi
else
pid=
fi
case $1 in
start)
if [ "$pid" = "" ]; then
nohup lein run prod 2>&1 1>>/var/log/$name.log &
echo $! > $pidfile
fi
$0 status
;;
stop)
if [ "$pid" = "" ]; then
echo $name - Not running
else
echo Stopping $name
kill $pid
fi
if [ -f $pidfile ]; then
rm $pidfile
fi
;;
restart)
$0 stop
$0 start
;;
status)
if [ "$pid" = "" ]; then
echo $name stopped
else
echo $name running with PID $pid
fi
;;
*)
echo $0 "(stop | start | restart | status)"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment