4007d9ba9c
This PR is to handle the issue 3527. When device boots up, NTP throws a traceback as explained in the issue 3527. - Traceback will be seen when MGMT_VRF_CONFIG does not exist in the database. Traceback is coming from the script “/etc/init.d/ntp”. - Traceback does not affect the NTP functionality with/without management VRF. When MGMT_VRF_CONFIG does not exist or when MGMT_VRF_CONFIG’s mgmtVrfEnabled is configured to “false”, “NTP” will be started in the “default VRF” context, which is working fine even with this traceback. - This traceback error will be hidden by redirecting the error to /dev/null without affecting functionality.
92 lines
2.4 KiB
Bash
Executable File
92 lines
2.4 KiB
Bash
Executable File
#!/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 "cgexec -g l3mdev:mgmt".
|
|
# Check has been added to verify the management VRF enabled status and use cgexec when it is enabled.
|
|
# This file will be copied on top of the etc/init.d/ntp file that gets created during build process.
|
|
|
|
### BEGIN INIT INFO
|
|
# Provides: ntp
|
|
# Required-Start: $network $remote_fs $syslog
|
|
# Required-Stop: $network $remote_fs $syslog
|
|
# Default-Start: 2 3 4 5
|
|
# Default-Stop:
|
|
# Short-Description: Start NTP daemon
|
|
### END INIT INFO
|
|
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
|
|
|
. /lib/lsb/init-functions
|
|
|
|
DAEMON=/usr/sbin/ntpd
|
|
PIDFILE=/var/run/ntpd.pid
|
|
|
|
test -x $DAEMON || exit 5
|
|
|
|
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
|
|
|
|
case $1 in
|
|
start)
|
|
log_daemon_msg "Starting NTP server" "ntpd"
|
|
if [ -z "$UGID" ]; then
|
|
log_failure_msg "user \"$RUNASUSER\" does not exist"
|
|
exit 1
|
|
fi
|
|
(
|
|
flock -w 180 9
|
|
vrfEnabled=$(/usr/local/bin/sonic-cfggen -d -v 'MGMT_VRF_CONFIG["vrf_global"]["mgmtVrfEnabled"]' 2> /dev/null)
|
|
if [ "$vrfEnabled" = "true" ]
|
|
then
|
|
log_daemon_msg "Starting NTP server in mgmt-vrf" "ntpd"
|
|
cgexec -g l3mdev:mgmt start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -- -p $PIDFILE $NTPD_OPTS
|
|
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
|
|
log_end_msg $?
|
|
;;
|
|
stop)
|
|
log_daemon_msg "Stopping NTP server" "ntpd"
|
|
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --retry=TERM/30/KILL/5 --exec $DAEMON
|
|
log_end_msg $?
|
|
rm -f $PIDFILE
|
|
;;
|
|
restart|force-reload)
|
|
$0 stop && sleep 2 && $0 start
|
|
;;
|
|
try-restart)
|
|
if $0 status >/dev/null; then
|
|
$0 restart
|
|
else
|
|
exit 0
|
|
fi
|
|
;;
|
|
reload)
|
|
exit 3
|
|
;;
|
|
status)
|
|
status_of_proc $DAEMON "NTP server"
|
|
;;
|
|
*)
|
|
echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
|
|
exit 2
|
|
;;
|
|
esac
|