Skip to content

Instantly share code, notes, and snippets.

@CatTail
Last active April 22, 2016 01:34
Show Gist options
  • Save CatTail/626ca308241aec467e331a6427324ca9 to your computer and use it in GitHub Desktop.
Save CatTail/626ca308241aec467e331a6427324ca9 to your computer and use it in GitHub Desktop.
Simple process manager
#! /bin/bash
PROGRAM_NAME="choppe"
PROGRAM="node app.js"
function getpid()
{
ps aux | grep "$PROGRAM" | grep -v grep | awk '{ print $2 }'
}
function help()
{
echo "Usage: bin/ctl <start|stop|restart|status>"
}
function start()
{
if [ $(getpid) ]; then
echo "$PROGRAM_NAME already running"
else
nohup $PROGRAM&
echo "$PROGRAM_NAME started"
fi
}
function stop()
{
if [ $(getpid) ]; then
kill -s SIGKILL $(getpid)
echo "$PROGRAM_NAME stoped"
else
echo "$PROGRAM_NAME not running"
fi
}
case $1 in
start )
start
;;
stop )
stop
;;
restart )
stop
start
;;
status )
if [ $(getpid) ]; then
echo "$PROGRAM_NAME is running"
else
echo "$PROGRAM_NAME is not running"
fi
;;
help|-h|--help )
help
;;
* )
help
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment