Network dependent services

From Gentoo Wiki
Jump to:navigation Jump to:search

Services like netmount or fetchmail which depend on an available network connection could be started/stopped with the following setup:[1]


Precondition is that network management is done with dhcpcd.


Get the patch for dhcpcd:[2]

root #mkdir -p /etc/portage/patches/net-misc/dhcpcd-6.9.0
root #wget -P /etc/portage/patches/net-misc/dhcpcd-6.9.0

Get the patch for openrc:[3]

root #mkdir -p /etc/portage/patches/sys-apps/openrc-0.13.11
root #wget -P /etc/portage/patches/sys-apps/openrc-0.13.11

Re-emerge both dhcpcd and openrc:

root #emerge -1avt =net-misc/dhcpcd-6.6.7 =sys-apps/openrc-0.13.11

Add one line start_inactive=true to the init script:[4]

root #patch /etc/init.d/dhcpcd < attachment.cgi?id=384410

Restart dhcpcd:

root #/etc/init.d/dhcpcd restart

Later versions than the presently stable of net-misc/dhcpcd and sys-apps/openrc have not been tested with these patches. It does not work for sys-apps/openrc-0.16.4.


Services having "need net" in their init.d scripts like fetchmail would then start after dhcpcd is started.

FILE /etc/init.d/fetchmail


depend() {
        need net
        use mta
root #eselect rc start fetchmail
Starting init script
dhcpcd          * Starting DHCP Client Daemon ...
fetchmail       * WARNING: fetchmail is scheduled to start when dhcpcd has started            [ ok ]

They will be stopped when dhcpcd turns inactive and will be restarted when dhcpcd is back.

user $rc-config show default
  dhcpcd                    [inactive]
  fetchmail                 [stopped]

This should be sufficient for most end user computers. For more complex requirements in dependency behaviour see OpenRC#Dependency_behaviour.