# [SYSTEMD] ntpdate failed to synchronise at boot

## ade05fr

hie everyone

i have migrated from openRC to systemd and now i have an issue with ntpdate which i have never had with openRC.

now my time is not synchronise correctly

here is the log from journalctl

```

ade05fr@wolftop ~ $ sudo systemctl status ntpdate.service

ntpdate.service - Set time via NTP using ntpdate

   Loaded: loaded (/usr/lib64/systemd/system/ntpdate.service; enabled)

  Drop-In: /etc/systemd/system/ntpdate.service.d

           └─00gentoo.conf

   Active: failed (Result: exit-code) since mar. 2013-12-24 10:26:41 CET; 8min ago

  Process: 2033 ExecStart=/usr/sbin/ntpdate -b -u $SERVER (code=exited, status=1/FAILURE)

 Main PID: 2033 (code=exited, status=1/FAILURE)

   CGroup: /system.slice/ntpdate.service

déc. 24 10:26:41 wolftop ntpdate[2033]: Error resolving 0.gentoo.pool.ntp.org: System error (-11)

déc. 24 10:26:41 wolftop ntpdate[2033]: 24 Dec 10:26:41 ntpdate[2033]: Can't find host 0.gentoo.pool.ntp.org: System error (-11)

déc. 24 10:26:41 wolftop ntpdate[2033]: Error resolving 1.gentoo.pool.ntp.org: System error (-11)

déc. 24 10:26:41 wolftop ntpdate[2033]: 24 Dec 10:26:41 ntpdate[2033]: Can't find host 1.gentoo.pool.ntp.org: System error (-11)

déc. 24 10:26:41 wolftop ntpdate[2033]: Error resolving 2.gentoo.pool.ntp.org: System error (-11)

déc. 24 10:26:41 wolftop systemd[1]: ntpdate.service: main process exited, code=exited, status=1/FAILURE

déc. 24 10:26:41 wolftop systemd[1]: Failed to start Set time via NTP using ntpdate.

déc. 24 10:26:41 wolftop systemd[1]: Unit ntpdate.service entered failed state.

```

the file localtime from /etc is correctly set 

I have modifier the dhcpcd service and ntpdate service in the after and before clause like that

```

 cat /usr/lib/systemd/system/ntpdate.service 

[Unit]

Description=Set time via NTP using ntpdate

After=network.target nss-lookup.target dhcpcd.service

Before=time-sync.target

Wants=time-sync.target

[Service]

Type=oneshot

ExecStart=/usr/sbin/ntpdate -b -u $SERVER

RemainAfterExit=yes

[Install]

WantedBy=multi-user.target

```

```

 cat /usr/lib/systemd/system/dhcpcd.service 

[Unit]

Description=Lightweight DHCP client daemon

Wants=network.target

Before=network.target ntpdate.service

[Service]

ExecStart=/sbin/dhcpcd -q --nobackground

[Install]

WantedBy=multi-user.target

```

even though the synchronization is not ok at boot sequence

FYI if i run manually in a gnome-terminal the command 

```
sudo systemctl start ntpdate.service
```

then the time is correctly modified

I think that the problem is only related to a dependance between dhcp and the network connection.

can someone help me ?

thanks

----------

## Kompi

I think you are right, the error messages from ntpdate suggest that it cannot resolve host names via DNS, which indicates that the network is not yet up when ntpdate is started.

I think the problem is ntpdate.service is started as soon as dhcpcd is started. However, dhcpcd will need some time to acquire the IP-address, DNS nameserver IP etc.

Try modifying the [Service] section of your dhcpcd.service the following way:

```
[Service]

Type=forking

ExecStart=/sbin/dhcpcd -q --background --waitip 
```

The --waitip flag tells dhcpcd to fork not before an IP address has been acquired. The "type=forking" in combination with --background instead of --nobackground will change this to a forking daemon. This should have the effect that any service with "After=dhcpcd.service" should wait until dhcpcd forks, i.e. the IP address is assigned.

----------

## thawn

I found the solution here

basically. you need to enable the NetworkManager.service and the NetworkManager-wait-online.service, otherwise the network.target is reached before the network is actually up (read the explanation in the link above for more details) so do:

```
systemctl enable NetworkManager.service

systemctl enable NetworkManager-wait-online.service

```

and you should be all set.

----------

## 666threesixes666

bleh i need the answer for openrc too for networkmanager   :Evil or Very Mad: 

----------

## nixphoeni

I've been wondering this for a while...it doesn't seem to be enough to enable NetworkManager-wait-online.  Drop the following into /etc/systemd/system/ntpdate.service.d/10network-online.conf:

```
[Unit]

After=network-online.target

Wants=network-online.target
```

This starts ntpdate after the network comes online at boot.

----------

## UberLord

Because of the nature of systemd, you need to add a service to "wait" while the "network" is up.

Systemd, network-manager and dhcpcd have their own.

For dhcpcd, you need to install dhcpcd-ui to get the dhcpcd-online tool (and systemd service file for it) which it can use.

Pester the Gentoo devs here please https://bugs.gentoo.org/show_bug.cgi?id=522854

because they are clearly dragging their heels over this.

----------

