Created
June 15, 2012 18:21
-
-
Save mitchallen/2938003 to your computer and use it in GitHub Desktop.
Example script for running a node app as a service under RHEL6 (sudo start. See the comments for usage.
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
#!upstart | |
description "myapp nodejs server" | |
author "Mitch Allen" | |
start on startup | |
stop on shutdown | |
respawn | |
expect fork | |
expect daemon | |
nice -5 | |
script | |
export HOME="/export/home/MY-USER" | |
echo $$ > /var/run/myapp.pid | |
su --session-command="/usr/bin/nodejs $HOME/test/server.js >> /var/log/myapp.sys.log 2>&1" root & | |
end script | |
pre-start script | |
# Date format same as (new Date()).toISOString() for consistency | |
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/log/myapp.sys.log | |
end script | |
pre-stop script | |
rm /var/run/myapp.pid | |
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/myapp.sys.log | |
end script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that this is for RHEL6.
Add the contents of this gist to a file and edit for your nodejs deployment:
Example usage:
Start, view status, stop:
Start, view process, stop, view process:
Start then tail the log (allowing you to monitor the output of your node app):
Tail the log from a remote client (substituting USER and SERVER for your environment):
References: