Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for declaring service dependencies seems to contradict itself #28

Open
pascal-fb-martin opened this issue Aug 28, 2023 · 1 comment

Comments

@pascal-fb-martin
Copy link

I am going through the runit documentation, starting with the Q&A:

How do I make a service depend on another service
I have a service that needs another service to be available before it can start. How can I tell runit about this dependency?
Answer: Make sure in the ./run script of the dependant service that the service it depends on is available before the service daemon starts. The sv program can be used for that. E.g. the cron service wants the socklog-unix system logging service to be available before starting the cron service daemon, so no logs get lost:

$ cat /etc/sv/cron/run
#!/bin/sh
sv start socklog-unix || exit 1
exec cron -f
$
See also the documentation.

Following the "documentation" link above leads to this less clear description:

runit's service supervision resolves dependencies for service daemons designed to be run by a supervisor process automatically. The service daemon (or the corresponding run scripts) should behave as follows:
before providing the service, check if all services it depends on are available. If not, exit with an error, the supervisor will then try again.
write all logs through runit's logging facility. The runsv program takes care that all logs for the service are written safely to disk. Therefore there's no need to depend on a system logging service.
optionally when the service is told to become down, take down other services that depend on this one after disabling the service.
If you want to run service daemons that do not support service supervision as described above, please refer to this page about service dependencies I wrote some time ago.

I am not sure what "do not support service supervision" means. The service I depend on is also started through runit.

Following the this page link above leads to a third seemingly conflicting description:

Service dependency
If you really have a service that needs another service up and running before starting, you can use the svwaitup program included in the runit package.
Add a line like this to the service's run script:

#!/bin/sh
svwaitup 3 /service/tinydns /service/dnscache || exit 1
exec /example/service/startup
This will cause this service to start as soon as /service/tinydns and /service/dnscache were at least 3 seconds up and running.
For each service it depends on, add the corresponding service directory to the arguments of svwaitup.

Note that there is always a race condition, the service it depends on could die just in the moment it was 3 seconds up.

The svwaitup is nowhere to be found on a newly installed Void Linux (using void-live-x86_64-20230628-base.iso).

Which of these three pages should I believe?

@0x5c
Copy link

0x5c commented Aug 28, 2023

The documentation up on smarden.org is very outdated and references multiple things that are no longer true. It is in dire need of a refresh or even rewrite from scratch. The same is true of the documentation source files in this repo; they have not been touched since Void Linux forked runit.
The only updated form of documentation is the manual pages.

In general, runit has no concept of service dependencies, so any condition that must be met before a service can start must be manually ensured in the service's run script. For simply depending on a service, this would be like sv start <dependency> || exit 1 like the first cited paragraph indicates.

For logging, things get more complex to explain as behaviour will depend on many factors.
First, if the service has no /log subservice*, output will be put in runsvdir's commandline (visible in ps, htop, etc). If the logger subservice exists, output will be sent to it.
Assuming Void Linux's setup, this subservice will start an instance of vlogger, which by-default will internally write anything it receives to syslog. A separate service collects syslog contents and writes it to disk.
There should be no need to manually check for a system logging service when using the /log subservice since runsv will always ensure it runs if it exists.

*It's worth noting that runit does not support any other subservice than the log one.

If you want to run service daemons that do not support service supervision as described above, please refer to this page about service dependencies I wrote some time ago.

I am not sure what "do not support service supervision" means. The service I depend on is also started through runit.

This is unrelated; the way runit functions is that it starts a program and keeps track of it as a child process. This is called service supervision. However, the "classic" way to do services involves letting them fork in the background and keeping note of their PID. The link talks (amongst other things) about adapting those forking services to runit.

The svwaitup is nowhere to be found on a newly installed Void Linux (using void-live-x86_64-20230628-base.iso).

This utility and many more ceased to be built by default by runit's build system since runit 1.4.0, from March of 2006. sv start is the new and correct way to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants