Gentoo Archives: gentoo-user

From: covici@××××××××××.com
To: gentoo-user@l.g.o
Subject: [gentoo-user] systemd how can I get a service to start after network is up
Date: Tue, 20 May 2014 10:29:16
Message-Id: 10251.1400581747@ccs.covici.com
Hi.  I have a simple, static, ethernet network.  However when booting
using systemd, a number of services which should start only after the
network is up, insist on starting in parallell and so fail for various
reasons.  Here is my network service and my ntpdate service file, and I
would like to know how to get the ntpdate service file to wait till the
network is up before trying to start.

Thanks in advance for any suggestions.

Network service file:
[Unit]
Description=Network Connectivity for %i
Documentation= nam ip
Before=network.target
wants=network.target
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device
[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/conf.d/network@%i
ExecStart=/bin/ip link set dev %i up
ExecStart=/bin/ip addr add ${address}/${netmask} broadcast ${broadcast} dev %i
ExecStart=-/bin/bash -c "test -n ${gateway} && /bin/ip route add default via ${gateway}"
ExecStart=-/bin/bash -c "test -f /etc/conf.d/postup@%i.sh&&/bin/bash  -c /etc/conf.d/postup@%i.sh"
ExecStop=/bin/ip addr flush dev %i
ExecStop=/bin/ip link set dev %i down
[Install]
WantedBy=multi-user.target

and here is my ntpdate service file:

[Unit]
Description=Set time via NTP using ntpdate
After=network.target nss-lookup.target
Before=time-sync.target
Wants=time-sync.target

[Service]
Type=oneshot
EnvironmentFile=/etc/conf.d/ntp-client
ExecStart=/usr/sbin/ntpdate $NTPCLIENT_OPTS
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

-- 
Your life is like a penny.  You're going to lose it.  The question is:
How do
you spend it?

         John Covici
         covici@××××××××××.com

Replies

Subject Author
Re: [gentoo-user] systemd how can I get a service to start after network is up Michael Hampicke <mh@××××.biz>