Skip to content

Instantly share code, notes, and snippets.

@bodokaiser
Last active Aug 29, 2015
Embed
What would you like to do?
node init script without supervisor (supervisor takes a few resources)
#!/bin/sh
#
# chkconfig: 35 99 99
# description: node.js /home/bodokaiser/tmp/<name>
#
. /etc/rc.d/init.d/functions
# application name
NAME="engine"
# application user
USER="bodokaiser"
# environment variable
ENV="NODE_ENV=production"
# path to executable (we use supervisor for code reload)
EXEC='$(which node) --harmony'
# path to nodejs entry script
SCRIPT="/srv/node/$NAME/lib"
# path to log file
LOGFILE="/var/log/node-$NAME.log"
# path to lock file
PIDFILE="/var/run/node-$NAME.pid"
start()
{
if [ ! -f $PIDFILE ]
then
echo -e $"Starting $NAME: "
PID=`runuser -l $USER -c "$ENV $EXEC $SCRIPT" >> $LOGFILE 2>&1 & echo $!`
if [ ! -z $PID ]
then
echo $PID > $PIDFILE
echo_success
else
echo_failure
fi
return $?
else
echo -e $"Already running $NAME."
echo_failure
return 1
fi
}
stop()
{
if [ -f $PIDFILE ]
then
echo -e $"Stopping $NAME: "
PID=`cat $PIDFILE`
kill -TERM $PID
if [ $? ]
then
echo_success
rm -f $PIDFILE
else
echo_failure
fi
return $?
else
echo -e $"Not started $NAME."
echo_failure
return 1
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
RETVAL=1
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment