Skip to content

Commit cdfb1ce

Browse files
authored
[ntp] enable/disable NTP long jump according to reboot type (#4577)
* [ntp] enable/disable NTP long jump according to reboot type - Enable NTP long jump after cold reboot. - Disable NTP long jump after warrm/fast reboot. Signed-off-by: Ying Xie <[email protected]> * fix typo * further refactoring * use sonic-db-cli instead
1 parent 9c7105b commit cdfb1ce

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

files/image_config/ntp/ntp-config.sh

+32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
#!/bin/bash
22

3+
ntp_default_file='/etc/default/ntp'
4+
ntp_temp_file='/tmp/ntp.orig'
5+
6+
reboot_type='cold'
7+
8+
function get_database_reboot_type()
9+
{
10+
SYSTEM_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable`
11+
SYSTEM_FAST_START=`sonic-db-cli STATE_DB get "FAST_REBOOT|system"`
12+
13+
if [[ x"${SYSTEM_WARM_START}" == x"true" ]]; then
14+
reboot_type='warm'
15+
elif [[ x"${SYSTEM_FAST_START}" == x"1" ]]; then
16+
reboot_type='fast'
17+
fi
18+
}
19+
20+
function modify_ntp_default
21+
{
22+
cp ${ntp_default_file} ${ntp_temp_file}
23+
sed -e "$1" ${ntp_temp_file} >${ntp_default_file}
24+
}
25+
326
sonic-cfggen -d -t /usr/share/sonic/templates/ntp.conf.j2 >/etc/ntp.conf
427

28+
get_database_reboot_type
29+
if [[ x"${reboot_type}" == x"cold" ]]; then
30+
echo "Enabling NTP long jump for reboot type ${reboot_type} ..."
31+
modify_ntp_default "s/NTPD_OPTS='-x'/NTPD_OPTS='-g'/"
32+
else
33+
echo "Disabling NTP long jump for reboot type ${reboot_type} ..."
34+
modify_ntp_default "s/NTPD_OPTS='-g'/NTPD_OPTS='-x'/"
35+
fi
36+
537
systemctl restart ntp

0 commit comments

Comments
 (0)