[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
howtos:slackware_admin:runit [2018/12/19 20:39 (UTC)] – [2. Use runit with traditional init] chrisabela | howtos:slackware_admin:runit [2019/09/19 15:39 (UTC)] – [Sources] use ordered list syntax aaditya | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Runit ====== | ====== Runit ====== | ||
- | ===== 1. Introduction ===== | + | ===== Introduction ===== |
runit is a UNIX init scheme with service supervision. It is a cross-platform Unix init scheme with service supervision, | runit is a UNIX init scheme with service supervision. It is a cross-platform Unix init scheme with service supervision, | ||
Line 11: | Line 11: | ||
To read on the benefits of runit, see here: http:// | To read on the benefits of runit, see here: http:// | ||
- | ===== 2. Use runit with traditional init ===== | + | //* Unless otherwise stated, all commands in this article are to be run by root.// |
+ | |||
+ | ===== Use runit with traditional init (sysvinit) | ||
runit is not provided by Slackware, but a SlackBuild is maintained on https:// | runit is not provided by Slackware, but a SlackBuild is maintained on https:// | ||
Line 29: | Line 31: | ||
</ | </ | ||
- | For a typical Slackware-stlyle service, you can also edit ''/ | + | ==== Starting via rc.local ==== |
+ | |||
+ | For a typical Slackware-stlyle service, you can edit ''/ | ||
< | < | ||
Line 36: | Line 40: | ||
fi | fi | ||
</ | </ | ||
- | |||
- | if you require it. | ||
and then edit write ''/ | and then edit write ''/ | ||
Line 44: | Line 46: | ||
#!/bin/sh | #!/bin/sh | ||
RUNIT=x$( /sbin/pidof runsvdir ) | RUNIT=x$( /sbin/pidof runsvdir ) | ||
- | if [ “$RUNIT” != x ]; then | + | if [ "$RUNIT" |
kill $RUNIT | kill $RUNIT | ||
fi | fi | ||
Line 57: | Line 59: | ||
and reboot | and reboot | ||
- | ===== 3. Using runit with sysvinit and inittab | + | ==== Starting via inittab |
Remove the entries in ''/ | Remove the entries in ''/ | ||
Line 77: | Line 79: | ||
or reboot | or reboot | ||
- | ===== 4. How to replace init with runit ===== | + | ===== How to replace init with runit ===== |
+ | |||
+ | runit provides '' | ||
If you followed the previous chapter, then stop runsvdir and reverse all the changes that you made on your system. | If you followed the previous chapter, then stop runsvdir and reverse all the changes that you made on your system. | ||
- | Remove | + | So, remove |
< | < | ||
Line 87: | Line 91: | ||
</ | </ | ||
- | Reboot: | + | And reboot: |
< | < | ||
Line 95: | Line 99: | ||
Also, it is best to re-build and re-install runit | Also, it is best to re-build and re-install runit | ||
- | This time, when running slackbuild, do pass any value for CONFIG, or set it to yes: | + | This time, when running slackbuild, do pass not any value for CONFIG, or set it to yes: |
< | < | ||
Line 167: | Line 171: | ||
< | < | ||
append=" | append=" | ||
- | < | + | </code> |
Then run lilo: | Then run lilo: | ||
Line 184: | Line 188: | ||
However, with the last alternative, | However, with the last alternative, | ||
- | ===== 5. Startup and Shutdown | + | ==== Startup and Shutdown ==== |
- | The traditional | + | The bsd style init scripts provided by Slackware are used to bring up the system. |
- | The script ''/ | + | Initially the single user script ''/ |
+ | |||
+ | The script ''/ | ||
Note that the shutdown command provided by sysvinit package will not work in runit. To reboot you enter | Note that the shutdown command provided by sysvinit package will not work in runit. To reboot you enter | ||
Line 206: | Line 212: | ||
The '' | The '' | ||
- | ===== 6. runsv ===== | + | Desktop Environments call ''/ |
- | + | ||
- | Although runit may replace init as the PID 1 daemon, there is not much benefit unless other services are migrated from Slackware’s BSD style to runsv(8). While this is not a complicated task, some familiarisation with runit’s characteristics is recommended | + | |
- | + | ||
- | Make an arbitrary directory under ''/ | + | |
< | < | ||
- | mkdir /etc/sv/example/ | + | mv /sbin/shutdown |
+ | ln -s / | ||
</ | </ | ||
- | In order to let the non-privileged user (say user chris) run it, change | + | However consider that shutdown would not work for the original init. |
+ | |||
+ | ===== runsv ===== | ||
+ | |||
+ | Although runit may replace init as the PID 1 daemon, there is not much benefit unless other services are migrated from Slackware' | ||
+ | |||
+ | Make an arbitrary directory under ''/ | ||
< | < | ||
- | chmod -R chris.users | + | mkdir / |
</ | </ | ||
- | As a non-priviliged user, create some directories | + | As a non-priviliged user (say user bob), create some directories: |
< | < | ||
- | mkdir -p /home/chris/runit/logs | + | mkdir -p /home/bob/runit/logs |
</ | </ | ||
- | Then edit a script that simulates a (finicky) service in a convenient directory; say | + | Then edit a ''/ |
< | < | ||
Line 245: | Line 254: | ||
< | < | ||
- | chmod +x /home/chris/ | + | chmod +x /home/bob/ |
</ | </ | ||
Line 251: | Line 260: | ||
< | < | ||
- | /home/chris/ | + | /home/bob/ |
</ | </ | ||
- | Log back to root, and edit a file called ''/ | + | Log in back as root and edit a file called ''/ |
< | < | ||
#!/bin/sh -e | #!/bin/sh -e | ||
exec 2>&1 | exec 2>&1 | ||
- | exec chpst -u chris /home/chris/ | + | exec chpst -u bob /home/bob/ |
</ | </ | ||
Line 276: | Line 285: | ||
</ | </ | ||
- | and edit another file under it also called ''/ | + | and edit another file under it, also called ''/ |
< | < | ||
#!/bin/sh | #!/bin/sh | ||
- | exec chpst -u chris svlogd -tt /home/chris/runit/logs | + | exec chpst -u bob svlogd -tt /home/bob/runit/logs |
</ | </ | ||
Line 289: | Line 298: | ||
</ | </ | ||
- | Run the sv service to ensure that it works: | + | Run the service to ensure that it works: |
< | < | ||
Line 301: | Line 310: | ||
</ | </ | ||
- | Watch how your “service” works, crashes, but it is recovered by runit: | + | Watch how your "service" |
+ | |||
+ | As your non-privilged user: | ||
< | < | ||
- | tail -f /home/chris/ | + | tail -f /home/bob/runit/ |
</ | </ | ||
- | ===== 7. | + | Hit CTRL+C to exit. |
+ | |||
+ | Finally, login back as root and let bob take the ownership of the whole ''/ | ||
+ | |||
+ | < | ||
+ | chown -R bob.users / | ||
+ | </ | ||
+ | |||
+ | Now bob can manage this service with the '' | ||
+ | |||
+ | ===== Managing Services with sv ===== | ||
To see the status of a supervised service use '' | To see the status of a supervised service use '' | ||
Line 326: | Line 347: | ||
sv s /service/* | sv s /service/* | ||
</ | </ | ||
- | ==== 7.1. Stop/ | + | |
+ | ==== Stop/ | ||
Start a service | Start a service | ||
Line 346: | Line 368: | ||
</ | </ | ||
- | Each of these is a shortcut, for ‘up’, ‘down’, and ‘terminate’, respectively. Only the first letter of each word is recognised. | + | Each of these is a shortcut, for 'up', 'down', and 'terminate', respectively. Only the first letter of each word is recognised. |
- | More verbose forms of the above | + | |
+ | More verbose forms of the above: | ||
< | < | ||
- | sv start sshd | + | sv start example |
- | sv stop sshd | + | sv stop example |
- | sv restart | + | sv restart |
</ | </ | ||
Each of these will also return the status of the service upon exit. | Each of these will also return the status of the service upon exit. | ||
- | ==== 7.2. Enabling a service ==== | + | ==== Enabling a service ==== |
Service directories are placed under ''/ | Service directories are placed under ''/ | ||
Line 369: | Line 392: | ||
Once a service is linked it will always start on boot and restart if it stops (unless this is disabled). | Once a service is linked it will always start on boot and restart if it stops (unless this is disabled). | ||
- | ==== 7.3. Disabling a service ==== | + | ==== Disabling a service ==== |
To disable a service in the current runlevel remove the symlink to its service directory from ''/ | To disable a service in the current runlevel remove the symlink to its service directory from ''/ | ||
Line 390: | Line 413: | ||
touch / | touch / | ||
</ | </ | ||
- | ==== 7.4. Dependencies ==== | + | |
+ | ==== Dependencies ==== | ||
Dependencies of service are supported by starting the dependent run script as follows: | Dependencies of service are supported by starting the dependent run script as follows: | ||
Line 399: | Line 423: | ||
. | . | ||
. | . | ||
- | exec … | + | exec ... |
</ | </ | ||
- | ===== 8. Runlevels ===== | ||
- | If you installed the slackbuild configuration files, you have two runlevels: default and single. The current runlevel is default. You can verify by looking under ''/ | + | ==== Runlevels ==== |
+ | |||
+ | If you installed the slackbuild configuration files, you have two runlevels: default and single. The current runlevel is default. You can verify by looking under ''/ | ||
Change runlevel to another runlevel; single: | Change runlevel to another runlevel; single: | ||
Line 411: | Line 436: | ||
</ | </ | ||
- | You will see that ''/ | + | You will see that ''/ |
< | < | ||
Line 417: | Line 442: | ||
</ | </ | ||
- | You can create any other runlevel and name them as you like. To start you can copy an existing runlevel directory and modify as you wish. | + | You can create any other runlevel and name them as you like. To start, you can copy an existing runlevel directory and modify as you wish. |
< | < | ||
Line 424: | Line 449: | ||
You can edit the runsvdir line of ''/ | You can edit the runsvdir line of ''/ | ||
- | ===== 9. run scripts ===== | ||
- | Only one executable can be called for a service | + | ===== Run scripts ===== |
+ | |||
+ | Only one executable can be called for a service | ||
+ | |||
+ | Another set of installable run scripts are available at [[https:// | ||
- | In direct contrast to Slackware’s BSD style service scripts, runit run scripts must not must run in the foreground, otherwise runit would think that they have crashed and restart them. | + | In direct contrast to Slackware's BSD style service scripts, runit run scripts must not must run in the foreground, otherwise runit would think that they have crashed and restart them. |
For some services, this may not be possible, but there are workarounds. You can forcefully terminate them by ending the run script like this: | For some services, this may not be possible, but there are workarounds. You can forcefully terminate them by ending the run script like this: | ||
Line 436: | Line 464: | ||
</ | </ | ||
- | Or you can use the '' | + | Or you can use the '' |
< | < | ||
Line 442: | Line 470: | ||
</ | </ | ||
- | ===== 10. Migrating Services ===== | + | ===== Migrating Services ===== |
- | It is suggested that services are migrated from stage 2 (which are still under the Slackware’s BSD init scheme) to stage 3 carefully. Start from the bottom of ''/ | + | It is suggested that services are migrated from stage 2 (which are still under the Slackware's BSD init scheme) to stage 3 carefully. Start from the bottom of ''/ |
Then continue for ''/ | Then continue for ''/ | ||
- | Proceed with other services to benefit’s from runit features. Note that for some services, such as '' | + | Proceed with other services to benefit's from runit features. Note that for some services, such as '' |
- | Let’s take the popular '' | + | Let's take the popular '' |
Stop the service: | Stop the service: | ||
Line 489: | Line 517: | ||
</ | </ | ||
- | For '' | + | If run exits and '' |
- | ===== 11. Sources | + | It is stuggested to let '' |
- | + | ||
- | (1) http://smarden.org/runit/ | + | ===== Using runit-init with other init scripts |
+ | |||
+ | ==== OpenRC ==== | ||
+ | |||
+ | Here '' | ||
+ | |||
+ | It requires a working OpenRC system. Check the [[howtos:general_admin: | ||
+ | The level 1 runit service uses the OpenRC '' | ||
- | (2) https://slackbuilds.org | + | The [[https://wiki.gentoo.org/ |
- | (3) https:// | + | ==== void-runit ==== |
- | (4) https://voidlinux.org/usage/runit/ | + | Here the scripts provided by the [[https://github.com/void-linux/void-runit|void-runit]] project are used to mount the filesystem, load modules, etc. |
- | (5) https://www.youtube.com/ | + | Currently this is the most independent way to setup runit. |
- | (6) http:// | + | ===== Sources ===== |
- | (7) https:// | + | - http:// |
+ | - https:// | ||
+ | - https:// | ||
+ | - https:// | ||
+ | - http:// | ||
+ | - https:// | ||
+ | - https:// | ||
+ | - https:// | ||
+ | - https:// | ||
+ | - https:// | ||
- | (8) https:// | + | ---- |
* Written for Slackware 14.2 in December 2018 | * Written for Slackware 14.2 in December 2018 |