Skip to content

Instantly share code, notes, and snippets.

@night-codes
Last active August 29, 2015 14:10
Show Gist options
  • Save night-codes/dd6dd7c61d78e05e600a to your computer and use it in GitHub Desktop.
Save night-codes/dd6dd7c61d78e05e600a to your computer and use it in GitHub Desktop.
#! /bin/sh
#chkconfig: 345 20 80
#description: node.js server service
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/srv/msrv.su/node/ # modify if you need
DESC="node.js server service"
NAME="node_service"
DAEMON="node"
NODEAPP="index.js"
DIR="/srv/service/dir/node/"
DIRlogs="/srv/service/dir/logs"
ARGS=" --nouse-idle-notification -w --debug --minUptime 5 --killSignal=SIGTERM --watchDirectory $DIR -a -o $DIRlogs/out.log -l $DIRlogs/logs.log -e $DIRlogs/err.log --spinSleepTime 15"
TEST=`forever list|grep $DIRlogs`
NODE="node"
# NODE="node --max-old-space-size=8192 --nouse-idle-notification --expose-gc "
# NODE="node --max-old-space-size=8192 --nouse-idle-notification"
cd $DIR
case "$1" in
start)
if [[ $TEST ]]; then
echo "ERROR: $NODEAPP already running!"
else
forever $ARGS start -c "$NODE" $NODEAPP
fi
;;
restart)
if [[ $TEST ]]; then
forever $ARGS restart -c "$NODE" $NODEAPP
else
forever $ARGS start -c "$NODE" $NODEAPP
fi
;;
stop)
if [[ $TEST ]]; then
forever $ARGS stop $NODEAPP
else
echo "ERROR: $NODEAPP isn't running!"
fi
;;
status)
echo -n "Status: $DESC: "
forever list
;;
*)
echo "Usage: $NAME {start|stop|restart|status}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment