diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 6ba11ce65082..3fa4a33703a1 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -244,8 +244,7 @@ function postStartAction() fi if [[ "$BOOT_TYPE" == "fast" ]]; then - # set the key to expire in 3 minutes - $SONIC_DB_CLI STATE_DB SET "FAST_REBOOT|system" "1" "EX" "180" + $SONIC_DB_CLI STATE_DB SET "FAST_REBOOT|system" "enable" fi $SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" diff --git a/files/image_config/ntp/ntp-config.sh b/files/image_config/ntp/ntp-config.sh index 9b982d8707b6..a4ec60c9ee66 100755 --- a/files/image_config/ntp/ntp-config.sh +++ b/files/image_config/ntp/ntp-config.sh @@ -8,11 +8,11 @@ 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"` + 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 + elif [[ x"${SYSTEM_FAST_START}" == x"enable" ]]; then reboot_type='fast' fi } diff --git a/files/image_config/warmboot-finalizer/finalize-warmboot.sh b/files/image_config/warmboot-finalizer/finalize-warmboot.sh index 412559289026..2e219f83b120 100755 --- a/files/image_config/warmboot-finalizer/finalize-warmboot.sh +++ b/files/image_config/warmboot-finalizer/finalize-warmboot.sh @@ -52,6 +52,16 @@ function check_warm_boot() WARM_BOOT=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` } +function check_fast_reboot() +{ + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then + FAST_REBOOT='true' + else + FAST_REBOOT='false' + fi +} + function wait_for_database_service() { @@ -97,6 +107,12 @@ function finalize_warm_boot() sudo config warm_restart disable } +function finalize_fast_reboot() +{ + debug "Finalizing fast-reboot..." + sonic-db-cli STATE_DB SET "FAST_REBOOT|system" "disable" &>/dev/null +} + function stop_control_plane_assistant() { if [[ -x ${ASSISTANT_SCRIPT} ]]; then @@ -118,6 +134,7 @@ function restore_counters_folder() wait_for_database_service +check_fast_reboot check_warm_boot if [[ x"${WARM_BOOT}" != x"true" ]]; then @@ -152,4 +169,7 @@ if [[ -n "${list}" ]]; then debug "Some components didn't finish reconcile: ${list} ..." fi +if [ ${FAST_REBOOT} == "true" ]; then + finalize_fast_reboot +fi finalize_warm_boot diff --git a/files/scripts/bgp.sh b/files/scripts/bgp.sh index b7a383ebbdd7..ff5ca7e7be06 100755 --- a/files/scripts/bgp.sh +++ b/files/scripts/bgp.sh @@ -30,7 +30,8 @@ function validate_restore_count() function check_fast_boot () { - if [[ $($SONIC_DB_CLI STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then FAST_BOOT="true" else FAST_BOOT="false" diff --git a/files/scripts/service_mgmt.sh b/files/scripts/service_mgmt.sh index c1916aefa088..84be757ac16d 100755 --- a/files/scripts/service_mgmt.sh +++ b/files/scripts/service_mgmt.sh @@ -19,7 +19,8 @@ function check_warm_boot() function check_fast_boot () { - if [[ $($SONIC_DB_CLI STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then FAST_BOOT="true" else FAST_BOOT="false" diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index e875f50a11db..27b0423aade4 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -60,7 +60,8 @@ function check_warm_boot() function check_fast_boot() { - if [[ $($SONIC_DB_CLI STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then FAST_BOOT="true" else FAST_BOOT="false" @@ -285,7 +286,7 @@ stop() { # be restarted. if [[ x"$FAST_BOOT" != x"true" ]]; then debug "Clearing FAST_REBOOT flag..." - clean_up_tables STATE_DB "'FAST_REBOOT*'" + sonic-db-cli STATE_DB SET "FAST_REBOOT|system" "disable" fi # Unlock has to happen before reaching out to peer service unlock_service_state_change diff --git a/files/scripts/syncd_common.sh b/files/scripts/syncd_common.sh index 3d03c8b9e4e5..7f0d825b636f 100755 --- a/files/scripts/syncd_common.sh +++ b/files/scripts/syncd_common.sh @@ -50,7 +50,8 @@ function check_warm_boot() function check_fast_boot() { - if [[ $($SONIC_DB_CLI STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then FAST_BOOT="true" else FAST_BOOT="false" @@ -82,7 +83,8 @@ function getBootType() ;; *SONIC_BOOT_TYPE=fast*|*fast-reboot*) # check that the key exists - if [[ $($SONIC_DB_CLI STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then TYPE='fast' else TYPE='cold' diff --git a/files/scripts/teamd.sh b/files/scripts/teamd.sh index 4de3f25c4dbd..b58b38230d97 100755 --- a/files/scripts/teamd.sh +++ b/files/scripts/teamd.sh @@ -32,7 +32,8 @@ function validate_restore_count() function check_fast_boot () { - if [[ $($SONIC_DB_CLI STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then FAST_BOOT="true" else FAST_BOOT="false" diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index 5fc7f13c3082..4632f42a0fb4 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -699,14 +699,15 @@ def is_warm_restart_enabled(container_name): # Check if System fast reboot is enabled. def is_fast_reboot_enabled(): - fb_system_state = 0 - cmd = ['sonic-db-cli', 'STATE_DB', 'get', "FAST_REBOOT|system"] - proc = subprocess.Popen(cmd, universal_newlines=True, stdout=subprocess.PIPE) - (stdout, stderr) = proc.communicate() + state_db = SonicV2Connector(host='127.0.0.1') + state_db.connect(state_db.STATE_DB, False) - if proc.returncode != 0: - log.log_error("Error running command '{}'".format(cmd)) - elif stdout: - fb_system_state = stdout.rstrip('\n') + TABLE_NAME_SEPARATOR = '|' + prefix = 'FAST_REBOOT' + TABLE_NAME_SEPARATOR - return fb_system_state + _hash = '{}{}'.format(prefix, 'system') + fb_system_state = state_db.get(state_db.STATE_DB, _hash, "enable") + fb_enable_state = True if fb_system_state == "true" else False + + state_db.close(state_db.STATE_DB) + return fb_enable_state