From a500a610e13a257ec8ade30786f0068cf90b55b3 Mon Sep 17 00:00:00 2001 From: Ying Xie Date: Thu, 8 Aug 2019 15:32:25 +0000 Subject: [PATCH 1/4] [service dependent] describe non-warm-reboot dependency outside systemctl When dependency was described with systemctl, it will kick in all the time, including under warm reboot/restart scenarios. This is not what we always want. For components that are capable of warm reboot/start, they need to describe dependency in service files. Signed-off-by: Ying Xie --- files/build_templates/teamd.service.j2 | 2 +- files/scripts/swss.sh | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/files/build_templates/teamd.service.j2 b/files/build_templates/teamd.service.j2 index 58c858effb36..1bea7b7d48be 100644 --- a/files/build_templates/teamd.service.j2 +++ b/files/build_templates/teamd.service.j2 @@ -11,4 +11,4 @@ ExecStart=/usr/bin/{{docker_container_name}}.sh wait ExecStop=/usr/bin/{{docker_container_name}}.sh stop [Install] -WantedBy=multi-user.target swss.service +WantedBy=multi-user.target diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index 88bce037b9c4..55c75a27871f 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -2,6 +2,7 @@ SERVICE="swss" PEER="syncd" +DEPENDENT="teamd" DEBUGLOG="/tmp/swss-syncd-debug.log" LOCKFILE="/tmp/swss-syncd-lock" @@ -83,6 +84,9 @@ startPeerService() { if [[ x"$WARM_BOOT" != x"true" ]]; then /bin/systemctl start ${PEER} + for dep in ${DEPENDENT}; do + /bin/systemctl start ${dep} + done fi } @@ -138,6 +142,9 @@ stop() { # if warm start enabled or peer lock exists, don't stop peer service docker if [[ x"$WARM_BOOT" != x"true" ]]; then /bin/systemctl stop ${PEER} + for dep in ${DEPENDENT}; do + /bin/systemctl stop ${dep} + done fi } From 39c0c2c89cde1369878557d541ca119dba9371d1 Mon Sep 17 00:00:00 2001 From: Ying Xie Date: Thu, 8 Aug 2019 18:46:27 +0000 Subject: [PATCH 2/4] [service] teamd service should not require swss service Adding require swss will cause teamd to be killed by systemctl when swss stops. This is not what we want in warm reboot. Signed-off-by: Ying Xie --- files/build_templates/teamd.service.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/build_templates/teamd.service.j2 b/files/build_templates/teamd.service.j2 index 1bea7b7d48be..8034698ecc07 100644 --- a/files/build_templates/teamd.service.j2 +++ b/files/build_templates/teamd.service.j2 @@ -1,6 +1,6 @@ [Unit] Description=TEAMD container -Requires=updategraph.service swss.service +Requires=updategraph.service After=updategraph.service swss.service Before=ntp-config.service From 5ea509c193591c08a9847a6887263bd6551cd9d3 Mon Sep 17 00:00:00 2001 From: Ying Xie Date: Thu, 8 Aug 2019 18:53:09 +0000 Subject: [PATCH 3/4] refactoring code --- files/scripts/swss.sh | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index 55c75a27871f..60e5d21f6a1d 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -79,7 +79,7 @@ function clean_up_tables() end" 0 } -startPeerService() { +startPeerAndDependentService() { check_warm_boot if [[ x"$WARM_BOOT" != x"true" ]]; then @@ -90,6 +90,16 @@ startPeerService() { fi } +stopPeerAndDependentService() { + # if warm start enabled or peer lock exists, don't stop peer service docker + if [[ x"$WARM_BOOT" != x"true" ]]; then + /bin/systemctl stop ${PEER} + for dep in ${DEPENDENT}; do + /bin/systemctl stop ${dep} + done + fi +} + start() { debug "Starting ${SERVICE} service..." @@ -120,7 +130,7 @@ start() { } wait() { - startPeerService + startPeerAndDependentService /usr/bin/${SERVICE}.sh wait } @@ -139,13 +149,7 @@ stop() { # Unlock has to happen before reaching out to peer service unlock_service_state_change - # if warm start enabled or peer lock exists, don't stop peer service docker - if [[ x"$WARM_BOOT" != x"true" ]]; then - /bin/systemctl stop ${PEER} - for dep in ${DEPENDENT}; do - /bin/systemctl stop ${dep} - done - fi + stopPeerAndDependentService } case "$1" in From 4c0d1dea86bd4c9ab628d41440acad9a8e4526e1 Mon Sep 17 00:00:00 2001 From: Ying Xie Date: Thu, 8 Aug 2019 12:30:38 -0700 Subject: [PATCH 4/4] rename functions to match other functions in the file --- files/scripts/swss.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index 60e5d21f6a1d..7b6ae6b5dbfe 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -79,7 +79,7 @@ function clean_up_tables() end" 0 } -startPeerAndDependentService() { +start_peer_and_dependent_services() { check_warm_boot if [[ x"$WARM_BOOT" != x"true" ]]; then @@ -90,7 +90,7 @@ startPeerAndDependentService() { fi } -stopPeerAndDependentService() { +stop_peer_and_dependent_services() { # if warm start enabled or peer lock exists, don't stop peer service docker if [[ x"$WARM_BOOT" != x"true" ]]; then /bin/systemctl stop ${PEER} @@ -130,7 +130,7 @@ start() { } wait() { - startPeerAndDependentService + start_peer_and_dependent_services /usr/bin/${SERVICE}.sh wait } @@ -149,7 +149,7 @@ stop() { # Unlock has to happen before reaching out to peer service unlock_service_state_change - stopPeerAndDependentService + stop_peer_and_dependent_services } case "$1" in