Official Documentation: http://smarden.org/runit/ Quickstart: https://kchard.github.io/runit-quickstart/
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
/
├── etc
│ └── runit
│ ├── templates
│ │ ├── run
│ │ └── log
│ │ └── run
│ └── my-service
│ ├── run
│ └── log
│ └── run
└── opt
├── script.sh
└── logs
└── current
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
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 the service to runit by adding a symblink ln -s /etc/runit/my-service /etc/service/my-service
.