-
-
Save CalvinRodo/5225713 to your computer and use it in GitHub Desktop.
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
description "Upstart script to run a nodejs app as a service" | |
author "Louis Chatriot" | |
env NODE_BIN=/usr/local/bin/node | |
env APP_DIR=/path/to/app/dir | |
env SCRIPT_FILE="scriptfile.js" # Entry point for the nodejs app | |
env LOG_FILE=/path/to/logfile.log | |
env RUN_AS="anyuser" # Upstart can only be run nicely as root, need to drop privileges | |
env SERVER_ENV="anything" # Usual apps can be run in different environments (development, test, production ...) | |
# I typically use the environment variable NODE_ENV (see below) | |
# If not needed simply remove the "NODE_ENV=$SERVER_ENV" below | |
# Start service on startup, stop on shutdown | |
start on runlevel [2345] | |
stop on runlevel [016] | |
# Respawn in case of a crash, with default parameters | |
respawn | |
script | |
# Make sure logfile exists and can be written by the user we drop privileges to | |
touch $LOG_FILE | |
chown $RUN_AS:$RUN_AS $LOG_FILE | |
chdir $APP_DIR | |
NODE_ENV=$SERVER_ENV su -s /bin/sh -c 'exec "$0" "$@"' $RUN_AS -- $NODE_BIN $SCRIPT_FILE >> $LOG_FILE 2>&1 | |
end script | |
post-start script | |
echo "===== App restarted =====" >> $LOG_FILE | |
end script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment