Skip to content

Commit

Permalink
[ntp] enable/disable NTP long jump according to reboot type (#4577)
Browse files Browse the repository at this point in the history
* [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 <ying.xie@microsoft.com>

* fix typo

* further refactoring

* use sonic-db-cli instead
  • Loading branch information
yxieca authored and abdosi committed May 21, 2020
1 parent dcb780e commit 14b3f00
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions files/image_config/ntp/ntp-config.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
#!/bin/bash

ntp_default_file='/etc/default/ntp'
ntp_temp_file='/tmp/ntp.orig'

reboot_type='cold'

function get_database_reboot_type()
{
SYSTEM_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable`
SYSTEM_FAST_START=`sonic-db-cli STATE_DB get "FAST_REBOOT|system"`

if [[ x"${SYSTEM_WARM_START}" == x"true" ]]; then
reboot_type='warm'
elif [[ x"${SYSTEM_FAST_START}" == x"1" ]]; then
reboot_type='fast'
fi
}

function modify_ntp_default
{
cp ${ntp_default_file} ${ntp_temp_file}
sed -e "$1" ${ntp_temp_file} >${ntp_default_file}
}

sonic-cfggen -d -t /usr/share/sonic/templates/ntp.conf.j2 >/etc/ntp.conf

get_database_reboot_type
if [[ x"${reboot_type}" == x"cold" ]]; then
echo "Enabling NTP long jump for reboot type ${reboot_type} ..."
modify_ntp_default "s/NTPD_OPTS='-x'/NTPD_OPTS='-g'/"
else
echo "Disabling NTP long jump for reboot type ${reboot_type} ..."
modify_ntp_default "s/NTPD_OPTS='-g'/NTPD_OPTS='-x'/"
fi

systemctl restart ntp

0 comments on commit 14b3f00

Please sign in to comment.