Skip to content

Commit 681e34a

Browse files
authored
[service] add warmboot finializer service (#2725)
After warm reboot is done, we need to disable warm reboot flag and tear down anything setup for warm reboot and persisted across. Signed-off-by: Ying Xie <[email protected]>
1 parent 1b07437 commit 681e34a

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

files/build_templates/sonic_debian_extension.j2

+5
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable ntp-config.service
144144
sudo cp $IMAGE_CONFIGS/ntp/ntp-config.sh $FILESYSTEM_ROOT/usr/bin/
145145
sudo cp $IMAGE_CONFIGS/ntp/ntp.conf.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/
146146

147+
# Copy warmboot-finalizer files
148+
sudo LANG=C cp $IMAGE_CONFIGS/warmboot-finalizer/finalize-warmboot.sh $FILESYSTEM_ROOT/usr/local/bin/finalize-warmboot.sh
149+
sudo LANG=C cp $IMAGE_CONFIGS/warmboot-finalizer/warmboot-finalizer.service $FILESYSTEM_ROOT/etc/systemd/system/
150+
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable warmboot-finalizer.service
151+
147152
# Copy rsyslog configuration files and templates
148153
sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-config.service $FILESYSTEM_ROOT/etc/systemd/system/
149154
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable rsyslog-config.service
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#! /bin/bash
2+
3+
VERBOSE=no
4+
5+
# Check components
6+
COMP_LIST="orchagent neighsyncd bgp"
7+
EXP_STATE="reconciled"
8+
9+
ASSISTANT_SCRIPT="/usr/bin/neighbor_advertiser"
10+
11+
12+
function debug()
13+
{
14+
/usr/bin/logger "WARMBOOT_FINALIZER : $1"
15+
if [[ x"${VERBOSE}" == x"yes" ]]; then
16+
echo `date` "- $1"
17+
fi
18+
}
19+
20+
21+
function check_warm_boot()
22+
{
23+
WARM_BOOT=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|system" enable`
24+
}
25+
26+
27+
function wait_for_database_service()
28+
{
29+
debug "Wait for database to become ready..."
30+
31+
# Wait for redis server start before database clean
32+
until [[ $(/usr/bin/docker exec database redis-cli ping | grep -c PONG) -gt 0 ]];
33+
do sleep 1;
34+
done
35+
36+
# Wait for configDB initialization
37+
until [[ $(/usr/bin/docker exec database redis-cli -n 4 GET "CONFIG_DB_INITIALIZED") ]];
38+
do sleep 1;
39+
done
40+
41+
debug "Database is ready..."
42+
}
43+
44+
45+
function get_component_state()
46+
{
47+
/usr/bin/redis-cli -n 6 hget "WARM_RESTART_TABLE|$1" state
48+
}
49+
50+
51+
function check_list()
52+
{
53+
RET_LIST=''
54+
for comp in $@; do
55+
state=`get_component_state ${comp}`
56+
if [[ x"${state}" != x"${EXP_STATE}" ]]; then
57+
RET_LIST="${RET_LIST} ${comp}"
58+
fi
59+
done
60+
61+
echo ${RET_LIST}
62+
}
63+
64+
65+
function finalize_warm_boot()
66+
{
67+
debug "Finalizing warmboot..."
68+
sudo config warm_restart disable
69+
}
70+
71+
72+
wait_for_database_service
73+
74+
check_warm_boot
75+
76+
if [[ x"${WARM_BOOT}" != x"true" ]]; then
77+
debug "warmboot is not enabled ..."
78+
exit 0
79+
fi
80+
81+
list=${COMP_LIST}
82+
83+
# Wait up to 5 minutes
84+
for i in `seq 60`; do
85+
list=`check_list ${list}`
86+
if [[ -z "${list}" ]]; then
87+
break
88+
fi
89+
sleep 5
90+
done
91+
92+
if [[ -n "${list}" ]]; then
93+
debug "Some components didn't finish reconcile: ${list} ..."
94+
fi
95+
96+
finalize_warm_boot
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
Description=Monitor warm recovery and disable warmboot when done
3+
Requires=database.service
4+
After=database.service
5+
6+
[Service]
7+
Type=oneshot
8+
ExecStart=/usr/local/bin/finalize-warmboot.sh
9+
10+
[Install]
11+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)