Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[service] add warmboot finializer service #2715

Merged
merged 1 commit into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable ntp-config.service
sudo cp $IMAGE_CONFIGS/ntp/ntp-config.sh $FILESYSTEM_ROOT/usr/bin/
sudo cp $IMAGE_CONFIGS/ntp/ntp.conf.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/

# Copy warmboot-finalizer files
sudo LANG=C cp $IMAGE_CONFIGS/warmboot-finalizer/finalize-warmboot.sh $FILESYSTEM_ROOT/usr/local/bin/finalize-warmboot.sh
sudo LANG=C cp $IMAGE_CONFIGS/warmboot-finalizer/warmboot-finalizer.service $FILESYSTEM_ROOT/etc/systemd/system/
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable warmboot-finalizer.service

# Copy rsyslog configuration files and templates
sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-config.service $FILESYSTEM_ROOT/etc/systemd/system/
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable rsyslog-config.service
Expand Down
96 changes: 96 additions & 0 deletions files/image_config/warmboot-finalizer/finalize-warmboot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#! /bin/bash

VERBOSE=no

# Check components
COMP_LIST="orchagent neighsyncd bgp"
EXP_STATE="reconciled"
yxieca marked this conversation as resolved.
Show resolved Hide resolved

ASSISTANT_SCRIPT="/usr/bin/neighbor_advertiser"


function debug()
{
/usr/bin/logger "WARMBOOT_FINALIZER : $1"
jleveque marked this conversation as resolved.
Show resolved Hide resolved
if [[ x"${VERBOSE}" == x"yes" ]]; then
echo `date` "- $1"
fi
}


function check_warm_boot()
{
WARM_BOOT=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|system" enable`
}


function wait_for_database_service()
{
debug "Wait for database to become ready..."

# Wait for redis server start before database clean
until [[ $(/usr/bin/docker exec database redis-cli ping | grep -c PONG) -gt 0 ]];
do sleep 1;
done

# Wait for configDB initialization
until [[ $(/usr/bin/docker exec database redis-cli -n 4 GET "CONFIG_DB_INITIALIZED") ]];
do sleep 1;
done

debug "Database is ready..."
}


function get_component_state()
{
/usr/bin/redis-cli -n 6 hget "WARM_RESTART_TABLE|$1" state
}


function check_list()
{
RET_LIST=''
for comp in $@; do
state=`get_component_state ${comp}`
if [[ x"${state}" != x"${EXP_STATE}" ]]; then
RET_LIST="${RET_LIST} ${comp}"
fi
done

echo ${RET_LIST}
}


function finalize_warm_boot()
{
debug "Finalizing warmboot..."
sudo config warm_restart disable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need sudo here

Copy link
Contributor Author

@yxieca yxieca Apr 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last login: Mon Apr 1 15:22:27 2019 from 10.20.48.209
admin@str-7260cx3-acs-2:$ config warm_restart enable
Root privileges are required for this operation
admin@str-7260cx3-acs-2:$ config warm_restart disable
Root privileges are required for this operation

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yxieca but the service runs as root?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I guess extra sudo doesn't hurt? :-)

}


wait_for_database_service

check_warm_boot

if [[ x"${WARM_BOOT}" != x"true" ]]; then
debug "warmboot is not enabled ..."
exit 0
fi

list=${COMP_LIST}

# Wait up to 5 minutes
for i in `seq 60`; do
list=`check_list ${list}`
if [[ -z "${list}" ]]; then
break
fi
sleep 5
done

if [[ -n "${list}" ]]; then
debug "Some components didn't finish reconcile: ${list} ..."
fi

finalize_warm_boot
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Monitor warm recovery and disable warmboot when done
Requires=database.service
After=database.service

[Service]
Type=oneshot
ExecStart=/usr/local/bin/finalize-warmboot.sh

[Install]
WantedBy=multi-user.target