diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 01a52fb7a0d3..23d111051f62 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -235,6 +235,7 @@ function postStartAction() ($(docker exec -i database$DEV sonic-db-cli PING | grep -c PONG) -gt 0) ]]; do sleep 1; done + if [[ ("$BOOT_TYPE" == "warm" || "$BOOT_TYPE" == "fastfast" || "$BOOT_TYPE" == "fast") && -f $WARM_DIR/dump.rdb ]]; then # retain the dump file from last boot for debugging purposes mv $WARM_DIR/dump.rdb $WARM_DIR/dump.rdb.old @@ -248,28 +249,18 @@ function postStartAction() $SONIC_CFGGEN -j /etc/sonic/config_db$DEV.json --write-to-db fi 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" - fi - - $SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" fi - if [ -e /tmp/pending_config_migration ]; then + if [ -e /tmp/pending_config_migration ] || [ -e /tmp/pending_config_initialization ]; then # this is first boot to a new image, config-setup execution is pending. - # For fast/cold reboot case, DB contains nothing at this point - # Call db_migrator after config-setup loads the config (from old config or minigraph) - echo "Delaying db_migrator until config migration is over" + # for warmboot case, DB is loaded but migration is still pending + # For firstbboot/fast/cold reboot case, DB contains nothing at this point + # unset CONFIG_DB_INITIALIZED to indicate pending config load and migration + # This flag will be set to "1" after DB migration/initialization is completed as part of config-setup + $SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "0" else - # this is not a first time boot to a new image. Datbase container starts w/ old pre-existing config - if [[ -x /usr/local/bin/db_migrator.py ]]; then - # Migrate the DB to the latest schema version if needed - if [ -z "$DEV" ]; then - /usr/local/bin/db_migrator.py -o migrate - fi - fi + # set CONFIG_DB_INITIALIZED to indicate end of config load and migration + $SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" fi # Add redis UDS to the redis group and give read/write access to the group REDIS_SOCK="/var/run/redis${DEV}/redis.sock" diff --git a/files/image_config/config-setup/config-setup b/files/image_config/config-setup/config-setup index b23d84cf2607..3369b0ec86e7 100755 --- a/files/image_config/config-setup/config-setup +++ b/files/image_config/config-setup/config-setup @@ -295,6 +295,7 @@ do_config_initialization() fi rm -f /tmp/pending_config_initialization + sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" } # Restore config-setup post migration hooks from a backup copy @@ -344,13 +345,14 @@ check_all_config_db_present() } # DB schema is subject to change between two images -# Perform DB schema migration after loading backup config from previous image +# Perform DB schema migration after loading backup config/minigraph from previous image do_db_migration() { if [[ -x /usr/local/bin/db_migrator.py ]]; then # Migrate the DB to the latest schema version if needed /usr/local/bin/db_migrator.py -o migrate fi + sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" } # Perform configuration migration from backup copy. diff --git a/files/image_config/warmboot-finalizer/finalize-warmboot.sh b/files/image_config/warmboot-finalizer/finalize-warmboot.sh index 783f3881816b..b01832a6c7b8 100755 --- a/files/image_config/warmboot-finalizer/finalize-warmboot.sh +++ b/files/image_config/warmboot-finalizer/finalize-warmboot.sh @@ -74,7 +74,7 @@ function wait_for_database_service() done # Wait for configDB initialization - until [[ $(sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; + until [[ $(sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") -eq 1 ]]; do sleep 1; done diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index 0e37fe1376cd..86c2bae2ddb8 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -87,7 +87,7 @@ function wait_for_database_service() done # Wait for configDB initialization - until [[ $($SONIC_DB_CLI CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; + until [[ $($SONIC_DB_CLI CONFIG_DB GET "CONFIG_DB_INITIALIZED") -eq 1 ]]; do sleep 1; done } diff --git a/files/scripts/syncd_common.sh b/files/scripts/syncd_common.sh index a850e31b207d..826cdd731ba6 100755 --- a/files/scripts/syncd_common.sh +++ b/files/scripts/syncd_common.sh @@ -66,7 +66,7 @@ function wait_for_database_service() done # Wait for configDB initialization - until [[ $($SONIC_DB_CLI CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; + until [[ $($SONIC_DB_CLI CONFIG_DB GET "CONFIG_DB_INITIALIZED") -eq 1 ]]; do sleep 1; done }