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 revision Previous revision
Next revision
Previous revision
howtos:slackware_admin:runit [2019/01/09 13:38 (UTC)]
chrisabela [4. How to replace init with runit]
howtos:slackware_admin:runit [2019/02/13 11:02 (UTC)] (current)
chrisabela
Line 44: Line 44:
 #!/bin/sh #!/bin/sh
 RUNIT=x$( /sbin/pidof runsvdir ) RUNIT=x$( /sbin/pidof runsvdir )
-if [ $RUNIT” !=  x ]; then+if [ "$RUNIT" ​!=  x ]; then
   kill $RUNIT   kill $RUNIT
 fi fi
Line 188: Line 188:
 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 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 script ''/​etc/​rc.d/​rc.6''​ is the rebooting script for the traditional init, while ''/​etc/​rc.d/​rc.0''​ (symlinked to 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''​
  
 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 205: Line 205:
  
 The ''​halt'',​ ''​reboot''​ and ''​poweroff''​ commands provided by the sysvinit package would still work with runit. The ''​halt'',​ ''​reboot''​ and ''​poweroff''​ commands provided by the sysvinit package would still work with runit.
 +
 +Desktop Environments call ''/​sbin/​shutdown''​ so they will not work until you move this file and symlink it to ''/​usr/​sbin/​shutdown''​
 +
 +<​code>​
 +mv /​sbin/​shutdown /​sbin/​shutdown.sysv
 +ln -s /​usr/​sbin/​shutdown /​sbin/​shutdown
 +</​code>​
 +
 +However consider that shutdown would not work for the original init.
  
 ===== 6. runsv ===== ===== 6. runsv =====
  
-Although runit may replace init as the PID 1 daemon, there is not much benefit unless other services are migrated from Slackwares BSD style to runsv(8). While this is not a complicated task, some familiarisation with runits 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.
  
 Make an arbitrary directory under ''/​etc/​sv/''​ Make an arbitrary directory under ''/​etc/​sv/''​
Line 301: Line 310:
 </​code>​ </​code>​
  
-Watch how your service” works, crashes, but it is recovered by runit:+Watch how your "service" ​works, crashes, but it is recovered by runit:
  
 <​code>​ <​code>​
Line 326: Line 335:
 sv s /service/* sv s /service/*
 </​code>​ </​code>​
 +
 ==== 7.1. Stop/​Start/​Restart ==== ==== 7.1. Stop/​Start/​Restart ====
  
Line 346: Line 356:
 </​code>​ </​code>​
  
-Each of these is a shortcut, for updown, 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
  
Line 390: Line 400:
 touch /​etc/​sv/​service/​down touch /​etc/​sv/​service/​down
 </​code>​ </​code>​
 +
 ==== 7.4. Dependencies ==== ==== 7.4. Dependencies ====
  
Line 399: Line 410:
 . .
 . .
-exec +exec ...
 </​code>​ </​code>​
 +
 ===== 8. Runlevels ===== ===== 8. Runlevels =====
  
Line 424: Line 436:
  
 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 ===== ===== 9. 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 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
  
-In direct contrast to Slackwares 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 444: Line 457:
 ===== 10. Migrating Services ===== ===== 10. Migrating Services =====
  
-It is suggested that services are migrated from stage 2 (which are still under the Slackwares 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'' ​
  
 Then continue for ''/​etc/​rc.d/​rc.S''​ Then continue for ''/​etc/​rc.d/​rc.S''​
  
-Proceed with other services to benefits from runit features. Note that for some services, such as ''​atd''​ and ''​crond'',​ you would need to edit ''/​etc/​rc.d/​rc.M''​ as they are hard-coded.+Proceed with other services to benefit's from runit features. Note that for some services, such as ''​atd''​ and ''​crond'',​ you would need to edit ''/​etc/​rc.d/​rc.M''​ as they are hard-coded.
  
-Lets take the popular ''​NetworkManager''​ service as an example. According to the permission of ''/​etc/​rc.d/​rc.networkmanager''​ this script is called by ''/​etc/​rc.d/​rc.M''​ The latter is called by ''/​etc/​runit/​2''​ (stage 2).+Let's take the popular ''​NetworkManager''​ service as an example. According to the permission of ''/​etc/​rc.d/​rc.networkmanager''​ this script is called by ''/​etc/​rc.d/​rc.M''​ The latter is called by ''/​etc/​runit/​2''​ (stage 2).
  
 Stop the service: Stop the service:
Line 489: Line 502:
 </​code>​ </​code>​
  
-For ''​udev'',​ it is stuggested to let it under runits stage 2, but you can setup its monitoring for stage 3. +If run exits and ''​/​etc/​sv/<​service name>/​finish'' ​exists (typically when the service is switched off)''​runsv''​ runs ''​finish''​ if it has executable permission. 
 + 
 +It is stuggested to let ''​udev'' ​under runit's stage 2, but you can setup its monitoring for stage 3. 
  
 ===== 11. Sources ===== ===== 11. Sources =====
Line 513: Line 528:
 <!-- 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}}
 +
  

In Other Languages
QR Code
QR Code howtos:slackware_admin:runit (generated for current page)