Last active
April 22, 2016 01:34
-
-
Save CatTail/626ca308241aec467e331a6427324ca9 to your computer and use it in GitHub Desktop.
Simple process manager
This file contains hidden or 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/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