Skip to content

Instantly share code, notes, and snippets.

@jeffgca
Created October 22, 2013 00:09
Show Gist options
  • Save jeffgca/7093110 to your computer and use it in GitHub Desktop.
Save jeffgca/7093110 to your computer and use it in GitHub Desktop.
An upstart script for ghost on Ubuntu 13.10
#!upstart
2 #
3 # An example upstart script for running a Node.js process as a service
4 # using Forever as the process monitor. For more configuration options
5 # associated with Forever, see: https://github.com/nodejitsu/forever
6 #
7 # You will need to set the environment variables noted below to conform to
8 # your use case, and should change the description.
9 #
10 description "Example upstart script for a Node.js process"
11
12 start on startup
13 stop on shutdown
14
15 # This line is needed so that Upstart reports the pid of the Node.js process
16 # started by Forever rather than Forever's pid.
17 expect fork
18
19 env NODE_BIN_DIR="/usr/bin/nodejs"
20 env NODE_PATH="/usr/local/lib/node_modules"
21 env APPLICATION_DIRECTORY="/data/apps/ghost"
22 env APPLICATION_START="index.js"
23 env LOG="/var/log/node-canuckistani-ghost.log"
24 env NODE_ENV=production
25
26 export NODE_ENV=production
27
28 script
29 # Add the node executables to the path, which includes Forever if it is
30 # installed globally, which it should be.
31 PATH=$NODE_BIN_DIR:$PATH
32 # The minUptime and spinSleepTime settings stop Forever from thrashing if
33 # the application fails immediately on launch. This is generally necessary to
34 # avoid loading development servers to the point of failure every time
35 # someone makes an error in application initialization code, or bringing down
36 # production servers the same way if a database or other critical service
37 # suddenly becomes inaccessible.
38 cd $APPLICATION_DIRECTORY && NODE_ENV=production exec forever --sourceDir $APPLICATION_DIRECTORY -a -l $LO G \
39 --minUptime 5000 --spinSleepTime 2000 start $APPLICATION_START
40 end script
41
42 pre-stop script
43 # Add the node executables to the path.
44 PATH=$NODE_BIN_DIR:$PATH
45 # Here we're using the pre-stop script to stop the Node.js application
46 # process so that Forever is given a chance to do its thing and tidy up
47 # its data. Note that doing it this way means that each application that
48 # runs under Forever must have a different start file name, regardless of
49 # which directory it is in.
50 exec forever stop $APPLICATION_START >> $LOG
51 end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment