From b299b7c2b5c1f16403bcdc8397d887f084526cf0 Mon Sep 17 00:00:00 2001 From: Junhua Zhai Date: Fri, 8 Apr 2022 06:32:40 +0000 Subject: [PATCH 1/3] Add peer gbsyncd if gearbox exists --- files/scripts/swss.sh | 60 ++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index 4f8f1b1af054..e1a780211e5b 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -112,11 +112,13 @@ start_peer_and_dependent_services() { check_warm_boot if [[ x"$WARM_BOOT" != x"true" ]]; then - if [[ ! -z $DEV ]]; then - /bin/systemctl start ${PEER}@$DEV - else - /bin/systemctl start ${PEER} - fi + for peer in ${PEER}; do + if [[ ! -z $DEV ]]; then + /bin/systemctl start ${peer}@$DEV + else + /bin/systemctl start ${peer} + fi + done for dep in ${DEPENDENT}; do /bin/systemctl start ${dep} done @@ -143,11 +145,13 @@ stop_peer_and_dependent_services() { for dep in ${DEPENDENT}; do /bin/systemctl stop ${dep} done - if [[ ! -z $DEV ]]; then - /bin/systemctl stop ${PEER}@$DEV - else - /bin/systemctl stop ${PEER} - fi + for peer in ${PEER}; do + if [[ ! -z $DEV ]]; then + /bin/systemctl stop ${peer}@$DEV + else + /bin/systemctl stop ${peer} + fi + done fi } @@ -207,11 +211,13 @@ wait() { # NOTE: This assumes Docker containers share the same names as their # corresponding services for SECS in {1..60}; do - if [[ ! -z $DEV ]]; then - RUNNING=$(docker inspect -f '{{.State.Running}}' ${PEER}$DEV) - else - RUNNING=$(docker inspect -f '{{.State.Running}}' ${PEER}) - fi + for peer in ${PEER}; do + if [[ ! -z $DEV ]]; then + RUNNING=$(docker inspect -f '{{.State.Running}}' ${peer}$DEV) + else + RUNNING=$(docker inspect -f '{{.State.Running}}' ${peer}) + fi + done ALL_DEPS_RUNNING=true for dep in ${MULTI_INST_DEPENDENT}; do if [[ ! -z $DEV ]]; then @@ -242,11 +248,13 @@ wait() { fi done - if [[ ! -z $DEV ]]; then - /usr/bin/docker-wait-any -s ${SERVICE}$DEV -d ${PEER}$DEV ${ALL_DEPS} - else - /usr/bin/docker-wait-any -s ${SERVICE} -d ${PEER} ${ALL_DEPS} - fi + for peer in ${PEER}; do + if [[ ! -z $DEV ]]; then + /usr/bin/docker-wait-any -s ${SERVICE}$DEV -d ${peer}$DEV ${ALL_DEPS} + else + /usr/bin/docker-wait-any -s ${SERVICE} -d ${peer} ${ALL_DEPS} + fi + done } stop() { @@ -283,6 +291,17 @@ stop() { stop_peer_and_dependent_services } +function check_peer_gbsyncd() +{ + PLATFORM=`$SONIC_DB_CLI CONFIG_DB hget 'DEVICE_METADATA|localhost' platform` + HWSKU=`$SONIC_DB_CLI CONFIG_DB hget 'DEVICE_METADATA|localhost' hwsku` + GEARBOX_CONFIG=/usr/share/sonic/device/$PLATFORM/$HWSKU/$DEV/gearbox_config.json + + if [ -f $GEARBOX_CONFIG ]; then + PEER="$PEER gbsyncd" + fi +} + if [ "$DEV" ]; then NET_NS="$NAMESPACE_PREFIX$DEV" #name of the network namespace SONIC_DB_CLI="sonic-db-cli -n $NET_NS" @@ -291,6 +310,7 @@ else SONIC_DB_CLI="sonic-db-cli" fi +check_peer_gbsyncd read_dependent_services case "$1" in From e7a6ff84fc51f061238075bdbea932a58fe005b9 Mon Sep 17 00:00:00 2001 From: Junhua Zhai Date: Mon, 18 Apr 2022 12:31:41 +0000 Subject: [PATCH 2/3] 1/ Use ALL_PEERS_RUNNING 2/ Monitor container gbsyncd --- files/scripts/swss.sh | 19 +++++++++++-------- .../docker-gbsyncd-credo/supervisord.conf.j2 | 8 ++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index e1a780211e5b..40acaa33c573 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -211,12 +211,17 @@ wait() { # NOTE: This assumes Docker containers share the same names as their # corresponding services for SECS in {1..60}; do + ALL_PEERS_RUNNING=true for peer in ${PEER}; do if [[ ! -z $DEV ]]; then RUNNING=$(docker inspect -f '{{.State.Running}}' ${peer}$DEV) else RUNNING=$(docker inspect -f '{{.State.Running}}' ${peer}) fi + if [[ x"$RUNNING" != x"true" ]]; then + ALL_PEERS_RUNNING=false + break + fi done ALL_DEPS_RUNNING=true for dep in ${MULTI_INST_DEPENDENT}; do @@ -231,7 +236,7 @@ wait() { fi done - if [[ x"$RUNNING" == x"true" && x"$ALL_DEPS_RUNNING" == x"true" ]]; then + if [[ x"$ALL_PEERS_RUNNING" == x"true" && x"$ALL_DEPS_RUNNING" == x"true" ]]; then break else sleep 1 @@ -248,13 +253,11 @@ wait() { fi done - for peer in ${PEER}; do - if [[ ! -z $DEV ]]; then - /usr/bin/docker-wait-any -s ${SERVICE}$DEV -d ${peer}$DEV ${ALL_DEPS} - else - /usr/bin/docker-wait-any -s ${SERVICE} -d ${peer} ${ALL_DEPS} - fi - done + if [[ ! -z $DEV ]]; then + /usr/bin/docker-wait-any -s ${SERVICE}$DEV -d `printf "%s$DEV " ${PEER}` ${ALL_DEPS} + else + /usr/bin/docker-wait-any -s ${SERVICE} -d ${PEER} ${ALL_DEPS} + fi } stop() { diff --git a/platform/components/docker-gbsyncd-credo/supervisord.conf.j2 b/platform/components/docker-gbsyncd-credo/supervisord.conf.j2 index 6f12053ce236..01ef324450a9 100644 --- a/platform/components/docker-gbsyncd-credo/supervisord.conf.j2 +++ b/platform/components/docker-gbsyncd-credo/supervisord.conf.j2 @@ -10,6 +10,14 @@ autorestart=unexpected startretries=0 exitcodes=0,3 events=PROCESS_STATE +buffer_size=1024 + +[eventlistener:supervisor-proc-exit-listener] +command=/usr/bin/supervisor-proc-exit-listener --container-name gbsyncd +events=PROCESS_STATE_EXITED,PROCESS_STATE_RUNNING +autostart=true +autorestart=unexpected +buffer_size=1024 [program:rsyslogd] command=/usr/sbin/rsyslogd -n -iNONE From 46191f9104a64e811f6dacfd520eb4f361e826d6 Mon Sep 17 00:00:00 2001 From: Junhua Zhai Date: Tue, 19 Apr 2022 12:51:43 +0000 Subject: [PATCH 3/3] Add gbsyncd to FEATURE table if needed --- files/scripts/gbsyncd.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/files/scripts/gbsyncd.sh b/files/scripts/gbsyncd.sh index 512ceed2d747..0990de5d8257 100755 --- a/files/scripts/gbsyncd.sh +++ b/files/scripts/gbsyncd.sh @@ -3,7 +3,11 @@ . /usr/local/bin/syncd_common.sh function startplatform() { - : + # Add gbsyncd to FEATURE table, if not in. It did have same config as syncd. + if [ -z $($SONIC_DB_CLI CONFIG_DB HGET 'FEATURE|gbsyncd' state) ]; then + local CMD="local r=redis.call('DUMP', KEYS[1]); redis.call('RESTORE', KEYS[2], 0, r)" + $SONIC_DB_CLI CONFIG_DB EVAL "$CMD" 2 'FEATURE|syncd' 'FEATURE|gbsyncd' + fi } function waitplatform() {