* Fix CONFIG_DB_INITIALIZED flag check logic and set/reset flag for warm-reboot * Fix db-cli usage * Handle same image warm-reboot and generalize handling of INIT flag * Cover boot from ONIE case: set config init flag when minigraph, config_db are missing * Handle case: first boot of SONiC * Check for config init flag * Simplify logic, and do not call db_migrator for same image reboot Co-authored-by: Vaibhav Hemant Dixit <vaibhav.dixit@microsoft.com>
This commit is contained in:
parent
45880bc126
commit
f835098361
@ -224,6 +224,7 @@ function postStartAction()
|
|||||||
($(docker exec -i database$DEV sonic-db-cli PING | grep -c PONG) -gt 0) ]]; do
|
($(docker exec -i database$DEV sonic-db-cli PING | grep -c PONG) -gt 0) ]]; do
|
||||||
sleep 1;
|
sleep 1;
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ ("$BOOT_TYPE" == "warm" || "$BOOT_TYPE" == "fastfast" || "$BOOT_TYPE" == "fast") && -f $WARM_DIR/dump.rdb ]]; then
|
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
|
# retain the dump file from last boot for debugging purposes
|
||||||
mv $WARM_DIR/dump.rdb $WARM_DIR/dump.rdb.old
|
mv $WARM_DIR/dump.rdb $WARM_DIR/dump.rdb.old
|
||||||
@ -237,28 +238,18 @@ function postStartAction()
|
|||||||
$SONIC_CFGGEN -j /etc/sonic/config_db$DEV.json --write-to-db
|
$SONIC_CFGGEN -j /etc/sonic/config_db$DEV.json --write-to-db
|
||||||
fi
|
fi
|
||||||
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
|
fi
|
||||||
|
|
||||||
$SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
|
if [ -e /tmp/pending_config_migration ] || [ -e /tmp/pending_config_initialization ]; then
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -e /tmp/pending_config_migration ]; then
|
|
||||||
# this is first boot to a new image, config-setup execution is pending.
|
# this is first boot to a new image, config-setup execution is pending.
|
||||||
# For fast/cold reboot case, DB contains nothing at this point
|
# for warmboot case, DB is loaded but migration is still pending
|
||||||
# Call db_migrator after config-setup loads the config (from old config or minigraph)
|
# For firstbboot/fast/cold reboot case, DB contains nothing at this point
|
||||||
echo "Delaying db_migrator until config migration is over"
|
# 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
|
else
|
||||||
# this is not a first time boot to a new image. Datbase container starts w/ old pre-existing config
|
# set CONFIG_DB_INITIALIZED to indicate end of config load and migration
|
||||||
if [[ -x /usr/local/bin/db_migrator.py ]]; then
|
$SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
|
||||||
# Migrate the DB to the latest schema version if needed
|
|
||||||
if [ -z "$DEV" ]; then
|
|
||||||
/usr/local/bin/db_migrator.py -o migrate
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
# Add redis UDS to the redis group and give read/write access to the group
|
# Add redis UDS to the redis group and give read/write access to the group
|
||||||
REDIS_SOCK="/var/run/redis${DEV}/redis.sock"
|
REDIS_SOCK="/var/run/redis${DEV}/redis.sock"
|
||||||
|
@ -256,6 +256,7 @@ do_config_initialization()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f /tmp/pending_config_initialization
|
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
|
# Restore config-setup post migration hooks from a backup copy
|
||||||
@ -305,13 +306,14 @@ check_all_config_db_present()
|
|||||||
}
|
}
|
||||||
|
|
||||||
# DB schema is subject to change between two images
|
# 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()
|
do_db_migration()
|
||||||
{
|
{
|
||||||
if [[ -x /usr/local/bin/db_migrator.py ]]; then
|
if [[ -x /usr/local/bin/db_migrator.py ]]; then
|
||||||
# Migrate the DB to the latest schema version if needed
|
# Migrate the DB to the latest schema version if needed
|
||||||
/usr/local/bin/db_migrator.py -o migrate
|
/usr/local/bin/db_migrator.py -o migrate
|
||||||
fi
|
fi
|
||||||
|
sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Perform configuration migration from backup copy.
|
# Perform configuration migration from backup copy.
|
||||||
|
@ -74,7 +74,7 @@ function wait_for_database_service()
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Wait for configDB initialization
|
# 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;
|
do sleep 1;
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ function wait_for_database_service()
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Wait for configDB initialization
|
# 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;
|
do sleep 1;
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ function wait_for_database_service()
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Wait for configDB initialization
|
# 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;
|
do sleep 1;
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user