Created
January 19, 2014 21:39
-
-
Save detj/8511325 to your computer and use it in GitHub Desktop.
Upstart script for node.js apps
This file contains 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
#example upstart script | |
description "Example upstart script" | |
author "detj" | |
# Environment variables | |
env LOG_FILE=/home/debjeet/test.log | |
env NODE_ENV="production" | |
start on filesystem or runlevel [2345] | |
stop on runlevel [016] | |
# Respawn in case of a crash, with default paramters | |
# Don't respawn after 10 retries in 100 seconds | |
respawn | |
respawn limit 10 100 | |
script | |
# variables | |
NODE_BIN=/usr/local/bin/node | |
APP_NAME=test | |
APP_DIR=/home/debjeet | |
SCRIPT_FILE=/home/debjeet/index.js | |
RUN_AS="debjeet" | |
# Make sure the log file exists and is writable | |
touch $LOG_FILE | |
chown $RUN_AS:$RUN_AS $LOG_FILE | |
# Change to the application directory | |
chdir $APP_DIR | |
# Launch the application | |
exec start-stop-daemon --start --chuid ${RUN_AS} --chdir ${APP_DIR} --exec ${NODE_BIN} ${SCRIPT_FILE} >> ${LOG_FILE} 2>&1 | |
end script | |
pre-start script | |
echo "Starting test" >> $LOG_FILE | |
end script | |
post-start script | |
echo "Started test" >> $LOG_FILE | |
end script | |
pre-stop script | |
echo "Stopping test" >> $LOG_FILE | |
end script | |
post-stop script | |
echo "Stopping test" >> $LOG_FILE | |
end script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment