diff --git a/files/build_templates/dhcp_relay.service.j2 b/files/build_templates/dhcp_relay.service.j2 index d501a663feba..b7b590a1036a 100644 --- a/files/build_templates/dhcp_relay.service.j2 +++ b/files/build_templates/dhcp_relay.service.j2 @@ -2,6 +2,8 @@ Description=DHCP relay container Requires=updategraph.service After=updategraph.service swss.service syncd.service teamd.service +BindsTo=sonic.target +After=sonic.target Before=ntp-config.service StartLimitIntervalSec=1200 StartLimitBurst=3 @@ -15,4 +17,4 @@ Restart=always RestartSec=30 [Install] -WantedBy=multi-user.target +WantedBy=sonic.target diff --git a/files/build_templates/gbsyncd.service.j2 b/files/build_templates/gbsyncd.service.j2 index e1080ae7d526..b33dfea6b00d 100644 --- a/files/build_templates/gbsyncd.service.j2 +++ b/files/build_templates/gbsyncd.service.j2 @@ -5,6 +5,8 @@ ConditionPathExists=!/usr/share/sonic/hwsku/gearbox_config.json After=database.service updategraph.service After=interfaces-config.service After=swss.service +BindsTo=sonic.target +After=sonic.target Before=ntp-config.service [Service] @@ -15,4 +17,4 @@ ExecStart=/usr/local/bin/gbsyncd.sh wait ExecStop=/usr/local/bin/gbsyncd.sh stop [Install] -WantedBy=multi-user.target +WantedBy=sonic.target diff --git a/files/build_templates/iccpd.service.j2 b/files/build_templates/iccpd.service.j2 index 979c45de72c5..d78407a87be3 100644 --- a/files/build_templates/iccpd.service.j2 +++ b/files/build_templates/iccpd.service.j2 @@ -2,6 +2,8 @@ Description=ICCPD container Requires=updategraph.service swss.service After=updategraph.service swss.service +BindsTo=sonic.target +After=sonic.target [Service] User={{ sonicadmin_user }} @@ -10,4 +12,4 @@ ExecStart=/usr/bin/{{docker_container_name}}.sh wait ExecStop=/usr/bin/{{docker_container_name}}.sh stop [Install] -WantedBy=multi-user.target swss.service +WantedBy=sonic.target swss.service diff --git a/files/build_templates/mgmt-framework.service.j2 b/files/build_templates/mgmt-framework.service.j2 index 883711aa82eb..1eb983a897fb 100644 --- a/files/build_templates/mgmt-framework.service.j2 +++ b/files/build_templates/mgmt-framework.service.j2 @@ -2,6 +2,8 @@ Description=Management Framework container Requires=database.service After=database.service swss.service syncd.service +BindsTo=sonic.target +After=sonic.target Before=ntp-config.service [Service] @@ -9,4 +11,3 @@ User={{ sonicadmin_user }} ExecStartPre=/usr/bin/{{docker_container_name}}.sh start ExecStart=/usr/bin/{{docker_container_name}}.sh wait ExecStop=/usr/bin/{{docker_container_name}}.sh stop - diff --git a/files/build_templates/mgmt-framework.timer b/files/build_templates/mgmt-framework.timer index 62ab8ef1bd58..37389fbc6db5 100644 --- a/files/build_templates/mgmt-framework.timer +++ b/files/build_templates/mgmt-framework.timer @@ -1,9 +1,11 @@ [Unit] Description=Delays management framework container until SONiC has started +PartOf=mgmt-framework.service [Timer] +OnUnitActiveSec=0 sec OnBootSec=3min 30 sec Unit=mgmt-framework.service [Install] -WantedBy=timers.target +WantedBy=timers.target sonic.target diff --git a/files/build_templates/nat.service.j2 b/files/build_templates/nat.service.j2 index 1d267cfe9302..10dc7cadf18c 100644 --- a/files/build_templates/nat.service.j2 +++ b/files/build_templates/nat.service.j2 @@ -2,6 +2,8 @@ Description=NAT container Requires=updategraph.service After=updategraph.service swss.service syncd.service +BindsTo=sonic.target +After=sonic.target Before=ntp-config.service StartLimitIntervalSec=1200 StartLimitBurst=3 @@ -15,5 +17,5 @@ Restart=always RestartSec=30 [Install] -WantedBy=multi-user.target +WantedBy=sonic.target diff --git a/files/build_templates/per_namespace/bgp.service.j2 b/files/build_templates/per_namespace/bgp.service.j2 index 9f3c72e20db5..5ba49ffc441a 100644 --- a/files/build_templates/per_namespace/bgp.service.j2 +++ b/files/build_templates/per_namespace/bgp.service.j2 @@ -4,6 +4,8 @@ Requires=database{% if multi_instance == 'true' %}@%i{% endif %}.service After=database{% if multi_instance == 'true' %}@%i{% endif %}.service Requires=updategraph.service After=updategraph.service +BindsTo=sonic.target +After=sonic.target Before=ntp-config.service StartLimitIntervalSec=1200 StartLimitBurst=3 @@ -18,4 +20,4 @@ Restart=always RestartSec=30 [Install] -WantedBy=multi-user.target +WantedBy=sonic.target diff --git a/files/build_templates/per_namespace/lldp.service.j2 b/files/build_templates/per_namespace/lldp.service.j2 index b48675b03202..fca84462934b 100644 --- a/files/build_templates/per_namespace/lldp.service.j2 +++ b/files/build_templates/per_namespace/lldp.service.j2 @@ -6,6 +6,10 @@ After=swss{% if multi_instance == 'true' %}@%i{% endif %}.service After=syncd{% if multi_instance == 'true' %}@%i{% endif %}.service Requires=updategraph.service After=updategraph.service +BindsTo=sonic.target +After=sonic.target +BindsTo=sonic.target +After=sonic.target Before=ntp-config.service StartLimitIntervalSec=1200 StartLimitBurst=3 @@ -19,4 +23,4 @@ Restart=always RestartSec=30 [Install] -WantedBy=multi-user.target +WantedBy=sonic.target diff --git a/files/build_templates/per_namespace/swss.service.j2 b/files/build_templates/per_namespace/swss.service.j2 index 8ac19037ffe7..5fb86929d3ba 100644 --- a/files/build_templates/per_namespace/swss.service.j2 +++ b/files/build_templates/per_namespace/swss.service.j2 @@ -12,6 +12,8 @@ Requires=opennsl-modules.service Requires=updategraph.service After=updategraph.service After=interfaces-config.service +BindsTo=sonic.target +After=sonic.target Before=ntp-config.service pmon.service StartLimitIntervalSec=1200 StartLimitBurst=3 @@ -26,4 +28,4 @@ Restart=always RestartSec=30 [Install] -WantedBy=multi-user.target +WantedBy=sonic.target diff --git a/files/build_templates/per_namespace/syncd.service.j2 b/files/build_templates/per_namespace/syncd.service.j2 index 8e0029a29421..9acf97c29fd4 100644 --- a/files/build_templates/per_namespace/syncd.service.j2 +++ b/files/build_templates/per_namespace/syncd.service.j2 @@ -17,6 +17,8 @@ After=nps-modules.service Requires=updategraph.service After=updategraph.service After=interfaces-config.service +BindsTo=sonic.target +After=sonic.target Before=ntp-config.service [Service] @@ -30,4 +32,4 @@ TimeoutStartSec=480 {% endif %} [Install] -WantedBy=multi-user.target +WantedBy=sonic.target diff --git a/files/build_templates/per_namespace/teamd.service.j2 b/files/build_templates/per_namespace/teamd.service.j2 index f5936baa6a79..7dff23fb83e9 100644 --- a/files/build_templates/per_namespace/teamd.service.j2 +++ b/files/build_templates/per_namespace/teamd.service.j2 @@ -7,6 +7,8 @@ After=topology.service {% endif %} Requires=updategraph.service After=updategraph.service +BindsTo=sonic.target +After=sonic.target Before=ntp-config.service StartLimitIntervalSec=1200 StartLimitBurst=3 @@ -20,4 +22,4 @@ Restart=always RestartSec=30 [Install] -WantedBy=multi-user.target +WantedBy=sonic.target diff --git a/files/build_templates/pmon.service.j2 b/files/build_templates/pmon.service.j2 index 9195b4d38ad6..59d9e6c3319a 100644 --- a/files/build_templates/pmon.service.j2 +++ b/files/build_templates/pmon.service.j2 @@ -5,6 +5,8 @@ After=database.service updategraph.service {% if sonic_asic_platform == 'mellanox' %} After=syncd.service {% endif %} +BindsTo=sonic.target +After=sonic.target Before=ntp-config.service StartLimitIntervalSec=1200 StartLimitBurst=3 @@ -18,4 +20,4 @@ Restart=always RestartSec=30 [Install] -WantedBy=multi-user.target +WantedBy=sonic.target diff --git a/files/build_templates/radv.service.j2 b/files/build_templates/radv.service.j2 index 5cf25a21046d..0427b7e60505 100644 --- a/files/build_templates/radv.service.j2 +++ b/files/build_templates/radv.service.j2 @@ -3,6 +3,8 @@ Description=Router advertiser container Requires=updategraph.service After=updategraph.service swss.service syncd.service Before=ntp-config.service +BindsTo=sonic.target +After=sonic.target StartLimitIntervalSec=1200 StartLimitBurst=3 @@ -15,4 +17,4 @@ Restart=always RestartSec=30 [Install] -WantedBy=multi-user.target +WantedBy=sonic.target diff --git a/files/build_templates/restapi.service.j2 b/files/build_templates/restapi.service.j2 index df1a50eb56c7..edc18167e93a 100644 --- a/files/build_templates/restapi.service.j2 +++ b/files/build_templates/restapi.service.j2 @@ -2,6 +2,8 @@ Description=RestAPI container Requires=updategraph.service After=updategraph.service +BindsTo=sonic.target +After=sonic.target Before=ntp-config.service [Service] @@ -13,4 +15,4 @@ Restart=always RestartSec=30 [Install] -WantedBy=multi-user.target \ No newline at end of file +WantedBy=sonic.target diff --git a/files/build_templates/sflow.service.j2 b/files/build_templates/sflow.service.j2 index e9d5a871432d..3d6a3c7f569d 100644 --- a/files/build_templates/sflow.service.j2 +++ b/files/build_templates/sflow.service.j2 @@ -2,6 +2,8 @@ Description=sFlow container Requisite=swss.service After=swss.service syncd.service hostcfgd.service +BindsTo=sonic.target +After=sonic.target Before=ntp-config.service StartLimitIntervalSec=1200 StartLimitBurst=3 @@ -15,4 +17,4 @@ Restart=always RestartSec=30 [Install] -WantedBy=multi-user.target +WantedBy=sonic.target diff --git a/files/build_templates/snmp.service.j2 b/files/build_templates/snmp.service.j2 index 4997ab737e37..a510aac5571d 100644 --- a/files/build_templates/snmp.service.j2 +++ b/files/build_templates/snmp.service.j2 @@ -3,8 +3,9 @@ Description=SNMP container Requires=updategraph.service Requisite=swss.service After=updategraph.service swss.service syncd.service +BindsTo=sonic.target +After=sonic.target Before=ntp-config.service -Conflicts=snmp.timer StartLimitIntervalSec=1200 StartLimitBurst=3 @@ -14,4 +15,3 @@ ExecStart=/usr/bin/{{docker_container_name}}.sh wait ExecStop=/usr/bin/{{docker_container_name}}.sh stop Restart=always RestartSec=30 - diff --git a/files/build_templates/snmp.timer b/files/build_templates/snmp.timer index 1b3ccf633ce4..abbcb67f6dee 100644 --- a/files/build_templates/snmp.timer +++ b/files/build_templates/snmp.timer @@ -1,6 +1,6 @@ [Unit] Description=Delays snmp container until SONiC has started -Conflicts=snmp.service +PartOf=snmp.service After=swss.service [Timer] diff --git a/files/build_templates/sonic.target b/files/build_templates/sonic.target new file mode 100644 index 000000000000..4070e21a080e --- /dev/null +++ b/files/build_templates/sonic.target @@ -0,0 +1,5 @@ +[Unit] +Description=SONiC services target. + +[Install] +WantedBy=multi-user.target diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index ba1d781b11ab..6e7025d8c92d 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -686,6 +686,9 @@ sudo cp $BUILD_TEMPLATES/mgmt-framework.timer $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_S echo "mgmt-framework.timer" | sudo tee -a $GENERATED_SERVICE_FILE {% endif %} +sudo cp $BUILD_TEMPLATES/sonic.target $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM +sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable sonic.target + sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get purge -y python-dev python3-dev sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get purge -y build-essential libssl-dev swig sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get purge -y libcairo2-dev libdbus-1-dev libgirepository1.0-dev libsystemd-dev pkg-config diff --git a/files/build_templates/telemetry.service.j2 b/files/build_templates/telemetry.service.j2 index 43fa039156d7..aa02e75ac07b 100644 --- a/files/build_templates/telemetry.service.j2 +++ b/files/build_templates/telemetry.service.j2 @@ -3,6 +3,8 @@ Description=Telemetry container Requires=database.service After=database.service swss.service syncd.service Before=ntp-config.service +BindsTo=sonic.target +After=sonic.target StartLimitIntervalSec=1200 StartLimitBurst=3 @@ -13,4 +15,3 @@ ExecStart=/usr/bin/{{docker_container_name}}.sh wait ExecStop=/usr/bin/{{docker_container_name}}.sh stop Restart=always RestartSec=30 - diff --git a/files/build_templates/telemetry.timer b/files/build_templates/telemetry.timer index e08f1c09eac6..4a605b8c50cb 100644 --- a/files/build_templates/telemetry.timer +++ b/files/build_templates/telemetry.timer @@ -1,9 +1,11 @@ [Unit] Description=Delays telemetry container until SONiC has started +PartOf=telemetry.service [Timer] +OnUnitActiveSec=0 sec OnBootSec=3min 30 sec Unit=telemetry.service [Install] -WantedBy=timers.target +WantedBy=timers.target sonic.target diff --git a/files/image_config/hostname/hostname-config.service b/files/image_config/hostname/hostname-config.service index c23ae10227a4..c82c2d0bf54e 100644 --- a/files/image_config/hostname/hostname-config.service +++ b/files/image_config/hostname/hostname-config.service @@ -2,10 +2,13 @@ Description=Update hostname based on configdb Requires=updategraph.service After=updategraph.service +BindsTo=sonic.target +After=sonic.target [Service] Type=oneshot +RemainAfterExit=yes ExecStart=/usr/bin/hostname-config.sh [Install] -WantedBy=multi-user.target +WantedBy=sonic.target diff --git a/files/image_config/interfaces/interfaces-config.service b/files/image_config/interfaces/interfaces-config.service index 71178affdee8..a3f715764616 100644 --- a/files/image_config/interfaces/interfaces-config.service +++ b/files/image_config/interfaces/interfaces-config.service @@ -2,10 +2,13 @@ Description=Update interfaces configuration Requires=updategraph.service After=updategraph.service +BindsTo=sonic.target +After=sonic.target [Service] Type=oneshot +RemainAfterExit=yes ExecStart=/usr/bin/interfaces-config.sh [Install] -WantedBy=multi-user.target +WantedBy=sonic.target diff --git a/files/image_config/ntp/ntp-config.service b/files/image_config/ntp/ntp-config.service index a22a0331045d..5639b04520e0 100644 --- a/files/image_config/ntp/ntp-config.service +++ b/files/image_config/ntp/ntp-config.service @@ -2,12 +2,15 @@ Description=Update NTP configuration Requires=updategraph.service After=updategraph.service +BindsTo=sonic.target +After=sonic.target Before=ntp.service StartLimitIntervalSec=0 [Service] Type=oneshot +RemainAfterExit=yes ExecStart=/usr/bin/ntp-config.sh [Install] -WantedBy=multi-user.target +WantedBy=sonic.target diff --git a/files/image_config/ntp/ntp.service b/files/image_config/ntp/ntp.service index acfd7e17266a..32a55dea892e 100644 --- a/files/image_config/ntp/ntp.service +++ b/files/image_config/ntp/ntp.service @@ -3,6 +3,8 @@ Description=Network Time Service Documentation=man:ntpd(8) After=network.target Conflicts=systemd-timesyncd.service +BindsTo=sonic.target +After=sonic.target StartLimitIntervalSec=0 [Service] diff --git a/files/image_config/rsyslog/rsyslog-config.service b/files/image_config/rsyslog/rsyslog-config.service index ee62a36ccf2d..34c56fb0e00b 100644 --- a/files/image_config/rsyslog/rsyslog-config.service +++ b/files/image_config/rsyslog/rsyslog-config.service @@ -2,10 +2,13 @@ Description=Update rsyslog configuration Requires=updategraph.service After=updategraph.service +BindsTo=sonic.target +After=sonic.target [Service] Type=oneshot +RemainAfterExit=yes ExecStart=/usr/bin/rsyslog-config.sh [Install] -WantedBy=multi-user.target +WantedBy=sonic.target diff --git a/src/sonic-host-services-data/debian/sonic-host-services-data.caclmgrd.service b/src/sonic-host-services-data/debian/sonic-host-services-data.caclmgrd.service index 4df4d948ef1d..e24ed10bb33d 100644 --- a/src/sonic-host-services-data/debian/sonic-host-services-data.caclmgrd.service +++ b/src/sonic-host-services-data/debian/sonic-host-services-data.caclmgrd.service @@ -2,6 +2,8 @@ Description=Control Plane ACL configuration daemon Requires=updategraph.service After=updategraph.service +BindsTo=sonic.target +After=sonic.target [Service] Type=simple @@ -10,4 +12,4 @@ Restart=always RestartSec=30 [Install] -WantedBy=multi-user.target +WantedBy=sonic.target diff --git a/src/sonic-host-services-data/debian/sonic-host-services-data.hostcfgd.service b/src/sonic-host-services-data/debian/sonic-host-services-data.hostcfgd.service index ea0c3ba60fb7..4adf2aba77ad 100644 --- a/src/sonic-host-services-data/debian/sonic-host-services-data.hostcfgd.service +++ b/src/sonic-host-services-data/debian/sonic-host-services-data.hostcfgd.service @@ -2,10 +2,13 @@ Description=Host config enforcer daemon Requires=updategraph.service After=updategraph.service +BindsTo=sonic.target +After=sonic.target [Service] Type=simple ExecStart=/usr/local/bin/hostcfgd [Install] -WantedBy=multi-user.target +WantedBy=sonic.target + diff --git a/src/sonic-host-services-data/debian/sonic-host-services-data.procdockerstatsd.service b/src/sonic-host-services-data/debian/sonic-host-services-data.procdockerstatsd.service index 388197d9741b..68b9e61b62c2 100644 --- a/src/sonic-host-services-data/debian/sonic-host-services-data.procdockerstatsd.service +++ b/src/sonic-host-services-data/debian/sonic-host-services-data.procdockerstatsd.service @@ -2,6 +2,8 @@ Description=Process and docker CPU/memory utilization data export daemon Requires=database.service updategraph.service After=database.service updategraph.service +BindsTo=sonic.target +After=sonic.target [Service] Type=simple @@ -9,5 +11,4 @@ ExecStart=/usr/local/bin/procdockerstatsd Restart=always [Install] -WantedBy=multi-user.target - +WantedBy=sonic.target