From 6bdb8a7dedf617ce0d267f4caa13a9fdac950b63 Mon Sep 17 00:00:00 2001 From: Ying Xie Date: Tue, 12 May 2020 04:32:12 +0000 Subject: [PATCH 1/4] [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 --- files/image_config/ntp/ntp-config.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/files/image_config/ntp/ntp-config.sh b/files/image_config/ntp/ntp-config.sh index 601b7bd421f0..da42c3999c55 100755 --- a/files/image_config/ntp/ntp-config.sh +++ b/files/image_config/ntp/ntp-config.sh @@ -1,5 +1,28 @@ #!/bin/bash +reboot_type='cold' + +function get_databaes_reboot_type() +{ + SYSTEM_WARM_START=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|system" enable` + SYSTEM_FAST_START=`/usr/bin/redis-cli -n 6 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 +} + sonic-cfggen -d -t /usr/share/sonic/templates/ntp.conf.j2 >/etc/ntp.conf +get_databaes_reboot_type +if [[ x"${reboot_type}" == x"cold" ]]; then + echo "Enabling NTP long jump for reboot type ${reboot_type} ..." + sed -i "s/NTPD_OPTS='-x'/NTPD_OPTS='-g'/" /etc/default/ntp +else + echo "Disabling NTP long jump for reboot type ${reboot_type} ..." + sed -i "s/NTPD_OPTS='-g'/NTPD_OPTS='-x'/" /etc/default/ntp +fi + systemctl restart ntp From 2c95fa71a24018fc1a57c83b06a8291411c0340b Mon Sep 17 00:00:00 2001 From: Ying Xie Date: Tue, 12 May 2020 14:31:09 +0000 Subject: [PATCH 2/4] fix typo --- files/image_config/ntp/ntp-config.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/image_config/ntp/ntp-config.sh b/files/image_config/ntp/ntp-config.sh index da42c3999c55..56a5d6121934 100755 --- a/files/image_config/ntp/ntp-config.sh +++ b/files/image_config/ntp/ntp-config.sh @@ -2,7 +2,7 @@ reboot_type='cold' -function get_databaes_reboot_type() +function get_database_reboot_type() { SYSTEM_WARM_START=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|system" enable` SYSTEM_FAST_START=`/usr/bin/redis-cli -n 6 get "FAST_REBOOT|system"` @@ -16,7 +16,7 @@ function get_databaes_reboot_type() sonic-cfggen -d -t /usr/share/sonic/templates/ntp.conf.j2 >/etc/ntp.conf -get_databaes_reboot_type +get_database_reboot_type if [[ x"${reboot_type}" == x"cold" ]]; then echo "Enabling NTP long jump for reboot type ${reboot_type} ..." sed -i "s/NTPD_OPTS='-x'/NTPD_OPTS='-g'/" /etc/default/ntp From e2a192061ce9f5a165eb19d67312289750909ff7 Mon Sep 17 00:00:00 2001 From: Ying Xie Date: Tue, 12 May 2020 16:00:41 +0000 Subject: [PATCH 3/4] further refactoring --- files/image_config/ntp/ntp-config.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/files/image_config/ntp/ntp-config.sh b/files/image_config/ntp/ntp-config.sh index 56a5d6121934..d8b8369c91c2 100755 --- a/files/image_config/ntp/ntp-config.sh +++ b/files/image_config/ntp/ntp-config.sh @@ -1,5 +1,8 @@ #!/bin/bash +ntp_default_file='/etc/default/ntp' +ntp_temp_file='/tmp/ntp.orig' + reboot_type='cold' function get_database_reboot_type() @@ -14,15 +17,21 @@ function get_database_reboot_type() 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} ..." - sed -i "s/NTPD_OPTS='-x'/NTPD_OPTS='-g'/" /etc/default/ntp + modify_ntp_default "s/NTPD_OPTS='-x'/NTPD_OPTS='-g'/" else echo "Disabling NTP long jump for reboot type ${reboot_type} ..." - sed -i "s/NTPD_OPTS='-g'/NTPD_OPTS='-x'/" /etc/default/ntp + modify_ntp_default "s/NTPD_OPTS='-g'/NTPD_OPTS='-x'/" fi systemctl restart ntp From 8157acf2ed5ebc26f0f911b56d3751619d84b5a4 Mon Sep 17 00:00:00 2001 From: Ying Xie Date: Tue, 12 May 2020 19:24:31 +0000 Subject: [PATCH 4/4] use sonic-db-cli instead --- files/image_config/ntp/ntp-config.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/image_config/ntp/ntp-config.sh b/files/image_config/ntp/ntp-config.sh index d8b8369c91c2..7ab84174dcaa 100755 --- a/files/image_config/ntp/ntp-config.sh +++ b/files/image_config/ntp/ntp-config.sh @@ -7,8 +7,8 @@ reboot_type='cold' function get_database_reboot_type() { - SYSTEM_WARM_START=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SYSTEM_FAST_START=`/usr/bin/redis-cli -n 6 get "FAST_REBOOT|system"` + 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'