df2a4ded98
Added source interface support for NTP. Also made NTP start on Mgmt-VRF by default when configured. **- How I did it** 1) Updated hostcfg to listen to global config NTP and NTP_SERVER tables and restart ntp when ever the configuration changes. NTP table includes source interface configuration. 2) The ntp script updated to by default start on Mgmt-VFT when configured. Signed-off-by: Prabhu Sreenivasan <prabhu.sreenivasan@broadcom>
49 lines
2.1 KiB
Bash
49 lines
2.1 KiB
Bash
#!/bin/sh
|
|
|
|
# This file was originally created automatically as part of default NTP application installation from debian package.
|
|
# This is now manually modified for supporting NTP in management VRF.
|
|
# When management VRF is enabled, the NTP application should be started using "ip vrf exec mgmt".
|
|
# Check has been added to verify the management VRF enabled status and use "ip vrf exec mgmt" when it is enabled.
|
|
# This file will be copied to /usr/lib/ntp/ntp-systemd-wrapper file that gets created during build process.
|
|
|
|
DAEMON=/usr/sbin/ntpd
|
|
PIDFILE=/var/run/ntpd.pid
|
|
|
|
if [ -r /etc/default/ntp ]; then
|
|
. /etc/default/ntp
|
|
fi
|
|
|
|
if [ -e /run/ntp.conf.dhcp ]; then
|
|
NTPD_OPTS="$NTPD_OPTS -c /run/ntp.conf.dhcp"
|
|
fi
|
|
|
|
LOCKFILE=/run/lock/ntpdate
|
|
|
|
RUNASUSER=ntp
|
|
UGID=$(getent passwd $RUNASUSER | cut -f 3,4 -d:) || true
|
|
if test "$(uname -s)" = "Linux"; then
|
|
NTPD_OPTS="$NTPD_OPTS -u $UGID"
|
|
fi
|
|
|
|
(
|
|
flock -w 180 9
|
|
# when mgmt vrf is configured, ntp starts in mgmt vrf by default unless user configures otherwise
|
|
vrfEnabled=$(/usr/local/bin/sonic-cfggen -d -v 'MGMT_VRF_CONFIG["vrf_global"]["mgmtVrfEnabled"]' 2> /dev/null)
|
|
vrfConfigured=$(/usr/local/bin/sonic-cfggen -d -v 'NTP["global"]["vrf"]' 2> /dev/null)
|
|
if [ "$vrfEnabled" = "true" ]
|
|
then
|
|
if [ "$vrfConfigured" = "default" ]
|
|
then
|
|
log_daemon_msg "Starting NTP server in default-vrf for default set as NTP vrf" "ntpd"
|
|
start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -- -p $PIDFILE $NTPD_OPTS
|
|
else
|
|
log_daemon_msg "Starting NTP server in mgmt-vrf" "ntpd"
|
|
ip vrf exec mgmt start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -- -p $PIDFILE $NTPD_OPTS
|
|
fi
|
|
else
|
|
log_daemon_msg "Starting NTP server in default-vrf" "ntpd"
|
|
start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -- -p $PIDFILE $NTPD_OPTS
|
|
fi
|
|
) 9>$LOCKFILE
|
|
|