README 3.3 KB

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