Skip to content

Commit

Permalink
[gearbox] Add peer gbsyncd for swss if gearbox exists (#10504)
Browse files Browse the repository at this point in the history
Fix the issues #10501 and #9733

If having gearbox, we need:
    * add gbsyncd as a peer since swss also has dependency on gbsyncd
    * add service gbsyncd to FEATURE table if it is missing
  • Loading branch information
jimmyzhai committed Apr 20, 2022
1 parent d853c9c commit 128d762
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
6 changes: 5 additions & 1 deletion files/scripts/gbsyncd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
57 changes: 40 additions & 17 deletions files/scripts/swss.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -207,11 +211,18 @@ 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
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
if [[ ! -z $DEV ]]; then
Expand All @@ -225,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
Expand All @@ -243,7 +254,7 @@ wait() {
done

if [[ ! -z $DEV ]]; then
/usr/bin/docker-wait-any -s ${SERVICE}$DEV -d ${PEER}$DEV ${ALL_DEPS}
/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
Expand Down Expand Up @@ -283,6 +294,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"
Expand All @@ -291,6 +313,7 @@ else
SONIC_DB_CLI="sonic-db-cli"
fi

check_peer_gbsyncd
read_dependent_services

case "$1" in
Expand Down
8 changes: 8 additions & 0 deletions platform/components/docker-gbsyncd-credo/supervisord.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 128d762

Please sign in to comment.