aboutsummaryrefslogtreecommitdiffstats
path: root/30-timesyncd
blob: a56652f8dd3c3ec08e291333f97872606d752f71 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh

INTERFACE="${1}"
STATUS="${2}"

case "${STATUS}" in
	up|dhcp4-change)
		if [ -n "${DHCP4_NTP_SERVERS}" ]; then
			mkdir -p /run/systemd/timesyncd.conf.d/

			echo -e "# generated for interface ${INTERFACE} by networkmanager-dispatcher-timesyncd\n" \
				> /run/systemd/timesyncd.conf.d/${INTERFACE}.conf
			echo "[Time]" >> /run/systemd/timesyncd.conf.d/${INTERFACE}.conf
			echo "NTP = ${DHCP4_NTP_SERVERS}" >> /run/systemd/timesyncd.conf.d/${INTERFACE}.conf

			# systemd-timesyncd does not notice changed configuration. So if it is
			# already running 'timedatectl set-ntp true' does not work.
			# Restart the service instead.
			systemctl restart systemd-timesyncd.service
		fi
		;;
	down)
		rm -f /run/systemd/timesyncd.conf.d/${INTERFACE}.conf
		;;
esac