Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SYSTEMD] ntpdate failed to synchronise at boot
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
ade05fr
Apprentice
Apprentice


Joined: 18 Sep 2006
Posts: 281

PostPosted: Tue Dec 24, 2013 10:39 am    Post subject: [SYSTEMD] ntpdate failed to synchronise at boot Reply with quote

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
Code:

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

Code:

 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


Code:

 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
Code:
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
_________________
[LAPTOP]
DELL Inspiron 5110
i5-2450M CPU @ 2.50GHz
[LINUX-GENTOO]
Gentoo 2018-0
kernel 5.0.6
gnome 3.30
Back to top
View user's profile Send private message
Kompi
Apprentice
Apprentice


Joined: 05 Oct 2002
Posts: 252
Location: Germany

PostPosted: Mon Dec 30, 2013 11:51 am    Post subject: Reply with quote

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:


Code:
[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.
Back to top
View user's profile Send private message
thawn
n00b
n00b


Joined: 31 Aug 2004
Posts: 41

PostPosted: Mon Jan 13, 2014 9:49 pm    Post subject: solution Reply with quote

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:
Code:
systemctl enable NetworkManager.service
systemctl enable NetworkManager-wait-online.service

and you should be all set.
Back to top
View user's profile Send private message
666threesixes666
Veteran
Veteran


Joined: 31 May 2011
Posts: 1248
Location: 42.68n 85.41w

PostPosted: Mon Jan 13, 2014 11:20 pm    Post subject: Reply with quote

bleh i need the answer for openrc too for networkmanager :evil:
Back to top
View user's profile Send private message
nixphoeni
Retired Dev
Retired Dev


Joined: 23 Oct 2004
Posts: 11

PostPosted: Sun Oct 26, 2014 1:16 am    Post subject: Reply with quote

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:

Code:
[Unit]
After=network-online.target
Wants=network-online.target


This starts ntpdate after the network comes online at boot.
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6835
Location: Blighty

PostPosted: Sun Oct 26, 2014 9:38 am    Post subject: Reply with quote

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.
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum