[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 revisionLast revisionBoth sides next revision | ||
playground:runit [2018/12/19 19:29 (UTC)] – chrisabela | playground:runit [2018/12/19 20:26 (UTC)] – [10. Migrating Services] chrisabela | ||
---|---|---|---|
Line 59: | Line 59: | ||
===== 3. Using runit with sysvinit and inittab ===== | ===== 3. Using runit with sysvinit and inittab ===== | ||
- | Remove the entries in / | + | Remove the entries in '' |
- | Edit / | + | Edit '' |
+ | < | ||
cat >>/ | cat >>/ | ||
SV: | SV: | ||
EOT | EOT | ||
+ | </ | ||
+ | |||
and tell init to re-read its configuration, | and tell init to re-read its configuration, | ||
+ | |||
+ | < | ||
init q | init q | ||
+ | </ | ||
+ | |||
or reboot | or reboot | ||
Line 74: | Line 81: | ||
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 / | + | Remove the last line from '' |
+ | < | ||
rm -rf /etc/runit /service | rm -rf /etc/runit /service | ||
+ | </ | ||
Reboot: | Reboot: | ||
+ | < | ||
shutdown -r now | shutdown -r now | ||
+ | </ | ||
Also, it is best to re-build and re-install runit | Also, it is best to re-build and re-install runit | ||
Line 86: | Line 97: | ||
This time, when running slackbuild, do pass any value for CONFIG, or set it to yes: | This time, when running slackbuild, do pass any value for CONFIG, or set it to yes: | ||
+ | < | ||
unset CONFIG | unset CONFIG | ||
- | ./runit.SlackBuild | + | sh runit.SlackBuild |
+ | </ | ||
and upgrade with the resulting runit package. | and upgrade with the resulting runit package. | ||
Line 93: | Line 106: | ||
Disable services that are already provided by the traditional init: | Disable services that are already provided by the traditional init: | ||
+ | < | ||
cd /service/ | cd /service/ | ||
rm * | rm * | ||
+ | </ | ||
Create a new TTY service for runit: | Create a new TTY service for runit: | ||
+ | < | ||
cd /etc/sv/ | cd /etc/sv/ | ||
cp -ar agetty-tty1/ | cp -ar agetty-tty1/ | ||
sed -i ' | sed -i ' | ||
ln -s / | ln -s / | ||
+ | </ | ||
Start runit' | Start runit' | ||
- | / | + | < |
+ | / | ||
+ | </ | ||
- | And check that the agetty is running, by logging in as an unpriviliged | + | And check that the agetty is running, by logging in as an unprivileged |
+ | < | ||
CTRL+ALT+F8 | CTRL+ALT+F8 | ||
+ | </ | ||
If this has been successful, then reverse the last intervention: | If this has been successful, then reverse the last intervention: | ||
+ | < | ||
kill $( pidof runsvdir ) | kill $( pidof runsvdir ) | ||
Line 120: | Line 142: | ||
ln -s / | ln -s / | ||
done | done | ||
+ | </ | ||
- | Then, to boot in runit, reboot and enter init=/ | + | Then, to boot in runit, reboot and enter '' |
+ | {{: | ||
+ | //Image 1.: Hit the Tab key on the Lilo Menu before the counter times out.// | ||
- | Image 1.: Hit the Tab key on the Lilo Menu before the counter times out. | + | {{:playground:runit-init.png?400|}} |
- | + | ||
- | + | ||
- | Image 2: Add init=/sbin/runit-init | + | |
+ | //Image 2: Add init=/ | ||
Confirm that runit has taken PID 1: | Confirm that runit has taken PID 1: | ||
+ | < | ||
ps -o comm= -p 1 | ps -o comm= -p 1 | ||
runit | runit | ||
+ | </ | ||
- | If you do not have a multi boot system, you may append the init selection | + | If you do not have a multi boot system, you may append the init selection |
- | in / | + | |
For example: | For example: | ||
+ | < | ||
append=" | append=" | ||
+ | < | ||
Then run lilo: | Then run lilo: | ||
- | # lilo -v | ||
- | Or just replace /sbin/init with / | + | < |
- | mv /sbin/init / | + | lilo -v |
+ | </ | ||
+ | |||
+ | Or just replace | ||
+ | |||
+ | < | ||
+ | cp /sbin/init / | ||
cp / | cp / | ||
+ | </ | ||
However, with the last alternative, | However, with the last alternative, | ||
Line 154: | Line 186: | ||
===== 5. Startup and Shutdown ===== | ===== 5. Startup and Shutdown ===== | ||
- | The traditional init reads / | + | The traditional init reads '' |
+ | |||
+ | The script ''/ | ||
+ | |||
+ | Note that the shutdown command provided by sysvinit package will not work in runit. To reboot you enter | ||
+ | |||
+ | < | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | and to halt enter | ||
- | The script | + | < |
+ | /sbin/runit-init 0 | ||
+ | </code> | ||
- | Note that the shutdown command provided by sysvinit package will not work in runit. To reboot you enter / | + | A convenient script is provided with the configuration files which is placed in '' |
- | The halt, reboot and poweroff commands provided by the sysvinit package would still work with runit. | + | The '' |
===== 6. runsv ===== | ===== 6. runsv ===== | ||
Line 166: | Line 210: | ||
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. | ||
- | Make an arbitrary directory under /etc/sv/ | + | Make an arbitrary directory under '' |
+ | < | ||
mkdir / | mkdir / | ||
+ | </ | ||
In order to let the non-privileged user (say user chris) run it, change the ownership of the service | In order to let the non-privileged user (say user chris) run it, change the ownership of the service | ||
+ | < | ||
chmod -R chris.users / | chmod -R chris.users / | ||
+ | </ | ||
- | As a non-priviliged | + | As a non-priviliged |
+ | < | ||
mkdir -p / | mkdir -p / | ||
+ | </ | ||
Then edit a script that simulates a (finicky) service in a convenient directory; say | Then edit a script that simulates a (finicky) service in a convenient directory; say | ||
+ | < | ||
#!/bin/bash | #!/bin/bash | ||
echo " | echo " | ||
for i in {1..10} | for i in {1..10} | ||
do | do | ||
- | | + | |
- | sleep 1 | + | sleep 1 |
done | done | ||
echo "Oh no I crashed..." | echo "Oh no I crashed..." | ||
exit 1 | exit 1 | ||
+ | </ | ||
Give it executable permission: | Give it executable permission: | ||
+ | < | ||
chmod +x / | chmod +x / | ||
+ | </ | ||
Run it to check and appreciate its execution: | Run it to check and appreciate its execution: | ||
+ | < | ||
/ | / | ||
+ | </ | ||
- | Log back to root, and edit a file called / | + | Log back to root, and edit a file called |
+ | < | ||
#!/bin/sh -e | #!/bin/sh -e | ||
exec 2>&1 | exec 2>&1 | ||
exec chpst -u chris / | exec chpst -u chris / | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | chmod +x / | ||
+ | </ | ||
Note the exec in the last line, it tells the shell that interprets the script to replace itself with the service daemon | Note the exec in the last line, it tells the shell that interprets the script to replace itself with the service daemon | ||
Naturally edit as necessary. | Naturally edit as necessary. | ||
- | |||
- | chmod +x / | ||
Create another directory: | Create another directory: | ||
+ | < | ||
mkdir / | mkdir / | ||
+ | </ | ||
- | 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 / | exec chpst -u chris svlogd -tt / | ||
+ | </ | ||
Give it executable permission: | Give it executable permission: | ||
+ | < | ||
chmod +x / | chmod +x / | ||
+ | </ | ||
Run the sv service to ensure that it works: | Run the sv service to ensure that it works: | ||
+ | < | ||
/ | / | ||
+ | </ | ||
- | Finally, we are ready to deploy the service. Create a symbolic link in /service to our staging location. | + | Finally, we are ready to deploy the service. Create a symbolic link in '' |
+ | < | ||
ln -s / | ln -s / | ||
+ | </ | ||
Watch how your “service” works, crashes, but it is recovered by runit: | Watch how your “service” works, crashes, but it is recovered by runit: | ||
+ | < | ||
tail -f / | tail -f / | ||
+ | </ | ||
===== 7. Managing Services with sv ===== | ===== 7. Managing Services with sv ===== | ||
- | To see the status of a supervised service use sv s < | + | To see the status of a supervised service use '' |
+ | |||
+ | < | ||
sv s example | sv s example | ||
+ | </ | ||
returns | returns | ||
+ | < | ||
run: example: (pid 42) 1587s | run: example: (pid 42) 1587s | ||
+ | </ | ||
To see the status of all services, use | To see the status of all services, use | ||
- | sv s /service/*. | + | < |
+ | sv s / | ||
+ | </ | ||
==== 7.1 Stop/ | ==== 7.1 Stop/ | ||
Start a service | Start a service | ||
+ | < | ||
sv u example | sv u example | ||
+ | </ | ||
Stop a service | Stop a service | ||
+ | < | ||
sv d example | sv d example | ||
+ | </ | ||
Restart a service | Restart a service | ||
+ | < | ||
sv t example | sv t example | ||
+ | </ | ||
Each of these is a shortcut, for ‘up’, ‘down’, and ‘terminate’, | Each of these is a shortcut, for ‘up’, ‘down’, and ‘terminate’, | ||
More verbose forms of the above | More verbose forms of the above | ||
+ | < | ||
sv start sshd | sv start sshd | ||
Line 270: | Line 355: | ||
sv restart sshd | sv restart sshd | ||
+ | </ | ||
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. | ||
Line 275: | Line 361: | ||
==== 7.2 Enabling a service ==== | ==== 7.2 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 '' |
+ | < | ||
ln -s / | ln -s / | ||
+ | </ | ||
- | Once a service is linked it will always start on boot and restart if it stops (unless | + | Once a service is linked it will always start on boot and restart if it stops (unless |
- | Disabling a service | + | ==== 7.3 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 '' |
+ | < | ||
rm / | rm / | ||
+ | </ | ||
Removing the symlink will also stop the service. | Removing the symlink will also stop the service. | ||
Line 291: | Line 381: | ||
Check out the sv man page to see additional options. | Check out the sv man page to see additional options. | ||
+ | < | ||
man sv | man sv | ||
+ | </ | ||
- | If you do not want a service to start upon bootup, or when enabled, just touch an empty file called down in the appropriate service directory. | + | If you do not want a service to start upon bootup, or when enabled, just touch an empty file called |
+ | < | ||
touch / | touch / | ||
- | + | </ | |
- | ==== 7.3 Dependencies ==== | + | ==== 7.4 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: | ||
+ | < | ||
#!/bin/sh | #!/bin/sh | ||
sv start dependent-service || exit 1 | sv start dependent-service || exit 1 | ||
Line 306: | Line 400: | ||
. | . | ||
exec … | exec … | ||
+ | </ | ||
===== 8. Runlevels ===== | ===== 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 / | + | 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: | ||
+ | < | ||
runsvchdir single | runsvchdir single | ||
+ | </ | ||
- | You will see that / | + | You will see that '' |
- | and / | + | |
+ | < | ||
runsvchdir default >/ | runsvchdir default >/ | ||
+ | </ | ||
- | You can create any other runlevels | + | You can create any other runlevel |
+ | < | ||
cp -ar / | cp -ar / | ||
+ | </ | ||
- | Likewise, you edit the runsvdir line of / | + | You can edit the runsvdir line of '' |
===== 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 | + | Only one executable can be called for a service and the last line must be called by the '' |
- | 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 that 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: | ||
+ | < | ||
sv d service_name | sv d service_name | ||
+ | </ | ||
- | 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 tail -f /dev/null). A slackbuild | + | Or you can use the '' |
+ | < | ||
exec chpst -b service_name pause | exec chpst -b service_name pause | ||
+ | </ | ||
===== 10. Migrating Services ===== | ===== 10. 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 end 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 |
- | Then continue for / | + | Then continue for '' |
- | 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 / | + | Proceed with other services to benefit’s from runit features. Note that for some services, such as '' |
- | Let’s take the popular NetworkManager service as an example. According to the permission of / | + | Let’s take the popular |
Stop the service: | Stop the service: | ||
+ | < | ||
/ | / | ||
+ | </ | ||
Disable it: | Disable it: | ||
+ | < | ||
chmod -x / | chmod -x / | ||
+ | </ | ||
Create a suitable directory for runit | Create a suitable directory for runit | ||
+ | < | ||
mkdir / | mkdir / | ||
+ | </ | ||
- | Write a runit run script: / | + | Write a runit run script: |
+ | < | ||
#!/bin/sh | #!/bin/sh | ||
prefix=/usr | prefix=/usr | ||
Line 372: | Line 481: | ||
export XDG_CACHE_HOME=/ | export XDG_CACHE_HOME=/ | ||
exec $NETWORKMANAGER_BIN -n > /dev/null 2>&1 | exec $NETWORKMANAGER_BIN -n > /dev/null 2>&1 | ||
+ | </ | ||
- | Symlink | + | Symlink |
+ | < | ||
ln -s / | ln -s / | ||
+ | </ | ||
- | For udev, it is stuggested to let it under runit’s stage 2, but you can setup its monitoring for stage 3. | + | For '' |
+ | ===== 11 Sources ===== | ||
+ | |||
+ | (1) http:// | ||
- | Sources: | + | (2) https://slackbuilds.org |
- | http://smarden.org/runit/ | + | |
- | https://slackbuilds.org | + | (3) https://en.wikipedia.org/wiki/Init |
- | https://en.wikipedia.org/wiki/Init | + | (4) https://voidlinux.org/usage/runit/ |
- | https://voidlinux.org/ | + | (5) https://www.youtube.com/watch? |
- | https://www.youtube.com/watch? | + | (6) http://kchard.github.io/ |
- | http://kchard.github.io/runit-quickstart/ | + | (7) https://www.slackbook.org/beta/ |
- | https://www.slackbook.org/beta/ | + | (8) https://gitlab.com/chrisabela/runit_scripts_for_slackware |
- | https:// | + | * Written for Slackware 14.2 in December 2018 |
+ | * Originally written by [[wiki: | ||
+ | <!-- Please do not modify anything below, except adding new tags.--> | ||
+ | {{tag> | ||
- | Author: Chris Abela for Slackware 14.2 | ||
- | December 2018 |