blob: 06817c8bcd16ff6c564419c22fb3f3efc528b58a [file] [log] [blame]
Denys Vlasenko75bb3322010-12-06 15:13:58 +01001In many cases, network configuration makes it necessary to run several daemons:
2dhcp, zeroconf, ppp, openvpn and such. They need to be controlled,
3and in many cases you also want to babysit them. runsvdir is a good tool for this.
4examples/var_service directory provides a few examples. It is meant to be used
5this way: copy it somewhere (say, /var/service) and run something like
6
7env - PATH=... <other vars=...> runsvdir /var/service &
8
9from one of system startup scripts. (Google "man runsvdir" and "man runsv"
10for more info about these tools).
11
12Some existing examples:
13
14var_service/dhcp_if -
15controls a udhcpc instance which provides dhpc-assigned IP
16address on interface named "if". Copy/rename this directory as needed to run
17udhcpc on other interfaces (var_service/dhcp_if/run script uses _foo suffix
Denys Vlasenko30997442010-12-06 15:44:13 +010018of the parent directory as interface name). When IP address is obtained or lost,
Denys Vlasenko75bb3322010-12-06 15:13:58 +010019var_service/dhcp_if/dhcp_handler is run. It saves new config data to
20/var/run/service/fw/dhcp_if.ipconf and (re)starts /var/service/fw service.
Denys Vlasenkobc3cdf82010-12-06 15:42:44 +010021This example can be used as a template for other dynamic network link services
22(ppp/vpn/zcip).
Denys Vlasenko75bb3322010-12-06 15:13:58 +010023
24var_service/ifplugd_if -
25watches link status of interface if. Downs and ups /var/service/dhcp_if
26service accordingly. In effect, it allows you to unplug/plug-to-different-network
27and have your IP properly re-negotiated at once.
28
29var_service/dhcp_if_pinger -
30Uses var_service/dhcp_if's data (/var/service/dhcp_if/dhcp_if.out file)
31to determine router IP. Pings it. If ping fails, restarts /var/service/dhcp_if
32service. Basically, an example of watchdog service for networks
33which are not reliable and need babysitting.
34
35var_service/fw -
Denys Vlasenko1f3709e2010-12-08 06:08:47 +010036A *one-shot* service which reconfigures network based on current known state
Denys Vlasenko75bb3322010-12-06 15:13:58 +010037of ALL interfaces. Uses conf/*.ipconf (static config) and /var/run/service/fw/*.ipconf
38(dynamic config from dhcp/ppp/vpn/etc) to determine what to do.
39One-shot-ness of this service means that it shuts itself off after single run.
Denys Vlasenkobc3cdf82010-12-06 15:42:44 +010040IOW: it is not a constantly running daemon sort of thing.
41It starts, it configures the network, it shuts down, all done
42(unlike infamous NetworkManagers which sit in RAM forever, doing hell knows what).
Denys Vlasenko75bb3322010-12-06 15:13:58 +010043
44However, any dhcp/ppp/vpn or similar service can restart it anytime
45when it senses the change in network configuration.
46This even works while fw service runs: if dhcp signals fw to (re)start
47while fw runs, fw will not stop after its execution, but will re-execute once,
48picking up dhcp's new configuration.
49This is achieved very simply by having
50# Make ourself one-shot
51sv o .
52at the very beginning of fw/run script, not at the end.
53Therefore, any "sv u /var/run/service/fw" command by any other
54script "undoes" o(ne-shot) command if fw still runs, thus
55runsv will rerun it; or start it in a normal way if fw is not running.
56
57System administrators are expected to edit fw/run script, since
58network configuration needs are likely to be very complex and different
59for non-trivial installations.