Update system time using NTP and NetworkManager (Gentoo)
·1 min read·paskov
On my laptop, I use NetworkManager to manage the LAN and WLAN interfaces.
The dispatcher script below starts ntp-client to synchronize the system clock when eth0 or wlan0 comes up. It stops the service when either interface goes down and ignores other interfaces and events. Replace eth0 and wlan0 with your interface names if they differ.
As root, save the following script as /etc/NetworkManager/dispatcher.d/10-ntp-client:
#!/bin/bash
IF=$1
STATE=$2
if [ "$IF" = "eth0" ] || [ "$IF" = "wlan0" ]; then
if [ "$STATE" = "up" ]; then
/etc/init.d/ntp-client start
elif [ "$STATE" = "down" ]; then
/etc/init.d/ntp-client stop
fi
fiThen make it executable:
chmod +x /etc/NetworkManager/dispatcher.d/10-ntp-clientThe script requires Gentoo’s net-misc/ntp package and its /etc/init.d/ntp-client service.
Related Posts
Gentoo GNU/Linux on Acer Extensa 5620Z
2010-11-14
ASUS WL-107g
2006-04-21
Comments 1
I have corrected the script a little
But in general it will not work when configured with more interfaces; you don’t want to stop ntp-client when any of your interfaces goes down but just when all of them are down.