2019-04-12 17:45:58 -05:00
|
|
|
#! /bin/bash
|
|
|
|
|
|
|
|
VERBOSE=no
|
|
|
|
|
2021-01-15 09:48:11 -06:00
|
|
|
# Define components that needs to reconcile during warm
|
|
|
|
# boot:
|
|
|
|
# The key is the name of the service that the components belong to.
|
|
|
|
# The value is list of component names that will reconcile.
|
|
|
|
declare -A RECONCILE_COMPONENTS=( \
|
|
|
|
["swss"]="orchagent neighsyncd" \
|
|
|
|
["bgp"]="bgp" \
|
|
|
|
["nat"]="natsyncd" \
|
2022-07-28 11:08:53 -05:00
|
|
|
["mux"]="linkmgrd" \
|
2021-01-15 09:48:11 -06:00
|
|
|
)
|
2021-07-11 08:58:05 -05:00
|
|
|
|
|
|
|
for reconcile_file in $(find /etc/sonic/ -iname '*_reconcile' -type f); do
|
|
|
|
file_basename=$(basename $reconcile_file)
|
|
|
|
docker_container_name=${file_basename%_reconcile}
|
|
|
|
RECONCILE_COMPONENTS[$docker_container_name]=$(cat $reconcile_file)
|
|
|
|
done
|
|
|
|
|
2019-04-12 17:45:58 -05:00
|
|
|
EXP_STATE="reconciled"
|
|
|
|
|
2020-09-20 22:16:42 -05:00
|
|
|
ASSISTANT_SCRIPT="/usr/local/bin/neighbor_advertiser"
|
2019-04-12 17:45:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
function debug()
|
|
|
|
{
|
|
|
|
/usr/bin/logger "WARMBOOT_FINALIZER : $1"
|
|
|
|
if [[ x"${VERBOSE}" == x"yes" ]]; then
|
|
|
|
echo `date` "- $1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-15 09:48:11 -06:00
|
|
|
function get_component_list()
|
|
|
|
{
|
|
|
|
SVC_LIST=${!RECONCILE_COMPONENTS[@]}
|
|
|
|
COMPONENT_LIST=""
|
|
|
|
for service in ${SVC_LIST}; do
|
|
|
|
components=${RECONCILE_COMPONENTS[${service}]}
|
|
|
|
status=$(sonic-db-cli CONFIG_DB HGET "FEATURE|${service}" state)
|
|
|
|
if [[ x"${status}" == x"enabled" || x"${status}" == x"always_enabled" ]]; then
|
|
|
|
COMPONENT_LIST="${COMPONENT_LIST} ${components}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-12 17:45:58 -05:00
|
|
|
function check_warm_boot()
|
|
|
|
{
|
2020-01-22 13:26:23 -06:00
|
|
|
WARM_BOOT=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable`
|
2019-04-12 17:45:58 -05:00
|
|
|
}
|
|
|
|
|
2023-04-09 08:59:15 -05:00
|
|
|
function check_fast_reboot()
|
|
|
|
{
|
|
|
|
debug "Checking if fast-reboot is enabled..."
|
|
|
|
FAST_REBOOT=`sonic-db-cli STATE_DB hget "FAST_RESTART_ENABLE_TABLE|system" enable`
|
|
|
|
if [[ x"${FAST_REBOOT}" == x"true" ]]; then
|
|
|
|
debug "Fast-reboot is enabled..."
|
|
|
|
else
|
|
|
|
debug "Fast-reboot is disabled..."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-04-12 17:45:58 -05:00
|
|
|
|
|
|
|
function wait_for_database_service()
|
|
|
|
{
|
|
|
|
debug "Wait for database to become ready..."
|
|
|
|
|
|
|
|
# Wait for redis server start before database clean
|
2020-05-06 17:41:28 -05:00
|
|
|
until [[ $(sonic-db-cli PING | grep -c PONG) -gt 0 ]]; do
|
|
|
|
sleep 1;
|
|
|
|
done
|
2019-04-12 17:45:58 -05:00
|
|
|
|
|
|
|
# Wait for configDB initialization
|
2023-08-04 18:00:26 -05:00
|
|
|
until [[ $(sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") -eq 1 ]];
|
2019-04-12 17:45:58 -05:00
|
|
|
do sleep 1;
|
|
|
|
done
|
|
|
|
|
|
|
|
debug "Database is ready..."
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function get_component_state()
|
|
|
|
{
|
2020-01-22 13:26:23 -06:00
|
|
|
sonic-db-cli STATE_DB hget "WARM_RESTART_TABLE|$1" state
|
2019-04-12 17:45:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function check_list()
|
|
|
|
{
|
|
|
|
RET_LIST=''
|
|
|
|
for comp in $@; do
|
|
|
|
state=`get_component_state ${comp}`
|
2021-01-15 09:48:11 -06:00
|
|
|
if [[ x"${state}" != x"${EXP_STATE}" ]]; then
|
2019-04-12 17:45:58 -05:00
|
|
|
RET_LIST="${RET_LIST} ${comp}"
|
2021-01-15 09:48:11 -06:00
|
|
|
fi
|
2019-04-12 17:45:58 -05:00
|
|
|
done
|
|
|
|
|
|
|
|
echo ${RET_LIST}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function finalize_warm_boot()
|
|
|
|
{
|
|
|
|
debug "Finalizing warmboot..."
|
|
|
|
sudo config warm_restart disable
|
|
|
|
}
|
|
|
|
|
2023-04-09 08:59:15 -05:00
|
|
|
function finalize_fast_reboot()
|
|
|
|
{
|
|
|
|
debug "Finalizing fast-reboot..."
|
|
|
|
sonic-db-cli STATE_DB hset "FAST_RESTART_ENABLE_TABLE|system" "enable" "false" &>/dev/null
|
2023-04-18 01:15:42 -05:00
|
|
|
sonic-db-cli CONFIG_DB DEL "WARM_RESTART|teamd" &>/dev/null
|
2023-04-09 08:59:15 -05:00
|
|
|
}
|
|
|
|
|
2019-08-15 02:45:54 -05:00
|
|
|
function stop_control_plane_assistant()
|
|
|
|
{
|
|
|
|
if [[ -x ${ASSISTANT_SCRIPT} ]]; then
|
|
|
|
debug "Tearing down control plane assistant ..."
|
|
|
|
${ASSISTANT_SCRIPT} -m reset
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-11-20 12:37:45 -06:00
|
|
|
function restore_counters_folder()
|
|
|
|
{
|
|
|
|
debug "Restoring counters folder after warmboot..."
|
|
|
|
|
2022-07-28 04:03:22 -05:00
|
|
|
cache_counters_folder="/host/counters"
|
|
|
|
if [[ -d $cache_counters_folder ]]; then
|
|
|
|
mv $cache_counters_folder /tmp/cache
|
2023-03-27 12:32:07 -05:00
|
|
|
chown -R admin:admin /tmp/cache
|
2022-07-28 04:03:22 -05:00
|
|
|
fi
|
2020-11-20 12:37:45 -06:00
|
|
|
}
|
|
|
|
|
2019-04-12 17:45:58 -05:00
|
|
|
|
|
|
|
wait_for_database_service
|
|
|
|
|
2023-04-09 08:59:15 -05:00
|
|
|
check_fast_reboot
|
2019-04-12 17:45:58 -05:00
|
|
|
check_warm_boot
|
|
|
|
|
|
|
|
if [[ x"${WARM_BOOT}" != x"true" ]]; then
|
|
|
|
debug "warmboot is not enabled ..."
|
2023-04-09 08:59:15 -05:00
|
|
|
if [[ x"${FAST_REBOOT}" != x"true" ]]; then
|
|
|
|
debug "fastboot is not enabled ..."
|
|
|
|
exit 0
|
|
|
|
fi
|
2019-04-12 17:45:58 -05:00
|
|
|
fi
|
|
|
|
|
2023-04-09 08:59:15 -05:00
|
|
|
if [[ (x"${WARM_BOOT}" == x"true") && (x"${FAST_REBOOT}" != x"true") ]]; then
|
|
|
|
restore_counters_folder
|
|
|
|
fi
|
2020-11-20 12:37:45 -06:00
|
|
|
|
2021-01-15 09:48:11 -06:00
|
|
|
get_component_list
|
|
|
|
|
|
|
|
debug "Waiting for components: '${COMPONENT_LIST}' to reconcile ..."
|
|
|
|
|
|
|
|
list=${COMPONENT_LIST}
|
2019-04-12 17:45:58 -05:00
|
|
|
|
|
|
|
# Wait up to 5 minutes
|
|
|
|
for i in `seq 60`; do
|
|
|
|
list=`check_list ${list}`
|
|
|
|
if [[ -z "${list}" ]]; then
|
2021-01-15 09:48:11 -06:00
|
|
|
break
|
2019-04-12 17:45:58 -05:00
|
|
|
fi
|
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
|
2023-04-09 08:59:15 -05:00
|
|
|
if [[ (x"${WARM_BOOT}" == x"true") && (x"${FAST_REBOOT}" != x"true") ]]; then
|
|
|
|
stop_control_plane_assistant
|
|
|
|
fi
|
2019-08-15 02:45:54 -05:00
|
|
|
|
2019-04-12 17:45:58 -05:00
|
|
|
if [[ -n "${list}" ]]; then
|
|
|
|
debug "Some components didn't finish reconcile: ${list} ..."
|
|
|
|
fi
|
|
|
|
|
2023-04-09 08:59:15 -05:00
|
|
|
if [ x"${FAST_REBOOT}" == x"true" ]; then
|
|
|
|
finalize_fast_reboot
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ x"${WARM_BOOT}" == x"true" ]; then
|
|
|
|
finalize_warm_boot
|
2023-04-18 01:15:42 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Save DB after stopped control plane assistant to avoid extra entries
|
|
|
|
debug "Save in-memory database after warm/fast reboot ..."
|
|
|
|
config save -y
|