Created
August 26, 2014 02:55
-
-
Save developerworks/508c408eff2109219bdf to your computer and use it in GitHub Desktop.
Ubuntu Upstart Configuration for Node.js Forever
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
author "hezhiqiang" | |
description "Console Admin Server" | |
start on runlevel [2345] | |
stop on starting rc RUNLEVEL=[016] | |
expect fork | |
env NODE_BIN_DIR="/usr/local/bin" | |
env NODE_PATH="/usr/local/lib/node_modules" | |
env APPLICATION_PATH="/root/console-admin-server/app.js" | |
env PIDFILE="/var/run/console-admin-server.pid" | |
env LOG="/var/log/console-admin-server.log" | |
env MIN_UPTIME="5000" | |
env SPIN_SLEEP_TIME="2000" | |
script | |
# Add the node executables to the path, which includes Forever if it is | |
# installed globally, which it should be. | |
PATH=$NODE_BIN_DIR:$PATH | |
# The minUptime and spinSleepTime settings stop Forever from thrashing if | |
# the application fails immediately on launch. This is generally necessary | |
# to avoid loading development servers to the point of failure every time | |
# someone makes an error in application initialization code, or bringing | |
# down production servers the same way if a database or other critical | |
# service suddenly becomes inaccessible. | |
exec forever \ | |
--pidFile $PIDFILE \ | |
-a \ | |
-l $LOG \ | |
--minUptime $MIN_UPTIME \ | |
--spinSleepTime $SPIN_SLEEP_TIME \ | |
start $APPLICATION_PATH | |
end script | |
pre-start script | |
# Date format same as (new Date()).toISOString() for consistency | |
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> "$LOG" | |
end script | |
pre-stop script | |
rm $PIDFILE | |
forever stop $APPLICATION_PATH | |
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> "$LOG" | |
end script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment