diff --git a/files/build_templates/gbsyncd-credo.service.j2 b/files/build_templates/gbsyncd-credo.service.j2 new file mode 120000 index 000000000000..69f613b0d892 --- /dev/null +++ b/files/build_templates/gbsyncd-credo.service.j2 @@ -0,0 +1 @@ +gbsyncd.service.j2 \ No newline at end of file diff --git a/files/build_templates/gbsyncd.service.j2 b/files/build_templates/gbsyncd.service.j2 index b33dfea6b00d..732d9c893367 100644 --- a/files/build_templates/gbsyncd.service.j2 +++ b/files/build_templates/gbsyncd.service.j2 @@ -1,5 +1,5 @@ [Unit] -Description=gbsyncd service +Description={{docker_container_name}} service Requires=database.service updategraph.service ConditionPathExists=!/usr/share/sonic/hwsku/gearbox_config.json After=database.service updategraph.service @@ -12,6 +12,8 @@ Before=ntp-config.service [Service] User=root Environment=sonic_asic_platform={{ sonic_asic_platform }} +Environment=gbsyncd_platform={{ docker_container_name }} +ExecCondition=/usr/bin/gbsyncd-platform.sh ExecStartPre=/usr/local/bin/gbsyncd.sh start ExecStart=/usr/local/bin/gbsyncd.sh wait ExecStop=/usr/local/bin/gbsyncd.sh stop diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 03fa16d26085..e4fdd92b1ea9 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -766,6 +766,7 @@ sudo LANG=C cp $SCRIPTS_DIR/swss.sh $FILESYSTEM_ROOT/usr/local/bin/swss.sh sudo LANG=C cp $SCRIPTS_DIR/syncd.sh $FILESYSTEM_ROOT/usr/local/bin/syncd.sh sudo LANG=C cp $SCRIPTS_DIR/syncd_common.sh $FILESYSTEM_ROOT/usr/local/bin/syncd_common.sh sudo LANG=C cp $SCRIPTS_DIR/gbsyncd.sh $FILESYSTEM_ROOT/usr/local/bin/gbsyncd.sh +sudo LANG=C cp $SCRIPTS_DIR/gbsyncd-platform.sh $FILESYSTEM_ROOT/usr/bin/gbsyncd-platform.sh sudo LANG=C cp $SCRIPTS_DIR/bgp.sh $FILESYSTEM_ROOT/usr/local/bin/bgp.sh sudo LANG=C cp $SCRIPTS_DIR/teamd.sh $FILESYSTEM_ROOT/usr/local/bin/teamd.sh sudo LANG=C cp $SCRIPTS_DIR/radv.sh $FILESYSTEM_ROOT/usr/local/bin/radv.sh diff --git a/files/scripts/gbsyncd-platform.sh b/files/scripts/gbsyncd-platform.sh new file mode 100755 index 000000000000..cb83e0e39e5e --- /dev/null +++ b/files/scripts/gbsyncd-platform.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# Check the gbsyncd platform defined on the device matching the service, +# or otherwise skip starting the service + +SERVICE="$gbsyncd_platform" +PLATFORM=${PLATFORM:-`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`} +DEVPATH="/usr/share/sonic/device" +CONFIGFILE="${DEVPATH}/${PLATFORM}/gbsyncd.ini" + +if [ ! -f "$CONFIGFILE" ]; then + if [ gbsyncd = "$SERVICE" ]; then + exit 0 + fi + exit 1 +fi + +while IFS="=" read -r key value; do + case "$key" in + platform) + if [ "$value" = "$SERVICE" ]; then + exit 0 + fi + ;; + esac +done < "$CONFIGFILE" + +exit 1 diff --git a/files/scripts/gbsyncd.sh b/files/scripts/gbsyncd.sh index 996fbf8cdf31..512ceed2d747 100755 --- a/files/scripts/gbsyncd.sh +++ b/files/scripts/gbsyncd.sh @@ -21,10 +21,10 @@ function stopplatform2() { OP=$1 DEV=$2 -SERVICE="gbsyncd" +SERVICE="$gbsyncd_platform" PEER="swss" -DEBUGLOG="/tmp/swss-gbsyncd-debug$DEV.log" -LOCKFILE="/tmp/swss-gbsyncd-lock$DEV" +DEBUGLOG="/tmp/swss-$SERVICE-debug$DEV.log" +LOCKFILE="/tmp/swss-$SERVICE-lock$DEV" NAMESPACE_PREFIX="asic" if [ "$DEV" ]; then NET_NS="$NAMESPACE_PREFIX$DEV" #name of the network namespace diff --git a/platform/broadcom/rules.dep b/platform/broadcom/rules.dep index fd9407aeb049..dff25a30398e 100644 --- a/platform/broadcom/rules.dep +++ b/platform/broadcom/rules.dep @@ -24,3 +24,4 @@ include $(PLATFORM_PATH)/one-aboot.dep include $(PLATFORM_PATH)/libsaithrift-dev.dep include $(PLATFORM_PATH)/docker-syncd-brcm-dnx.dep include $(PLATFORM_PATH)/docker-syncd-brcm-dnx-rpc.dep +include $(PLATFORM_PATH)/../components/docker-gbsyncd-credo.dep diff --git a/platform/broadcom/rules.mk b/platform/broadcom/rules.mk index f7fb22a07442..97e7d4b6ae6f 100644 --- a/platform/broadcom/rules.mk +++ b/platform/broadcom/rules.mk @@ -23,6 +23,7 @@ include $(PLATFORM_PATH)/one-aboot.mk include $(PLATFORM_PATH)/libsaithrift-dev.mk include $(PLATFORM_PATH)/docker-syncd-brcm-dnx.mk include $(PLATFORM_PATH)/docker-syncd-brcm-dnx-rpc.mk +include $(PLATFORM_PATH)/../components/docker-gbsyncd-credo.mk BCMCMD = bcmcmd $(BCMCMD)_URL = "https://sonicstorage.blob.core.windows.net/packages/20190307/bcmcmd?sv=2015-04-05&sr=b&sig=sUdbU7oVbh5exbXXHVL5TDFBTWDDBASHeJ8Cp0B0TIc%3D&se=2038-05-06T22%3A34%3A19Z&sp=r" diff --git a/platform/components/docker-gbsyncd-credo.dep b/platform/components/docker-gbsyncd-credo.dep new file mode 100644 index 000000000000..00551e0ac855 --- /dev/null +++ b/platform/components/docker-gbsyncd-credo.dep @@ -0,0 +1,12 @@ +DPATH := $($(DOCKER_GBSYNCD_BASE)_PATH) +DEP_FILES := $(SONIC_COMMON_FILES_LIST) +DEP_FILES += platform/components/docker-gbsyncd-credo.mk +DEP_FILES += platform/components/docker-gbsyncd-credo.dep +DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST) +DEP_FILES += $(shell git ls-files $(DPATH)) + +$(DOCKER_GBSYNCD_BASE)_CACHE_MODE := GIT_CONTENT_SHA +$(DOCKER_GBSYNCD_BASE)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) +$(DOCKER_GBSYNCD_BASE)_DEP_FILES := $(DEP_FILES) + +$(eval $(call add_dbg_docker,$(DOCKER_GBSYNCD_BASE),$(DOCKER_GBSYNCD_BASE_DBG))) diff --git a/platform/components/docker-gbsyncd-credo.mk b/platform/components/docker-gbsyncd-credo.mk new file mode 100644 index 000000000000..a1231d846355 --- /dev/null +++ b/platform/components/docker-gbsyncd-credo.mk @@ -0,0 +1,14 @@ +DOCKER_GBSYNCD_PLATFORM_CODE = credo + +LIBSAI_CREDO = libsaicredo_0.5.1-alpha.2_amd64.deb +$(LIBSAI_CREDO)_URL = +LIBSAI_CREDO_OWL = libsaicredo-owl_0.5.1-alpha.2_amd64.deb +$(LIBSAI_CREDO_OWL)_URL = + +ifneq ($($(LIBSAI_CREDO)_URL),) +include $(PLATFORM_PATH)/../template/docker-gbsyncd-base.mk +$(DOCKER_GBSYNCD_BASE)_CONTAINER_NAME = gbsyncd-$(DOCKER_GBSYNCD_PLATFORM_CODE) +$(DOCKER_GBSYNCD_BASE)_PATH = $(PLATFORM_PATH)/../components/docker-gbsyncd-$(DOCKER_GBSYNCD_PLATFORM_CODE) +SONIC_ONLINE_DEBS += $(LIBSAI_CREDO) $(LIBSAI_CREDO_OWL) +$(DOCKER_GBSYNCD_BASE)_DEPENDS += $(SYNCD) $(LIBSAI_CREDO) $(LIBSAI_CREDO_OWL) +endif diff --git a/platform/components/docker-gbsyncd-credo/Dockerfile.j2 b/platform/components/docker-gbsyncd-credo/Dockerfile.j2 new file mode 100644 index 000000000000..f82ea0e6c77d --- /dev/null +++ b/platform/components/docker-gbsyncd-credo/Dockerfile.j2 @@ -0,0 +1,40 @@ +FROM docker-config-engine-buster + +ARG docker_container_name +RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf + +## Make apt-get non-interactive +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update + +RUN apt-get install -f -y iproute2 libcap2-bin libprotobuf-dev + +COPY \ +{% for deb in docker_gbsyncd_credo_debs.split(' ') -%} +{% if 'libsaibcm' not in deb -%} +debs/{{ deb }}{{' '}} +{%- endif %} +{%- endfor -%} +debs/ + +RUN dpkg -i \ +{% for deb in docker_gbsyncd_credo_debs.split(' ') -%} +{% if 'libsaibcm' not in deb -%} +debs/{{ deb }}{{' '}} +{%- endif %} +{%- endfor %} + +COPY ["docker-init.sh", "/usr/bin/"] +COPY ["start.sh", "/usr/bin/"] + +COPY ["critical_processes.j2", "/usr/share/sonic/templates"] +COPY ["supervisord.conf.j2", "/usr/share/sonic/templates"] + +COPY ["files/supervisor-proc-exit-listener", "/usr/bin"] + +## Clean up +RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y +RUN rm -rf /debs + +ENTRYPOINT ["/usr/bin/docker-init.sh"] diff --git a/platform/components/docker-gbsyncd-credo/critical_processes.j2 b/platform/components/docker-gbsyncd-credo/critical_processes.j2 new file mode 100644 index 000000000000..bdd6903c5690 --- /dev/null +++ b/platform/components/docker-gbsyncd-credo/critical_processes.j2 @@ -0,0 +1 @@ +program:syncd diff --git a/platform/components/docker-gbsyncd-credo/docker-init.sh b/platform/components/docker-gbsyncd-credo/docker-init.sh new file mode 100755 index 000000000000..93a1b931dfad --- /dev/null +++ b/platform/components/docker-gbsyncd-credo/docker-init.sh @@ -0,0 +1,16 @@ +#! /bin/sh + +GB_CONFIG=/usr/share/sonic/hwsku/gearbox_config.json + +if [ ! -f $GB_CONFIG ]; then + exit 0 +fi + +CFGGEN_ARG="-j $GB_CONFIG" + +mkdir -p /etc/supervisor/conf.d/ + +sonic-cfggen $CFGGEN_ARG -t /usr/share/sonic/templates/supervisord.conf.j2 > /etc/supervisor/conf.d/supervisord.conf +sonic-cfggen $CFGGEN_ARG -t /usr/share/sonic/templates/critical_processes.j2 > /etc/supervisor/critical_processes + +exec /usr/local/bin/supervisord diff --git a/platform/components/docker-gbsyncd-credo/start.sh b/platform/components/docker-gbsyncd-credo/start.sh new file mode 100755 index 000000000000..ac7de02dcdca --- /dev/null +++ b/platform/components/docker-gbsyncd-credo/start.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +HWSKU_DIR=/usr/share/sonic/hwsku + +mkdir -p /etc/sai.d/ + +# Create/Copy the psai.profile to /etc/sai.d/psai.profile +if [ -f $HWSKU_DIR/psai.profile.j2 ]; then + sonic-cfggen -d -t $HWSKU_DIR/psai.profile.j2 > /etc/sai.d/psai.profile +else + if [ -f $HWSKU_DIR/psai.profile ]; then + cp $HWSKU_DIR/psai.profile /etc/sai.d/psai.profile + fi +fi diff --git a/platform/components/docker-gbsyncd-credo/supervisord.conf.j2 b/platform/components/docker-gbsyncd-credo/supervisord.conf.j2 new file mode 100644 index 000000000000..6f12053ce236 --- /dev/null +++ b/platform/components/docker-gbsyncd-credo/supervisord.conf.j2 @@ -0,0 +1,43 @@ +[supervisord] +logfile_maxbytes=1MB +logfile_backups=2 +nodaemon=true + +[eventlistener:dependent-startup] +command=python3 -m supervisord_dependent_startup +autostart=true +autorestart=unexpected +startretries=0 +exitcodes=0,3 +events=PROCESS_STATE + +[program:rsyslogd] +command=/usr/sbin/rsyslogd -n -iNONE +priority=1 +autostart=false +autorestart=unexpected +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true + +[program:start] +command=/usr/bin/start.sh +priority=2 +autostart=false +autorestart=false +startsecs=0 +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=rsyslogd:running + +[program:syncd] +environment=CREDO_DEVICE_PATH=/usr/lib +command=/usr/bin/syncd -s -p /etc/sai.d/psai.profile -x /usr/share/sonic/hwsku/context_config.json -g 1 +priority=3 +autostart=false +autorestart=false +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=start:exited diff --git a/platform/template/docker-gbsyncd-base.mk b/platform/template/docker-gbsyncd-base.mk index aa4f574141b2..579f76381010 100644 --- a/platform/template/docker-gbsyncd-base.mk +++ b/platform/template/docker-gbsyncd-base.mk @@ -27,4 +27,3 @@ $(DOCKER_GBSYNCD_BASE)_CONTAINER_NAME = gbsyncd $(DOCKER_GBSYNCD_BASE)_RUN_OPT += --net=host --privileged -t $(DOCKER_GBSYNCD_BASE)_RUN_OPT += -v /host/machine.conf:/etc/machine.conf $(DOCKER_GBSYNCD_BASE)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro -