How to automatically stop/start a service if another service is stopped/started?

scenario: I have 3 daemons. daemon-x, daemon-y and daemon-z. daemon-y and daemon-z depend on daemon-x.

2 things that I want.

1. I want daemon-y and daemon-z to only start after daemon-x.
I believe using "REQUIRE" will take care of this during boot time. Please confirm if this is true.

Assuming all 3 services are currently stopped. I want daemon-y and daemon-z to automatically start if I manually start daemon-z.

2. I want daemon-y and daemon-z to automatically stop if I stopped daemon-x.

Any ideas on how this can be done? Thank you
 
If I believe using "REQUIRE" will take care of this during boot time. Please confirm if this is true.
It doesn't. All REQUIRE and friends do is try to get the order correct. See rcorder(8):
Code:
BUGS
     The "REQUIRE" keyword is misleading: It doesn't describe which daemons
     have to be running before a script will be started.  It describes which
     scripts must be placed before it in the dependency ordering.  For
     example, if your script has a "REQUIRE" on "named", it means the script
     must be placed after the "named" script in the dependency ordering, not
     necessarily that it requires named(8) to be started or enabled.

Any ideas on how this can be done? Thank you
Probably the only reliable way to do this is to start all three daemons from the same rc(8) script. Because that's the only place that will allow you to find out if things started/stopped correctly.
 
You can get quite creative with rc(8) scripts. Besides the standard start and stop 'commands' you can add your own custom additions. You could for example create a script when called normally; service myscript start simply starts the daemons in the correct order. Then add a 'stopfront' for example; service myscript stopfront to only stop Z while keeping X and Y running. You probably already have some ideas what would be needed, and just add them as 'extra' commands.
 
No. But if all required services are enabled, rc ensures the correct ordering. This should normally be enough?
 
Has anything changed on this? I am in need to have service dependencies, especially when starting services.
This is vague. Do you mean "I have service X that depends on Y and Z where Y and Z must be started before X"? That is a simple case and as suggested, REQUIRE and rcorder should fix it.
Do you mean "X depend on Y and Z and if Y or Z stop and restart X must restart"? That is different and I'm not sure what will or should happen.
 
Sorry for the vagueness.

I need a way where service X depends on Y and Y must be started before X. I will try the REQUIRE keyword.
 
I need a way where service X depends on Y and Y must be started before X. I will try the REQUIRE keyword.
Rcorder (which means the Require and Provides comments in the rc file) will work correctly when booting the machine and when shutting it down.

But does it work when manually starting stopping services? In your example, if you say "service Y stop", will X be stopped first? And if you say "service X start" while Y is not running (probably because you stopped it manually a moment ago), will Y get started automatically, or will you get an error message that X can't start right now, or will it silently do the wrong thing?
 
Yeah, the REQUIRE keyword is not working. I have a REQUIRED X service that seems to be taking a while to actually start up before Y starts... Then Y fails because X is not ready...
 
But does it work when manually starting stopping services?
No. The only tool using these comments is rcorder.

When manually starting/stopping services, it's the admin's responsibility to take care for the correct order to do so. Sure this could be automated, but IMHO this would just add unnecessary complexity to the rc system.
 
taking a while to actually start up
Daemonized and returned immediately instead of finishing initialization before doing so, perhaps? Bundle them in a rc script as described above, but perhaps put a a simple looping/sleeping test for service X before the command to start Y.
 
Back
Top