Network dependent services
Services like netmount or fetchmail which depend on an available network connection could be started/stopped with the following setup:[1]
Precondition
Precondition is that network management is done with dhcpcd.
Implementation
Get the patch for dhcpcd:[2]
root #
mkdir -p /etc/portage/patches/net-misc/dhcpcd-6.9.0
root #
wget https://522206.bugs.gentoo.org/attachment.cgi?id=402858 -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 https://bugs.gentoo.org/attachment.cgi?id=402856 -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.
Result
Services having "need net" in their init.d scripts like fetchmail would then start after dhcpcd is started.
#!/sbin/runscript
piddir=${pid_dir:-/var/run/fetchmail}
pid_file=${piddir}/${RC_SVCNAME}.pid
rcfile=/etc/${RC_SVCNAME}rc
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.
References
- ↑ Bug 522206 – net-misc/dhcpcd-6.4.3 fails to start/stop network dependant services like ntpd, sshd, fetchmai, Gentoo's Bugzilla Main Page, (Last modified) April 9th, 2015. Retrieved on May 7th, 2015.
- ↑ 99-openrc_dhcpcd_hook.patch, updated for epatch_user, Gentoo's Bugzilla Main Page, May 8th, 2015. Retrieved on May 10th, 2015.
- ↑ runscript-background.patch, updated for epatch_user, Gentoo's Bugzilla Main Page, May 8th, 2015. Retrieved on May 10th, 2015.
- ↑ Roy Marples. Mark the dhcpcd service as starting inactive, Gentoo's Bugzilla Main Page, September 8th, 2014. Retrieved on May 7th, 2015.