Skip to content

Instantly share code, notes, and snippets.

@cris
Created February 29, 2012 09:20
Show Gist options
  • Save cris/1939389 to your computer and use it in GitHub Desktop.
Save cris/1939389 to your computer and use it in GitHub Desktop.
Socket.IO Upstart job
description "Socket.IO worker"
instance $NUM
stop on stopping socketio
respawn
limit nofile 10000 10000
respawn limit 99 5
kill timeout 5
env NUM=
env LOGFILE=/var/log/syslog
script
export LANG=en_US.UTF-8
export NODE_ENV=production
export NUM=$NUM
# Notice: node can't handle env vars after itself
# i.e.: node NUM=1
# doesn't pass NUM env var into node process
# So we put NUM only for informative ps auxf status
exec start-stop-daemon --start -c socketio --exec /usr/bin/env -- node /var/data/socketio/app.js NUM=$NUM >> /var/log/socketio/worker-$NUM.log 2>&1
end script
pre-start script
if [ -z $NUM ]; then
echo "[`date`] socketio-worker ERROR: NUM param should be set" >> $LOGFILE
echo "Usage: initctl start socketio-worker NUM=\$NUM" >> $LOGFILE
echo " where \$NUM is a number of worker" >> $LOGFILE
stop; exit 0
fi
echo "Starting socketio-worker $UPSTART_INSTANCE: " `date` >> $LOGFILE
end script
post-stop script
echo "Stopped socketio-worker $UPSTART_INSTANCE: " `date` >> $LOGFILE
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment