From e8965650e4099a1a9dea472aebb629b2fc5d9036 Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Wed, 22 Aug 2018 09:24:44 +0000 Subject: [PATCH] [swss]: simplify swss systemd service file move the swss service start/stop logic into /usr/local/bin/swss.sh Signed-off-by: Guohan Lu --- .../build_templates/sonic_debian_extension.j2 | 4 ++ files/build_templates/swss.service.j2 | 38 +------------ files/scripts/swss.sh | 57 +++++++++++++++++++ 3 files changed, 64 insertions(+), 35 deletions(-) create mode 100755 files/scripts/swss.sh diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index b43e616e1756..9a4af3c3c637 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -27,6 +27,7 @@ set -x -e . functions.sh BUILD_TEMPLATES=files/build_templates IMAGE_CONFIGS=files/image_config +SCRIPTS_DIR=files/scripts # Define target fold macro FILESYSTEM_ROOT_USR="$FILESYSTEM_ROOT/usr" @@ -292,6 +293,9 @@ sudo LANG=C chroot $FILESYSTEM_ROOT fuser -km /sys || true sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys {% endif %} +# Copy swss service script +sudo LANG=C cp $SCRIPTS_DIR/swss.sh $FILESYSTEM_ROOT/usr/local/bin/swss.sh + # Copy systemd timer configuration # It implements delayed start of services sudo cp $BUILD_TEMPLATES/snmp.timer $FILESYSTEM_ROOT/etc/systemd/system/ diff --git a/files/build_templates/swss.service.j2 b/files/build_templates/swss.service.j2 index 08e3f50e2697..61fff9721aed 100644 --- a/files/build_templates/swss.service.j2 +++ b/files/build_templates/swss.service.j2 @@ -16,41 +16,9 @@ After=nps-modules-4.9.0-7-amd64.service [Service] User=root -# Wait for redis server start before database clean -ExecStartPre=/bin/bash -c 'until [[ $(/usr/bin/docker exec database redis-cli ping | grep -c PONG) -gt 0 ]]; do sleep 1; done' -ExecStartPre=/usr/bin/docker exec database redis-cli -n 0 FLUSHDB -ExecStartPre=/usr/bin/docker exec database redis-cli -n 1 FLUSHDB -ExecStartPre=/usr/bin/docker exec database redis-cli -n 2 FLUSHDB -ExecStartPre=/usr/bin/docker exec database redis-cli -n 5 FLUSHDB -ExecStartPre=/usr/bin/docker exec database redis-cli -n 6 FLUSHDB - -{% if sonic_asic_platform == 'mellanox' %} -Environment=FAST_BOOT=1 -TimeoutStartSec=3min -ExecStartPre=/usr/bin/mst start -ExecStartPre=/usr/bin/mlnx-fw-upgrade.sh -ExecStartPre=/etc/init.d/sxdkernel start -ExecStartPre=/sbin/modprobe i2c-dev -ExecStartPre=/bin/bash -c "/etc/mlnx/mlnx-hw-management start" -{% elif sonic_asic_platform == 'cavium' %} -ExecStartPre=/etc/init.d/xpnet.sh start -{% endif %} - -ExecStartPre=/usr/bin/{{docker_container_name}}.sh start -ExecStartPre=/usr/bin/syncd.sh start -ExecStart=/usr/bin/{{docker_container_name}}.sh attach - -ExecStop=/usr/bin/{{docker_container_name}}.sh stop -ExecStopPost=/usr/bin/syncd.sh stop - -{% if sonic_asic_platform == 'mellanox' %} -ExecStopPost=/bin/bash -c "/etc/mlnx/mlnx-hw-management stop" -ExecStopPost=/etc/init.d/sxdkernel stop -ExecStopPost=/usr/bin/mst stop -{% elif sonic_asic_platform == 'cavium' %} -ExecStopPost=/etc/init.d/xpnet.sh stop -ExecStopPost=/etc/init.d/xpnet.sh start -{% endif %} +Environment=sonic_asic_platform={{ sonic_asic_platform }} +ExecStart=/usr/local/bin/swss.sh start +ExecStop=/usr/local/bin/swss.sh stop [Install] WantedBy=multi-user.target diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh new file mode 100755 index 000000000000..de46c0fbe7fc --- /dev/null +++ b/files/scripts/swss.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +start() { + # Wait for redis server start before database clean + until [[ $(/usr/bin/docker exec database redis-cli ping | grep -c PONG) -gt 0 ]]; + do sleep 1; + done + + # Flush DB + /usr/bin/docker exec database redis-cli -n 0 FLUSHDB + /usr/bin/docker exec database redis-cli -n 1 FLUSHDB + /usr/bin/docker exec database redis-cli -n 2 FLUSHDB + /usr/bin/docker exec database redis-cli -n 5 FLUSHDB + /usr/bin/docker exec database redis-cli -n 6 FLUSHDB + + # platform specific tasks + if [ x$sonic_asic_platform == x'mellanox' ]; then + FAST_BOOT=1 + /usr/bin/mst start + /usr/bin/mlnx-fw-upgrade.sh + /etc/init.d/sxdkernel start + /sbin/modprobe i2c-dev + /etc/mlnx/mlnx-hw-management start + elif [ x$sonic_asic_platform == x'cavium' ]; then + /etc/init.d/xpnet.sh start + fi + + # start swss and syncd docker + /usr/bin/swss.sh start + /usr/bin/syncd.sh start + /usr/bin/swss.sh attach +} + +stop() { + /usr/bin/swss.sh stop + /usr/bin/syncd.sh stop + + # platform specific tasks + if [ x$sonic_asic_platform == x'mellanox' ]; then + /etc/mlnx/mlnx-hw-management stop + /etc/init.d/sxdkernel stop + /usr/bin/mst stop + elif [ x$sonic_asic_platform == x'cavium' ]; then + /etc/init.d/xpnet.sh stop + /etc/init.d/xpnet.sh start + fi +} + +case "$1" in + start|stop) + $1 + ;; + *) + echo "Usage: $0 {start|stop}" + exit 1 + ;; +esac