Skip to content

Commit 012c832

Browse files
bsun-sudoBing Sun
authored andcommitted
[ntp] add ntp support in buster with mgmt vrf (sonic-net#55)
- create a file in files/image_config/ntp/ntp-systemd-wrapper to add mgmt vrf related start cmd for ntp service. So that the default /usr/lib/ntp/ntp-systemd-wrapper can be overriden during build time. - modify build_debian.sh to cp files/image_config/ntp/ntp-systemd-wrapper to /usr/lib/ntp/ntp-systemd-wrapper during build time. Co-authored-by: Bing Sun <[email protected]>
1 parent 2a237c5 commit 012c832

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

build_debian.sh

+4
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@ if [ -f files/image_config/ntp/ntp ]; then
451451
sudo cp ./files/image_config/ntp/ntp $FILESYSTEM_ROOT/etc/init.d/
452452
fi
453453

454+
if [ -f files/image_config/ntp/ntp-systemd-wrapper ]; then
455+
sudo cp ./files/image_config/ntp/ntp-systemd-wrapper $FILESYSTEM_ROOT/usr/lib/ntp/
456+
fi
457+
454458
## Version file
455459
sudo mkdir -p $FILESYSTEM_ROOT/etc/sonic
456460
sudo tee $FILESYSTEM_ROOT/etc/sonic/sonic_version.yml > /dev/null <<EOF
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
3+
# This file was originally created automatically as part of default NTP application installation from debian package.
4+
# This is now manually modified for supporting NTP in management VRF.
5+
# When management VRF is enabled, the NTP application should be started using "ip vrf exec mgmt".
6+
# Check has been added to verify the management VRF enabled status and use "ip vrf exec mgmt" when it is enabled.
7+
# This file will be copied to /usr/lib/ntp/ntp-systemd-wrapper file that gets created during build process.
8+
9+
DAEMON=/usr/sbin/ntpd
10+
PIDFILE=/var/run/ntpd.pid
11+
12+
if [ -r /etc/default/ntp ]; then
13+
. /etc/default/ntp
14+
fi
15+
16+
if [ -e /run/ntp.conf.dhcp ]; then
17+
NTPD_OPTS="$NTPD_OPTS -c /run/ntp.conf.dhcp"
18+
fi
19+
20+
LOCKFILE=/run/lock/ntpdate
21+
22+
RUNASUSER=ntp
23+
UGID=$(getent passwd $RUNASUSER | cut -f 3,4 -d:) || true
24+
if test "$(uname -s)" = "Linux"; then
25+
NTPD_OPTS="$NTPD_OPTS -u $UGID"
26+
fi
27+
28+
(
29+
flock -w 180 9
30+
vrfEnabled=$(/usr/local/bin/sonic-cfggen -d -v 'MGMT_VRF_CONFIG["vrf_global"]["mgmtVrfEnabled"]' 2> /dev/null)
31+
if [ "$vrfEnabled" = "true" ]
32+
then
33+
ip vrf exec mgmt start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -- -p $PIDFILE $NTPD_OPTS
34+
else
35+
start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -- -p $PIDFILE $NTPD_OPTS
36+
fi
37+
) 9>$LOCKFILE
38+

0 commit comments

Comments
 (0)