Skip to content

Running via lifeguard

Eric Richardson edited this page Aug 5, 2015 · 2 revisions

Lifeguard is a process runner, designed to restart an instance if it shuts down unexpectedly or if a new deployment is pushed.

StreamMachine extended lifeguard to add --handoff mode, which acts as a proxy to allow old and new instances of an app to communicate and transfer state information. StreamMachine uses that functionality to allow seamless restarts that keep listener and source connections alive.

Installing Lifeguard

Use npm to install lifeguard system-wide:

sudo npm install -g lifeguard

A lifeguard command will be installed in either /usr/bin or /usr/local/bin (depending on how Node.js is installed).

Running StreamMachine via Lifeguard

In a deployment setup, you would want to start lifeguard / StreamMachine via a system task such as Upstart.

For testing, you can start StreamMachine via a command like (assuming you have StreamMachine installed globally):

lifeguard --cmd "/usr/bin/env streammachine --config=/Users/foo/StreamMachine/config/standalone.js" --title "StreamMachine"

You could then trigger a handoff restart by sending the lifeguard process a USR2 signal:

killall -USR2 lifeguard:StreamMachine

You can also use the --dir flag to tell lifeguard to watch for changes to a tmp/restart.txt file in a given directory (to support restarts on Capistrano-style deployments):

lifeguard --cmd "/usr/bin/env streammachine --config=/home/StreamMachine/current/config/standalone.js" --dir /home/StreamMachine/current --title "StreamMachine"

Lifeguard would then watch for the creation of and changes to /home/StreamMachine/current/tmp/restart.txt. It would trigger a restart when the file is touched.