Last active
December 11, 2015 18:09
-
-
Save ryantm/4639588 to your computer and use it in GitHub Desktop.
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
Installation steps (untested, sorry no CentOS machine) | |
install file at /etc/init.d/marmalade | |
change PATH TO NODE BINARY | |
change PATH TO MARMALADE | |
change user if desired | |
#add script to rc.d | |
sudo chkconfig --add marmalade | |
sudo /etc/init.d/marmalade start |
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/sh | |
# place this file in in /etc/init.d/marmalade | |
# | |
# chkconfig: 35 99 99 | |
# description: Node.js /home/nodejs/sample/app.js | |
# | |
. /etc/rc.d/init.d/functions | |
USER="nodejs" # CHANGE USER IF DESIRED | |
DAEMON="/home/nodejs/.nvm/v0.4.10/bin/node" #PATH TO NODE BINARY | |
ROOT_DIR="/home/nodejs/sample" # PATH TO MARMALADE | |
SERVER="$ROOT_DIR/app.js" | |
LOG_FILE="$ROOT_DIR/app.js.log" | |
LOCK_FILE="/var/lock/subsys/node-server" | |
do_start() | |
{ | |
if [ ! -f "$LOCK_FILE" ] ; then | |
echo -n $"Starting $SERVER: " | |
runuser -l "$USER" -c "$DAEMON $SERVER >> $LOG_FILE &" && echo_success || echo_failure | |
RETVAL=$? | |
echo | |
[ $RETVAL -eq 0 ] && touch $LOCK_FILE | |
else | |
echo "$SERVER is locked." | |
RETVAL=1 | |
fi | |
} | |
do_stop() | |
{ | |
echo -n $"Stopping $SERVER: " | |
pid=`ps -aefw | grep "$DAEMON $SERVER" | grep -v " grep " | awk '{print $2}'` | |
kill -9 $pid > /dev/null 2>&1 && echo_success || echo_failure | |
RETVAL=$? | |
echo | |
[ $RETVAL -eq 0 ] && rm -f $LOCK_FILE | |
} | |
case "$1" in | |
start) | |
do_start | |
;; | |
stop) | |
do_stop | |
;; | |
restart) | |
do_stop | |
do_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