From a41d9a5d3f29e5f310908c32edadf7c141574035 Mon Sep 17 00:00:00 2001 From: Ying Xie Date: Thu, 8 Aug 2019 15:45:17 -0700 Subject: [PATCH] [service dependent] describe non-warm-reboot dependency outside systemd (#3311) * [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 * [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 * refactoring code * rename functions to match other functions in the file --- files/build_templates/teamd.service.j2 | 4 ++-- files/scripts/swss.sh | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/files/build_templates/teamd.service.j2 b/files/build_templates/teamd.service.j2 index 58c858effb36..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 @@ -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..7b6ae6b5dbfe 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" @@ -78,11 +79,24 @@ function clean_up_tables() end" 0 } -startPeerService() { +start_peer_and_dependent_services() { check_warm_boot if [[ x"$WARM_BOOT" != x"true" ]]; then /bin/systemctl start ${PEER} + for dep in ${DEPENDENT}; do + /bin/systemctl start ${dep} + done + fi +} + +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} + for dep in ${DEPENDENT}; do + /bin/systemctl stop ${dep} + done fi } @@ -116,7 +130,7 @@ start() { } wait() { - startPeerService + start_peer_and_dependent_services /usr/bin/${SERVICE}.sh wait } @@ -135,10 +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} - fi + stop_peer_and_dependent_services } case "$1" in