Skip to content

Instantly share code, notes, and snippets.

@rbranson
Created October 21, 2010 16:16
Show Gist options
  • Save rbranson/638792 to your computer and use it in GitHub Desktop.
Save rbranson/638792 to your computer and use it in GitHub Desktop.
start-stop-daemon friendly script to start node and log to a file
#!/bin/sh
#
# Runs node.js against script, logging to a logfile. We have to do
# this because there's no way to call node directly and have start-stop-daemon
# redirect stdout to a logfile.
#
LOGFILE=/var/log/node/node-application.log
NODE=/usr/local/bin/node
JAVASCRIPT=/var/apps/node-application/app.js
# Fork off node into the background and log to a file
${NODE} ${JAVASCRIPT} >>${LOGFILE} 2>&1 </dev/null &
# Capture the child process PID
CHILD="$!"
# Kill the child process when start-stop-daemon sends us a kill signal
trap "kill $CHILD" exit INT TERM
# Wait for child process to exit
wait
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment