Skip to content

Commit 31d7f27

Browse files
authored
Move RADV fastboot handling to a service script (#5108)
* New /usr/local/bin/ script to start/stop radv service
1 parent a5d7982 commit 31d7f27

File tree

3 files changed

+89
-4
lines changed

3 files changed

+89
-4
lines changed

files/build_templates/radv.service.j2

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ StartLimitBurst=3
88

99
[Service]
1010
User={{ sonicadmin_user }}
11-
ExecStartPre=/usr/bin/{{ docker_container_name }}.sh start
12-
ExecStart=/usr/bin/{{ docker_container_name }}.sh wait
13-
ExecStop=/usr/bin/{{ docker_container_name }}.sh stop
11+
ExecStartPre=/usr/local/bin/{{ docker_container_name }}.sh start
12+
ExecStart=/usr/local/bin/{{ docker_container_name }}.sh wait
13+
ExecStop=/usr/local/bin/{{ docker_container_name }}.sh stop
1414
Restart=always
1515
RestartSec=30
1616

files/build_templates/sonic_debian_extension.j2

+2-1
Original file line numberDiff line numberDiff line change
@@ -516,10 +516,11 @@ sudo LANG=C chroot $FILESYSTEM_ROOT fuser -km /sys || true
516516
sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys
517517
{% endif %}
518518

519-
# Copy swss and syncd service script
519+
# Copy service scripts (swss, syncd, bgp, radv)
520520
sudo LANG=C cp $SCRIPTS_DIR/swss.sh $FILESYSTEM_ROOT/usr/local/bin/swss.sh
521521
sudo LANG=C cp $SCRIPTS_DIR/syncd.sh $FILESYSTEM_ROOT/usr/local/bin/syncd.sh
522522
sudo LANG=C cp $SCRIPTS_DIR/bgp.sh $FILESYSTEM_ROOT/usr/local/bin/bgp.sh
523+
sudo LANG=C cp $SCRIPTS_DIR/radv.sh $FILESYSTEM_ROOT/usr/local/bin/radv.sh
523524

524525
# Copy sonic-netns-exec script
525526
sudo LANG=C cp $SCRIPTS_DIR/sonic-netns-exec $FILESYSTEM_ROOT/usr/bin/sonic-netns-exec

files/scripts/radv.sh

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
3+
function debug()
4+
{
5+
/usr/bin/logger $1
6+
/bin/echo `date` "- $1" >> ${DEBUGLOG}
7+
}
8+
9+
function check_warm_boot()
10+
{
11+
SYSTEM_WARM_START=`$SONIC_DB_CLI STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable`
12+
SERVICE_WARM_START=`$SONIC_DB_CLI STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable`
13+
if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then
14+
WARM_BOOT="true"
15+
else
16+
WARM_BOOT="false"
17+
fi
18+
}
19+
20+
function check_fast_boot ()
21+
{
22+
if [[ $($SONIC_DB_CLI STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then
23+
FAST_BOOT="true"
24+
else
25+
FAST_BOOT="false"
26+
fi
27+
}
28+
29+
start() {
30+
debug "Starting ${SERVICE}$DEV service..."
31+
32+
check_warm_boot
33+
check_fast_boot
34+
debug "Warm boot flag: ${SERVICE}$DEV ${WARM_BOOT}."
35+
debug "Fast boot flag: ${SERVICE}$DEV ${FAST_BOOT}."
36+
37+
# start service docker
38+
/usr/bin/${SERVICE}.sh start $DEV
39+
debug "Started ${SERVICE}$DEV service..."
40+
}
41+
42+
wait() {
43+
/usr/bin/${SERVICE}.sh wait $DEV
44+
}
45+
46+
stop() {
47+
debug "Stopping ${SERVICE}$DEV service..."
48+
49+
check_warm_boot
50+
check_fast_boot
51+
debug "Warm boot flag: ${SERVICE}$DEV ${WARM_BOOT}."
52+
debug "Fast boot flag: ${SERVICE}$DEV ${FAST_BOOT}."
53+
54+
# For WARM/FAST boot do not perform service stop
55+
if [[ x"$WARM_BOOT" != x"true" ]] && [[ x"$FAST_BOOT" != x"true" ]]; then
56+
/usr/bin/${SERVICE}.sh stop $DEV
57+
debug "Stopped ${SERVICE}$DEV service..."
58+
else
59+
debug "Killing Docker radv..."
60+
/usr/bin/docker kill radv &> /dev/null || debug "Docker radv is not running ($?) ..."
61+
fi
62+
}
63+
64+
DEV=$2
65+
66+
SERVICE="radv"
67+
DEBUGLOG="/tmp/radv-debug$DEV.log"
68+
NAMESPACE_PREFIX="asic"
69+
if [ "$DEV" ]; then
70+
NET_NS="$NAMESPACE_PREFIX$DEV" #name of the network namespace
71+
SONIC_DB_CLI="sonic-db-cli -n $NET_NS"
72+
else
73+
SONIC_DB_CLI="sonic-db-cli"
74+
fi
75+
76+
case "$1" in
77+
start|wait|stop)
78+
$1
79+
;;
80+
*)
81+
echo "Usage: $0 {start|wait|stop}"
82+
exit 1
83+
;;
84+
esac

0 commit comments

Comments
 (0)