[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.

Welcome to the Slackware Documentation Project

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
howtos:slackware_admin:runit [2019/05/28 12:11 (UTC)] – Improvements and clarifications in Chapter 6 chrisabelahowtos:slackware_admin:runit [2020/05/06 08:08 (UTC)] (current) – [Startup and Shutdown] chrisabela
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, a replacement for sysvinit, and other init schemes and supervision that are used with the traditional init. runit is compatible with djb's daemontools. runit is a UNIX init scheme with service supervision. It is a cross-platform Unix init scheme with service supervision, a replacement for sysvinit, and other init schemes and supervision that are used with the traditional init. runit is compatible with djb's daemontools.
Line 11: Line 11:
 To read on the benefits of runit, see here: http://smarden.org/runit/benefits.html To read on the benefits of runit, see here: http://smarden.org/runit/benefits.html
  
-===== 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://slackbuilds.org/. It does not have any dependencies. runit is not provided by Slackware, but a SlackBuild is maintained on https://slackbuilds.org/. It does not have any dependencies.
Line 29: Line 31:
 </code> </code>
  
-For a typical Slackware-stlyle service, you can also edit ''/etc/rc.d/rc.local'' file+==== Starting via rc.local ==== 
 + 
 +For a typical Slackware-stlyle service, you can edit ''/etc/rc.d/rc.local'' file
  
 <code> <code>
Line 36: Line 40:
 fi fi
 </code> </code>
- 
-if you require it. 
  
 and then edit write ''/etc/rc.d/rc.local_shutdown'' and then edit write ''/etc/rc.d/rc.local_shutdown''
Line 57: Line 59:
 and reboot and reboot
  
-===== 3. Using runit with sysvinit and inittab =====+==== Starting via inittab (supervised) ====
  
 Remove the entries in ''/etc/rc.d/rc.local'' and ''/etc/rc.d/rc.local_shutdown'' described above.  Remove the entries in ''/etc/rc.d/rc.local'' and ''/etc/rc.d/rc.local_shutdown'' described above. 
Line 77: Line 79:
 or reboot  or reboot 
  
-===== 4. How to replace init with runit =====+===== How to replace init with runit ===== 
 + 
 +runit provides ''runit-init'' which can be used to boot up the system.
  
 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 the last line from ''/etc/inittab''+So, remove the last line from ''/etc/inittab''
  
 <code> <code>
Line 87: Line 91:
 </code> </code>
  
-Reboot:+And reboot:
  
 <code> <code>
Line 184: Line 188:
 However, with the last alternative, be warned that if you had booted with the original init, the system may refuse to reboot, therefore boot from runit-init first.  However, with the last alternative, be warned that if you had booted with the original init, the system may refuse to reboot, therefore boot from runit-init first. 
  
-===== 5. Startup and Shutdown =====+==== Startup and Shutdown ====
  
-The traditional init reads ''/etc/inittab'' file to see how to run the system. It runs the ''/etc/rc.d/rc.S'' script and runs it. If set in the default runlevel 3, it follows it with ''/etc/rc.d/rc.M''. In runit the initialisation script is located in ''/etc/runit/1'' for all runlevels. By default ''/etc/runit/2'' is restricted to the TTY services. +The BSD style init scripts provided by Slackware are used to bring up the system. 
 + 
 +Initially the single user script ''/etc/rc.d/rc.S'' runs. If set in the default runlevel 3, it follows it with ''/etc/rc.d/rc.M''. In runit the initialisation script is located in ''/etc/runit/1'' for all runlevels. By default ''/etc/runit/2'' is restricted to the TTY services. 
  
 The script ''/etc/rc.d/rc.6'' is the rebooting script for the traditional init, while ''/etc/rc.d/rc.0'' (symlinked to the former) is the halting script. In runit, these scripts are called by ''/etc/runit/3'' The script ''/etc/rc.d/rc.6'' is the rebooting script for the traditional init, while ''/etc/rc.d/rc.0'' (symlinked to the former) is the halting script. In runit, these scripts are called by ''/etc/runit/3''
Line 215: Line 221:
 However consider that shutdown would not work for the original init. However consider that shutdown would not work for the original init.
  
-===== 6. runsv =====+===== runsv =====
  
 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 and makes the task easier. This short example should help illustrate runsv to new users. 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 and makes the task easier. This short example should help illustrate runsv to new users.
Line 225: Line 231:
 </code> </code>
  
-In order to let the non-privileged user (say user bob) run it, change the ownership of the service directory +As a non-priviliged user (say user bob), create some directories:
- +
-<code> +
-chown bob.users /etc/sv/example +
-</code> +
- +
-As a non-priviliged user, create some directories+
  
 <code> <code>
Line 237: Line 237:
 </code> </code>
  
-Then edit a script that simulates a (finicky) service in a convenient directory; say +Then edit a ''/home/bob/runit/service.sh'' script that simulates a (finicky) service in a convenient directory; say 
  
 <code> <code>
Line 263: Line 263:
 </code> </code>
  
-Edit a file called ''/etc/sv/example/run'' and give it executable permissions+Log in back as root and edit a file called ''/etc/sv/example/run'' and give it executable permissions:
  
 <code> <code>
Line 298: Line 298:
 </code> </code>
  
-Log in as root and run the sv service to ensure that it works:+Run the service to ensure that it works:
  
 <code> <code>
-su - 
 /etc/sv/example/run /etc/sv/example/run
 </code> </code>
Line 317: Line 316:
 <code> <code>
 tail -f /home/bob/runit/logs/current  tail -f /home/bob/runit/logs/current 
-CTRL+c 
 </code> </code>
  
-===== 7.  Managing Services with sv =====+Hit CTRL+C to exit. 
 + 
 +Finally, login back as root and let bob take the ownership of the whole ''/etc/sv/example/'' directory: 
 + 
 +<code> 
 +chown -R bob.users /etc/sv/example/ 
 +</code> 
 + 
 +Now bob can manage this service with the ''sv'' command. Note that in most cases, services should belong to root, and only to root. 
 + 
 +=====  Managing Services with sv =====
  
 To see the status of a supervised service use ''sv s <service_name>'', for example, To see the status of a supervised service use ''sv s <service_name>'', for example,
Line 340: Line 348:
 </code> </code>
  
-==== 7.1. Stop/Start/Restart ====+==== Stop/Start/Restart ====
  
 Start a service Start a service
Line 365: Line 373:
  
 <code> <code>
-sv start sshd+sv start example
  
-sv stop sshd+sv stop example
  
-sv restart sshd+sv restart example
 </code> </code>
  
 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 ''/etc/sv/''. To enable a service in the current runlevel, create a symlink from it to ''/service''. Service directories are placed under ''/etc/sv/''. To enable a service in the current runlevel, create a symlink from it to ''/service''.
Line 384: 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 ''/service''. To disable a service in the current runlevel remove the symlink to its service directory from ''/service''.
Line 406: Line 414:
 </code> </code>
  
-==== 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 418: Line 426:
 </code> </code>
  
-===== 8. Runlevels =====+==== 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 ''/etc/runit/runsvdir/,'' you will see that ''/etc/runit/current'' is a symbolic link ''/etc/runit/default''.+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 ''/etc/runit/runsvdir/,'' you will see that ''/etc/runit/runsvdir/current'' is a symbolic link ''/etc/runit/runsvdir/default/''.
  
 Change runlevel to another runlevel; single: Change runlevel to another runlevel; single:
Line 428: Line 436:
 </code> </code>
  
-You will see that ''/etc/runit/runsvdir/current'' is now symlinked to ''/etc/runit/runsvdir/single'' and ''/etc/runit/runsvdir/previous'' is symlinked to ''/etc/runsvdir/default''. If you reboot, you will boot again default runlevel as you have this entry in ''/etc/runit/2''+You will see that ''/etc/runit/runsvdir/current'' is now symlinked to ''/etc/runit/runsvdir/single'' and ''/etc/runit/runsvdir/previous'' is symlinked to ''/etc/runsvdir/default''. If you reboot, you will boot again on the default runlevel as you have this entry in ''/etc/runit/2''
  
 <code> <code>
Line 434: Line 442:
 </code> </code>
  
-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 startyou can copy an existing runlevel directory and modify as you wish. 
  
 <code> <code>
Line 442: Line 450:
 You can edit the runsvdir line of ''/etc/runit/2'' to your requirements. You can edit the runsvdir line of ''/etc/runit/2'' to your requirements.
  
-===== 9. run scripts =====+===== Run scripts =====
  
-Only one executable can be called for a service and the last line must be called by the ''exec'' command. There are some generic runit run scripts on the Internet, in other Linux distributions. Also, other Slackers may post them on publicly available repositories. The author of this article has placed his here: https://gitlab.com/chrisabela/runit_scripts_for_slackware+Only one executable can be called for a service (the last line) and it must be called by the ''exec'' command. There are some generic runit run scripts on the Internet and on other Linux distributions. Also, other Slackers may post them on publicly available repositories. The author of this article has placed his here: https://gitlab.com/chrisabela/runit_scripts_for_slackware 
 + 
 +Another set of installable run scripts are available at [[https://slackbuilds.org/repository/14.2/system/runit-services/|SBo]].
  
 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.
Line 454: Line 464:
 </code> </code>
  
-Or you can use the ''pause'' command to keep the service alive. ''pause'' is a trivial command that will simply not exit, until it is killed (akin to tail -f /dev/null). A SlackBuild for ''pause'' is available at https://slackbuilds.org Then end the run script with:+Or you can use the ''pause'' command to keep the service alive. ''pause'' is a trivial command that will simply not exit, until it is killed (akin to tail -f /dev/null). A SlackBuild for ''pause'' is available at [[https://slackbuilds.org/repository/14.2/system/pause/|SBo]]. Then end the run script with:
  
 <code> <code>
Line 460: Line 470:
 </code> </code>
  
-===== 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 ''/etc/rc.d/rc.M'' and work up. This means that you should start with any entries under ''/etc/rc.d/rc.local''  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 ''/etc/rc.d/rc.M'' and work up. This means that you should start with any entries under ''/etc/rc.d/rc.local'' 
Line 511: Line 521:
 It is stuggested to let ''udev'' under runit's stage 2, but you can setup its monitoring for stage 3.  It is stuggested to let ''udev'' under runit's stage 2, but you can setup its monitoring for stage 3. 
  
-===== 11. Sources ===== +===== Using runit-init with other init scripts =====
-  +
-(1) http://smarden.org/runit/+
  
-(2) https://slackbuilds.org+==== OpenRC ====
  
-(3) https://en.wikipedia.org/wiki/Init+Here ''runit-init'' is used for booting, which then transfers control to the OpenRC for things like mounting the filesystem, loading modules, running udev, etc.
  
-(4) https://voidlinux.org/usage/runit/+It requires a working OpenRC system. Check the [[howtos:general_admin:openrc]] page for instructions. 
 +The level 1 runit service uses the OpenRC ''boot'' and ''sysinit'' runlevels.
  
-(5) https://www.youtube.com/watch?v=jiBlIhFxNJo+The [[https://wiki.gentoo.org/wiki/Runit#Runit_as_the_init_system|gentoo wiki]] has more information, and [[https://gitlab.com/aadityabagga/runit-init-openrc|runit-init-openrc]] details how to install and set it up.
  
-(6) http://kchard.github.io/runit-quickstart/+==== void-runit ====
  
-(7) https://www.slackbook.org/beta/+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.
  
-(8) https://gitlab.com/chrisabela/runit_scripts_for_slackware+Currently this is the most independent way to setup runit. 
 + 
 +===== Sources ===== 
 + 
 +  - http://smarden.org/runit/ 
 +  - https://en.wikipedia.org/wiki/Init 
 +  - https://voidlinux.org/usage/runit/ 
 +  - https://www.youtube.com/watch?v=jiBlIhFxNJo 
 +  - http://kchard.github.io/runit-quickstart/ 
 +  - https://www.slackbook.org/beta/ 
 +  - https://gitlab.com/chrisabela/runit_scripts_for_slackware 
 +  - https://github.com/aadityabagga/runit-services 
 +  - https://wiki.gentoo.org/wiki/Runit 
 +  - https://github.com/void-linux/void-runit 
 + 
 +----
  
   * Written for Slackware 14.2 in December 2018   * Written for Slackware 14.2 in December 2018
Line 533: Line 557:
 <!-- Please do not modify anything below, except adding new tags.--> <!-- Please do not modify anything below, except adding new tags.-->
 {{tag>init runit}} {{tag>init runit}}
 +
 howtos:slackware_admin:runit ()