Skip to content

Instantly share code, notes, and snippets.

@brutella
Created August 9, 2018 13:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brutella/ebd8b2ece2cfdc52d06aabb25cfd5ac4 to your computer and use it in GitHub Desktop.
Save brutella/ebd8b2ece2cfdc52d06aabb25cfd5ac4 to your computer and use it in GitHub Desktop.
Get started with runit

runit

Official Documentation: http://smarden.org/runit/ Quickstart: https://kchard.github.io/runit-quickstart/

Install

sudo apt-get install runit

Launch runit on startup by running /usr/sbin/runsvdir-start & in /etc/rc.local. Read more The script runsvdir-start is a copy of the stage 2 script of runit – in Rasbian it's at /etc/runit/2.

cp /etc/runit/2 /usr/sbin/runsvdir-start

Usage

/
├── etc
│   └── runit
│       ├── templates
│       │   ├── run
│       │   └── log
│       │       └── run
│       └── my-service
│           ├── run
│           └── log
│               └── run
└── opt
    ├── script.sh
    └── logs
       └── current

Templates

Create a run templates for all future service in /etc/runit/template/run and /etc/runit/template/log/run

/etc/runit/template/run
–––––––––––––––––––––––
#!/bin/sh -e
# redirects all stderr output to stdout
exec 2>&1
exec COMMAND

/etc/runit/template/log/run
–––––––––––––––––––––––
#!/bin/sh
exec svlogd -tt LOGDIR

Make both run scripts executable by chmod +x /etc/runit/template/run and chmod +x /etc/runit/template/log/run

Service

Create a service by copying the templates via cp -r /etc/runit/template /etc/runit/my-service. Edit the scripts

/etc/runit/my-service/run
–––––––––––––––––––––––
#!/bin/sh -e
# redirects all stderr output to stdout
exec 2>&1
exec /opt/my-service/script.sh

/etc/runit/my-service/log/run
–––––––––––––––––––––––
#!/bin/sh
exec svlogd -tt /opt/my-service/logs

Publish

Publish the service to runit by adding a symblink ln -s /etc/runit/my-service /etc/service/my-service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment