diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 08aaae769fa8..8a2a8f988b70 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -184,8 +184,10 @@ sudo chroot $FILESYSTEM_ROOT service docker stop sudo cp {{script}} $FILESYSTEM_ROOT/usr/bin/ {% endfor %} {% for service in installer_services.split(' ') -%} -sudo cp {{service}} $FILESYSTEM_ROOT/etc/systemd/system/ -sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable {{service}} +if [ -f {{service}} ]; then + sudo cp {{service}} $FILESYSTEM_ROOT/etc/systemd/system/ + sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable {{service}} +fi {% endfor %} sudo LANG=C chroot $FILESYSTEM_ROOT fuser -km /sys || true sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys diff --git a/files/build_templates/swss.service.j2 b/files/build_templates/swss.service.j2 index f60ef6712dd8..3af444a553d4 100644 --- a/files/build_templates/swss.service.j2 +++ b/files/build_templates/swss.service.j2 @@ -1,18 +1,40 @@ [Unit] -Description=switch state service container +Description=switch state service Requires=database.service After=database.service [Service] -User={{ sonicadmin_user }} # Wait for redis server start before database clean ExecStartPre=/bin/bash -c "while true; do if [ \"$(/usr/bin/docker exec database redis-cli ping)\" == \"PONG\" ]; then break; fi; 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 -ExecStart=/usr/bin/{{docker_container_name}}.sh start + +{% if sonic_hwsku == 'ACS-MSN2700' %} +ExecStartPre=/etc/init.d/sxdkernel start +ExecStartPre=/usr/bin/mst start +ExecStartPre=/etc/mlnx/msn2700 start +{% elif sonic_hwsku == 'AS7512' %} +ExecStartPre=-/etc/init.d/xpnet.sh stop +ExecStartPre=/etc/init.d/xpnet.sh start +{% endif %} + +# systemd allows only one parent process within service, +# so we spawn both dockers from single bash parent +ExecStart=/bin/bash -c "/usr/bin/{{docker_container_name}}.sh start & /usr/bin/syncd.sh start & wait -n 0" + ExecStop=/usr/bin/{{docker_container_name}}.sh stop ExecStopPost=/usr/bin/syncd.sh stop +{% if sonic_hwsku == 'ACS-MSN2700' %} +ExecStopPost=/etc/mlnx/msn2700 stop +ExecStopPost=/etc/init.d/sxdkernel stop +ExecStopPost=/usr/bin/mst stop +{% elif sonic_hwsku == 'AS7512' %} +ExecStopPost=/etc/init.d/xpnet.sh stop +ExecStopPost=/etc/init.d/xpnet.sh start +{% endif %} + + [Install] WantedBy=multi-user.target diff --git a/files/build_templates/syncd.service.j2 b/files/build_templates/syncd.service.j2 deleted file mode 100644 index e0fdb7e270a5..000000000000 --- a/files/build_templates/syncd.service.j2 +++ /dev/null @@ -1,29 +0,0 @@ -[Unit] -Description=syncd container -Requires=database.service -After=database.service - -[Service] -User=root -{% if sonic_hwsku == 'ACS-MSN2700' %} -ExecStartPre=/etc/init.d/sxdkernel start -ExecStartPre=/usr/bin/mst start -ExecStartPre=/etc/mlnx/msn2700 start -{% elif sonic_hwsku == 'AS7512' %} -ExecStartPre=-/etc/init.d/xpnet.sh stop -ExecStartPre=/etc/init.d/xpnet.sh start -{% endif %} -ExecStart=/usr/bin/{{docker_container_name}}.sh start -ExecStop=/usr/bin/{{docker_container_name}}.sh stop -{% if sonic_hwsku == 'ACS-MSN2700' %} -ExecStopPost=/etc/mlnx/msn2700 stop -ExecStopPost=/etc/init.d/sxdkernel stop -ExecStopPost=/usr/bin/mst stop -{% elif sonic_hwsku == 'AS7512' %} -ExecStopPost=/etc/init.d/xpnet.sh stop -ExecStopPost=/etc/init.d/xpnet.sh start -{% endif %} -Restart=always - -[Install] -WantedBy=multi-user.target diff --git a/slave.mk b/slave.mk index fbec243d7149..0a5548a29dcc 100644 --- a/slave.mk +++ b/slave.mk @@ -322,7 +322,9 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : .platform export docker_container_name="$($(docker)_CONTAINER_NAME)" export docker_image_run_opt="$($(docker)_RUN_OPT)" j2 files/build_templates/docker_image_ctl.j2 > $($(docker)_CONTAINER_NAME).sh - j2 files/build_templates/$($(docker)_CONTAINER_NAME).service.j2 > $($(docker)_CONTAINER_NAME).service + if [ -f files/build_templates/$($(docker)_CONTAINER_NAME).service.j2 ]; then + j2 files/build_templates/$($(docker)_CONTAINER_NAME).service.j2 > $($(docker)_CONTAINER_NAME).service + fi chmod +x $($(docker)_CONTAINER_NAME).sh ) @@ -342,8 +344,8 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : .platform TARGET_MACHINE=$($*_MACHINE) IMAGE_TYPE=$($*_IMAGE_TYPE) DEBUG_BUILD=$(DEBUG_BUILD) ./build_image.sh $(LOG) $(foreach docker, $($*_DOCKERS), \ - rm $($(docker)_CONTAINER_NAME).sh - rm $($(docker)_CONTAINER_NAME).service + rm -f $($(docker)_CONTAINER_NAME).sh + rm -f $($(docker)_CONTAINER_NAME).service ) $(if $($*_DOCKERS),