-
-
Save ashnur/2763037 to your computer and use it in GitHub Desktop.
an Upstart script for node.js app I used once ago, it demonstrates how to use nave from within a script, just replace node with nave use with node version
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
#!upstart | |
description "APPNAME node.js server" | |
author "Shimon Doodkin" | |
# license: public domain | |
start on runlevel [2345] | |
stop on runlevel [06] | |
#pre-start script | |
# exec touch /var/log/APPNAME.nodejs.log | |
# exec chmod 777 /var/log/APPNAME.nodejs.log | |
#end script | |
script | |
export HOME="/root" | |
# 27017 dev_db, Are argument i pass to my bash the script | |
exec sudo -u www-data /bin/bash /var/www/APPNAME/init.sh 27017 dev_db | |
# some other snippets | |
# exec sudo -u www-data /bin/bash -c 'while true; do /usr/local/bin/node /var/www/APPNAME/server.js 2>&1 >> /var/log/APPNAME.nodejs.log; sleep 1; done;' | |
# exec /usr/local/bin/node /var/www/APPNAME/server.js 2>&1 >> /var/log/APPNAME.nodejs.log | |
# exec sudo -u www-data /usr/local/bin/node /var/www/APPNAME/server.js 2>&1 >> /var/log/APPNAME.nodejs.log | |
end script |
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 | |
while true; | |
do | |
echo starting $(date); | |
script_directory=`dirname "$0"`; | |
cd $script_directory; | |
# choose your arrows below | |
# echo "bla" > file.txt # replaces file | |
# echo "bla" >> file.txt # appends to file | |
# or use a different logging solution if you need. | |
nice -n 19 nave use 0.4.10 --debug server.js "$@" > /var/log/APPNAME.nodejs.log 2>&1; | |
# nice -n 19 /usr/local/bin/node --debug server.js $* > /var/log/APPNAME.nodejs.log 2>&1; # before nave | |
exit_value="$?" ; | |
echo stopping $(date); | |
if [ "$exit_value" != "0" ]; then | |
sleep 5; | |
else | |
sleep 0.5; | |
fi ; | |
done; | |
# instead of useing monit or respawn. i did a shell while true script. to restart the secipt self exits , and this loop launches it again. | |
# in these days you may not need the while true. i did it long time ago. it is from an old system. | |
# today you have all those modules like nodejs-cluster etc. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment