:: Re: [DNG] Runit service depend anot…
Page principale
Supprimer ce message
Répondre à ce message
Auteur: Steve Litt
Date:  
À: dng
Sujet: Re: [DNG] Runit service depend another script not daemon
On Tue, 2 Jul 2019 20:28:51 +0200
viverna <viverna@???> wrote:

> I'm not an expert of Runit and I want ask you how make a service
> depend another script not daemon.
> For example if I have a service that needs another service:
>
> cat /etc/service/my_service/run
> #!/bin/sh
> sv start service_required || exit 1
> exec my_service
>
> But if "service_required" is not a daemon?
>
> For example run ssh daemon is required bring a network interface up.
> Bring a network interface up is accomplished from a simple/very few
> command/s such as ifup and friend.
> ifup execute and terminate, and execute again forever.


Hi viverna,

I'm not quite sure what you're trying to accomplish, but if
service_required is not a daemon then you wouldn't use sv to start it.
If service_required is just a shellscript to set things up for
my_service, then you'd just do the following:

#!/bin/sh
service_required || exit 1
exec my_service

And under the preceding conditions, service_required should be renamed
setup_shellscript.

If service_required is a prerequisite for running several daemons, it
should be called from either /etc/runit/1 or /etc/runit/2. Once again,
it should be renamed.

If service_required should still be running when my_service starts up,
then service_required should have its own /etc/sv/service_required and
the symlink in /var/service, and a test should be devised to determine
whether service_required is functional. Let's say that test is
contained in a shellscript called service_required_is_functional, that
returns 0 when the service proves it's functioning, and some other
number otherwise (I use 1). Then the run script for my_service looks
like this:

#!/bin/sh
if service_required_is_functional; then
exec my_service
fi
sleep 1

There are ways to actually run service_required if it's not currently
running, but I prefer the preceding, because it's very simple. The
runsvdir does another round robin, by which time hopefully runsvdir has
done a runsv on service_required, and all is good. If service_required
keeps on failing, well, that's another story: It must be troubleshot.

The precedingly described process sounds very undeterministic and
subject to race conditions and it sounds like a field of tightly packed
mousetraps all supporting a tennis ball ready to fly and set off other
mousetraps. I know it sounds like that. All I can tell you is that in
the 4 years I've used runit, I've never detected a problem caused by
non-determinism or a race condition.

SteveT

Steve Litt
June 2019 featured book: Thriving in Tough Times
http://www.troubleshooters.com/thrive