runit — Init & Process Manager
If you like this project, consider supporting me on Buy Me a Coffee ☕️
tags:
- process
- runit
- init
- supervision
- sysadmin
-
linux
⚡ runit Cheatsheet
Description
runit is a UNIX init scheme and service supervision suite. Lightweight, fast boot, and used as PID 1 or process supervisor on Void Linux and embedded systems. / runit — UNIX-схема инициализации и супервизии сервисов. Лёгкая, быстрая загрузка; используется как PID 1 или процесс-супервизор на Void Linux и embedded-системах.
Common use cases / Типовые сценарии:
- Fast boot on minimal systems / Быстрая загрузка минимальных систем
- Process supervision without systemd / Супервизия без systemd
- Embedded / container base images / Embedded и базовые образы контейнеров
- Void Linux default init / Дефолтный init на Void Linux
Status: Maintained (Void Linux / runit upstream). Alternatives: systemd, OpenRC, s6, supervisord. / Статус: поддерживается; альтернативы — systemd, OpenRC, s6, supervisord.
Paths: service dirs /etc/sv/, /var/service/; run scripts run, finish, log/run.
Cross-reference: supervisord, systemd, s6.
Installation
Install runit / Установка runit
# Debian/Ubuntu
apt install runit
# Void Linux (already default init)
xbps-install -S runit
# From source
git clone https://github.com/runit/runit
cd runit && package/compile
chpst -V
runsvdir -V 2>&1 | head
Configuration
Service directory layout / Раскладка сервисного каталога
/etc/sv/<SERVICE>/run
/etc/sv/<SERVICE>/finish
/etc/sv/<SERVICE>/log/run
run script / run-скрипт
/etc/sv/myapp/run
#!/bin/sh
exec 2>&1
exec chpst -u myuser:mygroup \
/usr/local/bin/myapp --config /etc/myapp/config.yaml
log/run / log/run
/etc/sv/myapp/log/run
#!/bin/sh
exec svlogd -tt /var/log/myapp/
chmod 0755 /etc/sv/myapp/run /etc/sv/myapp/finish /etc/sv/myapp/log/run
mkdir -p /var/log/myapp
Enable service / Включение сервиса
ln -s /etc/sv/myapp /var/service/myapp
# Or on Void:
ln -s /etc/sv/myapp /var/service/myapp
Core Management
sv commands / команды sv
sv status myapp
sv up myapp
sv down myapp
sv restart myapp
sv reload myapp
sv pause myapp
sv cont myapp
sv once myapp
sv hup myapp
sv kill myapp TERM
runsvdir / runsvdir
runsvdir /var/service
# Runs all services in directory; supervised by init
Sysadmin Operations
Logs / Логи
tail -f /var/log/myapp/current
svlogd -tt /var/log/myapp/
Logrotate (svlogd) / Ротация логов (svlogd)
/var/log/myapp/config
s1000000
n5
!gzip
Security
Hardening / Ужесточение
- Run services as non-root / Запускайте сервисы от non-root
- Use chpst -u / -U for user switching / Используйте chpst -u/-U
- Restrict service dir permissions / Ограничьте права сервисного каталога
- Use svlogd for structured logs / Используйте svlogd для структурированных логов
- Monitor restart loops / Мониторьте циклы перезапуска
- Keep runit patched / Обновляйте runit
# chpst -u user:group in run script
# ls -ld /etc/sv/myapp /var/service/myapp
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Service down | run script crash | Check run script; logs |
| Permission denied | Wrong user/perms | chpst -u; fix ownership |
| log not written | log/run missing/bad | Create log/run; exec svlogd |
| Won't start | Port in use | Check port; fix conflict |
| restart loop | App config error | Check app config; fix |
sv status myapp
cat /etc/sv/myapp/run
tail -f /var/log/myapp/current
Comparison Tables
Init / process supervisors / Init / процесс-супервизоры
| Manager | Notes |
|---|---|
| runit | Minimal, fast, script-based |
| systemd | Full-featured, distro default |
| supervisord | Python, config-file based |
| s6 / s6-rc | Feature-rich, complex |
| OpenRC | Gentoo-style init |
Production Runbooks
Runbook: Create new service / Создание нового сервиса
- Install app; create non-root user / Установить приложение; создать пользователя
- Create /etc/sv/myapp/run with chpst / Создать run-скрипт
- Create log/run with svlogd / Создать log/run
- chmod 0755 run scripts / Исправить права
- ln -s /etc/sv/myapp /var/service/myapp / Подключить сервис
sv status myapp— verify up / Проверить статус- Test restart:
sv restart myapp/ Проверить перезапуск - Document service layout / Задокументировать раскладку
Runbook: Graceful reload / Корректная перезагрузка сервиса
- Check if app supports SIGHUP / Проверить поддержку SIGHUP
sv hup myapp/ Отправить SIGHUP- If not,
sv restart myapp/ Или перезапустить - Verify health after reload / Проверить здоровье
- Monitor logs for errors / Мониторить логи
- Document reload semantics / Задокументировать семантику
Documentation Links
- runit guide — http://smarden.org/runit/
- runit GitHub — https://github.com/runit/runit
- chpst — http://smarden.org/runit/chpst.8.html
- svlogd — http://smarden.org/runit/svlogd.8.html