[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 | ||
playground:runit [2018/12/19 20:03 (UTC)] – [7. Managing Services with sv] chrisabela | playground:runit [2018/12/19 20:22 (UTC)] – [10. Migrating Services] chrisabela | ||
---|---|---|---|
Line 330: | Line 330: | ||
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 348: | 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 353: | 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 369: | 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 384: | 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 450: | 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 '' |