Skip to content

Commit eaea921

Browse files
[services] kill container on stop in warm/fast mode
Signed-off-by: Stepan Blyschak <[email protected]>
1 parent 13aa233 commit eaea921

12 files changed

+116
-100
lines changed

files/build_templates/docker_image_ctl.j2

+14-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function updateSyslogConf()
3636
TARGET_IP=$(docker network inspect bridge --format={{ "'{{(index .IPAM.Config 0).Gateway}}'" }})
3737
CONTAINER_NAME="$DOCKERNAME"
3838
TMP_FILE="/tmp/rsyslog.$CONTAINER_NAME.conf"
39-
{%- if docker_container_name == "database" %}
39+
{%- if docker_container_name == "database" %}
4040
python -c "import jinja2, os; paths=['/usr/share/sonic/templates']; loader = jinja2.FileSystemLoader(paths); env = jinja2.Environment(loader=loader, trim_blocks=True); template_file='/usr/share/sonic/templates/rsyslog-container.conf.j2'; template = env.get_template(os.path.basename(template_file)); data=template.render({\"target_ip\":\"$TARGET_IP\",\"container_name\":\"$CONTAINER_NAME\"}); print(data)" > $TMP_FILE
4141
{%- else %}
4242
sonic-cfggen -t /usr/share/sonic/templates/rsyslog-container.conf.j2 -a "{\"target_ip\": \"$TARGET_IP\", \"container_name\": \"$CONTAINER_NAME\" }" > $TMP_FILE
@@ -105,7 +105,7 @@ function preStartAction()
105105
if [[ $(/bin/systemctl status watchdog-control.service | grep -c running) -gt 0 ]]; then
106106
echo "Stopping watchdog-control.service before starting PDE"
107107
systemctl stop watchdog-control.service
108-
fi
108+
fi
109109
{%- elif docker_container_name == "snmp" %}
110110
$SONIC_DB_CLI STATE_DB HSET 'DEVICE_METADATA|localhost' chassis_serial_number $(decode-syseeprom -s)
111111
{%- else %}
@@ -500,6 +500,17 @@ stop() {
500500
{%- endif %}
501501
}
502502

503+
kill() {
504+
{%- if docker_container_name == "database" %}
505+
docker kill $DOCKERNAME
506+
if [ "$DEV" ]; then
507+
ip netns delete "$NET_NS"
508+
fi
509+
{%- else %}
510+
/usr/local/bin/container kill $DOCKERNAME
511+
{%- endif %}
512+
}
513+
503514
DOCKERNAME={{docker_container_name}}
504515
OP=$1
505516
DEV=$2 # namespace/device number to operate on
@@ -527,7 +538,7 @@ fi
527538
[ -f /etc/sonic/sonic-environment ] && . /etc/sonic/sonic-environment
528539

529540
case "$1" in
530-
start|wait|stop)
541+
start|wait|stop|kill)
531542
$1
532543
;;
533544
*)

files/build_templates/mgmt-framework.service.j2

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ Before=ntp-config.service
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

files/build_templates/per_namespace/database.service.j2

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ StartLimitBurst=3
1414

1515
[Service]
1616
User=root
17-
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start{% if multi_instance == 'true' %} %i{% endif %}
18-
ExecStart=/usr/bin/{{docker_container_name}}.sh wait{% if multi_instance == 'true' %} %i{% endif %}
19-
ExecStop=/usr/bin/{{docker_container_name}}.sh stop{% if multi_instance == 'true' %} %i{% endif %}
17+
ExecStartPre=/usr/local/bin/{{docker_container_name}}.sh start{% if multi_instance == 'true' %} %i{% endif %}
18+
ExecStart=/usr/local/bin/{{docker_container_name}}.sh wait{% if multi_instance == 'true' %} %i{% endif %}
19+
ExecStop=/usr/local/bin/{{docker_container_name}}.sh stop{% if multi_instance == 'true' %} %i{% endif %}
2020
RestartSec=30
2121

2222
[Install]

files/build_templates/snmp.service.j2

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ StartLimitIntervalSec=1200
1010
StartLimitBurst=3
1111

1212
[Service]
13-
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start
14-
ExecStart=/usr/bin/{{docker_container_name}}.sh wait
15-
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
13+
ExecStartPre=/usr/local/bin/{{docker_container_name}}.sh start
14+
ExecStart=/usr/local/bin/{{docker_container_name}}.sh wait
15+
ExecStop=/usr/local/bin/{{docker_container_name}}.sh stop
1616
RestartSec=30

files/build_templates/sonic_debian_extension.j2

+5-1
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ fi
647647
## ensure proc is mounted
648648
sudo mount proc /proc -t proc || true
649649
if [[ $CONFIGURED_ARCH == armhf ]]; then
650-
# A workaround to fix the armhf build hung issue, caused by sonic-platform-nokia-7215_1.0_armhf.deb post installation script
650+
# A workaround to fix the armhf build hung issue, caused by sonic-platform-nokia-7215_1.0_armhf.deb post installation script
651651
ps -eo pid,cmd | grep python | grep "/etc/entropy.py" | awk '{print $1}' | xargs sudo kill -9 2>/dev/null || true
652652
fi
653653

@@ -783,6 +783,10 @@ sudo LANG=C cp $SCRIPTS_DIR/bgp.sh $FILESYSTEM_ROOT/usr/local/bin/bgp.sh
783783
sudo LANG=C cp $SCRIPTS_DIR/teamd.sh $FILESYSTEM_ROOT/usr/local/bin/teamd.sh
784784
sudo LANG=C cp $SCRIPTS_DIR/lldp.sh $FILESYSTEM_ROOT/usr/local/bin/lldp.sh
785785
sudo LANG=C cp $SCRIPTS_DIR/radv.sh $FILESYSTEM_ROOT/usr/local/bin/radv.sh
786+
sudo LANG=C cp $SCRIPTS_DIR/database.sh $FILESYSTEM_ROOT/usr/local/bin/database.sh
787+
sudo LANG=C cp $SCRIPTS_DIR/snmp.sh $FILESYSTEM_ROOT/usr/local/bin/snmp.sh
788+
sudo LANG=C cp $SCRIPTS_DIR/telemetry.sh $FILESYSTEM_ROOT/usr/local/bin/telemetry.sh
789+
sudo LANG=C cp $SCRIPTS_DIR/mgmt-framework.sh $FILESYSTEM_ROOT/usr/local/bin/mgmt-framework.sh
786790
sudo LANG=C cp $SCRIPTS_DIR/asic_status.sh $FILESYSTEM_ROOT/usr/local/bin/asic_status.sh
787791
sudo LANG=C cp $SCRIPTS_DIR/asic_status.py $FILESYSTEM_ROOT/usr/local/bin/asic_status.py
788792

files/build_templates/telemetry.service.j2

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ StartLimitBurst=3
1010

1111
[Service]
1212
User={{ sonicadmin_user }}
13-
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start
14-
ExecStart=/usr/bin/{{docker_container_name}}.sh wait
15-
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
13+
ExecStartPre=/usr/local/bin/{{docker_container_name}}.sh start
14+
ExecStart=/usr/local/bin/{{docker_container_name}}.sh wait
15+
ExecStop=/usr/local/bin/{{docker_container_name}}.sh stop
1616
RestartSec=30

files/scripts/database.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
service_mgmt.sh

files/scripts/mgmt-framework.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
service_mgmt.sh

files/scripts/radv.sh

-84
This file was deleted.

files/scripts/radv.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
service_mgmt.sh

files/scripts/service_mgmt.sh

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
# start service docker
33+
/usr/bin/${SERVICE}.sh start $DEV
34+
debug "Started ${SERVICE}$DEV service..."
35+
}
36+
37+
wait() {
38+
/usr/bin/${SERVICE}.sh wait $DEV
39+
}
40+
41+
stop() {
42+
debug "Stopping ${SERVICE}$DEV service..."
43+
44+
check_warm_boot
45+
check_fast_boot
46+
debug "Warm boot flag: ${SERVICE}$DEV ${WARM_BOOT}."
47+
debug "Fast boot flag: ${SERVICE}$DEV ${FAST_BOOT}."
48+
49+
# For WARM/FAST boot do not perform service stop
50+
if [[ x"$WARM_BOOT" != x"true" ]] && [[ x"$FAST_BOOT" != x"true" ]]; then
51+
/usr/bin/${SERVICE}.sh stop $DEV
52+
debug "Stopped ${SERVICE}$DEV service..."
53+
else
54+
debug "Killing Docker ${SERVICE}${DEV}..."
55+
/usr/bin/${SERVICE}.sh kill $DEV
56+
fi
57+
}
58+
59+
DEV=$2
60+
61+
SCRIPT_NAME=$(basename -- "$0")
62+
SERVICE="${SCRIPT_NAME%.*}"
63+
DEBUGLOG="/tmp/$SERVICE-debug$DEV.log"
64+
NAMESPACE_PREFIX="asic"
65+
if [ "$DEV" ]; then
66+
NET_NS="$NAMESPACE_PREFIX$DEV" #name of the network namespace
67+
SONIC_DB_CLI="sonic-db-cli -n $NET_NS"
68+
else
69+
SONIC_DB_CLI="sonic-db-cli"
70+
fi
71+
72+
case "$1" in
73+
start|wait|stop)
74+
$1
75+
;;
76+
*)
77+
echo "Usage: $0 {start|wait|stop}"
78+
exit 1
79+
;;
80+
esac

files/scripts/snmp.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
service_mgmt.sh

files/scripts/telemetry.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
service_mgmt.sh

0 commit comments

Comments
 (0)