Skip to content

Instantly share code, notes, and snippets.

@bear
Last active December 20, 2015 14:39
Show Gist options
  • Save bear/6148074 to your computer and use it in GitHub Desktop.
Save bear/6148074 to your computer and use it in GitHub Desktop.
runit uses a directory structure along the lines of:
/etc/sv/<appname>/
env/
log/
and in the <appname> dir it expects to find a "run" bash script - for this example the node app has been installed in /home/myapp/mynodeapp/ where "myapp" is the user to run the app under and is started by "node server.js".
environment vars are stored as files inside of /etc/sv/<appname>/env/
env/NODE_ENV
env/NODE_PATH
and the contents of the files are what you want the environment var to be set to
logging is handled the same way - you create a "run" bash script in the log/ dir that contains how you want to redirect stdio, I almost always use the same thing:
#!/bin/sh
exec chpst -umyapp svlogd -tt /var/log/appname
run script template for the app:
#!/bin/bash -e
envdir=$PWD/env
PATH=/usr/local/bin:/usr/bin:/bin
APP_ROOT=`readlink -f /home/myapp/mynodeapp`
if [ -s /home/myapp/.nvm/nvm.sh ]; then
. /home/myapp/.nvm/nvm.sh
fi
cd $APP_ROOT
exec 2>&1 chpst -e $envdir -u myapp node server.js
To start runit - add the following to /etc/init/runsvdir.conf and start the service
# for runit - manage /usr/sbin/runsvdir-start
start on runlevel 2
start on runlevel 3
start on runlevel 4
start on runlevel 5
stop on shutdown
respawn
exec /usr/sbin/runsvdir-start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment