1 |
stephdl |
1.1 |
After some messing about, I've finished my dependency system for runit, |
2 |
|
|
and am now using it to start up and shut down my machine. =) |
3 |
|
|
|
4 |
|
|
I've hacked about on svwaitup and svwaitdown a little; the diff is |
5 |
|
|
enclosed and is required to make the dependencies work. Summary of |
6 |
|
|
changes: |
7 |
|
|
* svwaitup has an option to retry (with a variable delay) if the |
8 |
|
|
supervisor is not running or the service is not requested to be up. |
9 |
|
|
This was needed as the dependencies are brought up in background |
10 |
|
|
processes for parallelism, so the parent has to wait. |
11 |
|
|
* svwaitdown has an option not to send the down command to services |
12 |
|
|
(still defaults to doing so). This is needed for the inverse situation |
13 |
|
|
of the above. =) |
14 |
|
|
You need the previous patch I posted as well which creates the tools |
15 |
|
|
svisup and svisdown. |
16 |
|
|
|
17 |
|
|
The actual dependency management is done by having links in |
18 |
|
|
servicedir/updeps that point to services which must be up first. The |
19 |
|
|
reverse dependencies can be automatically generated by the enclosed |
20 |
|
|
script svdepcalc, though at the moment it's really stupid and doesn't do |
21 |
|
|
any kind of checking for cycles..etc. |
22 |
|
|
|
23 |
|
|
Once the dependency links are there, svup and svdown will bring services |
24 |
|
|
up and down in a way which obeys all dependency rules. The way I use it: |
25 |
|
|
* All services are in a single directory; no pseudo-runlevels or |
26 |
|
|
anything |
27 |
|
|
* All services have a 'down' file to stop them starting. |
28 |
|
|
* The /etc/runit/1 script runs svup in the background on a dummy service |
29 |
|
|
which depends on everything I want to run (apache..etc). |
30 |
|
|
* runsvdir starts and brings up the supervisors, and as it does so, svup |
31 |
|
|
brings services up. |
32 |
|
|
|
33 |
|
|
Once the machine is up you can use svup and svdown freely to start and |
34 |
|
|
stop services in a way which follows the dependencies. Then, to shut |
35 |
|
|
down: |
36 |
|
|
|
37 |
|
|
* /etc/runit/3 runs 'for SRV in /service/*; do svdown $SRV; done' which |
38 |
|
|
brings services down in line with dependencies. At least, if they |
39 |
|
|
terminate properly. There is a timeout for services that don't. (they |
40 |
|
|
are not killed at this stage) |
41 |
|
|
* /etc/runit/3 runs svwaitdown -kx with a short timeout to clean up any |
42 |
|
|
services which did not get terminated cleanly by the above |
43 |
|
|
* Halt. |
44 |
|
|
|
45 |
|
|
I make few promises about the actual correct functioning of these |
46 |
|
|
scripts and strongly recommend that you have a good read of them (in |
47 |
|
|
fact, it'd be nice if you did that anyway to give me some feedback). |
48 |
|
|
They work for me on exactly one machine, and have been tested a bit on |
49 |
|
|
some fake services as well, but that's not a *lot* of testing.. =) |
50 |
|
|
|
51 |
|
|
Thanks in advance for any comments, and I hope that at least someone |
52 |
|
|
finds this useful =) |
53 |
|
|
|
54 |
|
|
Torne |