forked from jedrichards/node-deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy-node-app.conf
60 lines (48 loc) · 2.15 KB
/
proxy-node-app.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
description "Upstart job definition for proxy-node-app"
author "Name"
# Automatically start the app when the filesystem and networking become available.
# Automatically stop the app on system shutdown.
start on filesystem and started networking
stop on shutdown
# Specify that the service should respawn if it quits unexpectedly. The respawn
# limit says that if the service respawns more than 10 times in 5 seconds it
# should quit respawning.
respawn
respawn limit 10 5
# Export a bunch of environment variables to be used below and in the Node app's
# child process.
env APP_NAME=proxy-node-app
env ENTRYPOINT=index.js
env NODE_APPS_DIR=/var/node
env USER=root
env GROUP=root
env PORT=80
env NODE_ENV=production
env NODE_BIN=/usr/bin/node
env LOG_FILENAME=log
env PID_FILENAME=pid
# The pre-start script executes just before the app is started.
# Here we're just sanity checking that the Node app's directory
# exists so we'll at least get a log file if it doesn't. We also
# make sure the Node app's directory and all the files in there
# are owned by the node user.
pre-start script
mkdir -p $NODE_APPS_DIR/$APP_NAME
chown -R node:node $NODE_APPS_DIR/$APP_NAME
end script
# This script actually starts the app. Since this is a front-facing
# reverse proxy it needs to start on port 80 so we start as root, then
# downgrade to the node user internally in the app code. For any other
# standard Node app however we should start as the node user from the
# beginning. By changing directory to the Node app's location we enable
# the use of relative paths inside the Node app's code. Additionally,
# stdout and stderr from the Node app are both piped to the log file.
script
exec start-stop-daemon --start --make-pidfile --pidfile $NODE_APPS_DIR/$APP_NAME/$PID_FILENAME --chdir $NODE_APPS_DIR/$APP_NAME/app --chuid $USER:$GROUP --exec $NODE_BIN $ENTRYPOINT >> $NODE_APPS_DIR/$APP_NAME/$LOG_FILENAME 2>&1
end script
# The post-stop script executes after the app has shut down, and in
# this case all we need to do is clean up the pidfile (start-stop-daemon
# will not automatically remove the pidfile it makes).
post-stop script
rm -f $NODE_APPS_DIR/$APP_NAME/$PID_FILENAME
end script