Skip to content

Commit e179ec2

Browse files
[services] introduce sonic.target (#5705)
- Why I did it Group all SONiC services together and able to manage them together. Will be used in config reload command as much simpler and generic way to restart services. - How I did it Add services to sonic.target - How to verify it Together with sonic-net/sonic-utilities#1199 config reload -y Signed-off-by: Stepan Blyshchak <[email protected]>
1 parent 3de6a67 commit e179ec2

29 files changed

+90
-28
lines changed

files/build_templates/dhcp_relay.service.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Description=DHCP relay container
33
Requires=updategraph.service
44
After=updategraph.service swss.service syncd.service teamd.service
5+
BindsTo=sonic.target
6+
After=sonic.target
57
Before=ntp-config.service
68
StartLimitIntervalSec=1200
79
StartLimitBurst=3
@@ -15,4 +17,4 @@ Restart=always
1517
RestartSec=30
1618

1719
[Install]
18-
WantedBy=multi-user.target
20+
WantedBy=sonic.target

files/build_templates/gbsyncd.service.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ ConditionPathExists=!/usr/share/sonic/hwsku/gearbox_config.json
55
After=database.service updategraph.service
66
After=interfaces-config.service
77
After=swss.service
8+
BindsTo=sonic.target
9+
After=sonic.target
810
Before=ntp-config.service
911

1012
[Service]
@@ -15,4 +17,4 @@ ExecStart=/usr/local/bin/gbsyncd.sh wait
1517
ExecStop=/usr/local/bin/gbsyncd.sh stop
1618

1719
[Install]
18-
WantedBy=multi-user.target
20+
WantedBy=sonic.target

files/build_templates/iccpd.service.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Description=ICCPD container
33
Requires=updategraph.service swss.service
44
After=updategraph.service swss.service
5+
BindsTo=sonic.target
6+
After=sonic.target
57

68
[Service]
79
User={{ sonicadmin_user }}
@@ -10,4 +12,4 @@ ExecStart=/usr/bin/{{docker_container_name}}.sh wait
1012
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
1113

1214
[Install]
13-
WantedBy=multi-user.target swss.service
15+
WantedBy=sonic.target swss.service

files/build_templates/mgmt-framework.service.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
Description=Management Framework container
33
Requires=database.service
44
After=database.service swss.service syncd.service
5+
BindsTo=sonic.target
6+
After=sonic.target
57
Before=ntp-config.service
68

79
[Service]
810
User={{ sonicadmin_user }}
911
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start
1012
ExecStart=/usr/bin/{{docker_container_name}}.sh wait
1113
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
12-
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
[Unit]
22
Description=Delays management framework container until SONiC has started
3+
PartOf=mgmt-framework.service
34

45
[Timer]
6+
OnUnitActiveSec=0 sec
57
OnBootSec=3min 30 sec
68
Unit=mgmt-framework.service
79

810
[Install]
9-
WantedBy=timers.target
11+
WantedBy=timers.target sonic.target

files/build_templates/nat.service.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Description=NAT container
33
Requires=updategraph.service
44
After=updategraph.service swss.service syncd.service
5+
BindsTo=sonic.target
6+
After=sonic.target
57
Before=ntp-config.service
68
StartLimitIntervalSec=1200
79
StartLimitBurst=3
@@ -15,5 +17,5 @@ Restart=always
1517
RestartSec=30
1618

1719
[Install]
18-
WantedBy=multi-user.target
20+
WantedBy=sonic.target
1921

files/build_templates/per_namespace/bgp.service.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Requires=database{% if multi_instance == 'true' %}@%i{% endif %}.service
44
After=database{% if multi_instance == 'true' %}@%i{% endif %}.service
55
Requires=updategraph.service
66
After=updategraph.service
7+
BindsTo=sonic.target
8+
After=sonic.target
79
Before=ntp-config.service
810
StartLimitIntervalSec=1200
911
StartLimitBurst=3
@@ -18,4 +20,4 @@ Restart=always
1820
RestartSec=30
1921

2022
[Install]
21-
WantedBy=multi-user.target
23+
WantedBy=sonic.target

files/build_templates/per_namespace/lldp.service.j2

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ After=swss{% if multi_instance == 'true' %}@%i{% endif %}.service
66
After=syncd{% if multi_instance == 'true' %}@%i{% endif %}.service
77
Requires=updategraph.service
88
After=updategraph.service
9+
BindsTo=sonic.target
10+
After=sonic.target
11+
BindsTo=sonic.target
12+
After=sonic.target
913
Before=ntp-config.service
1014
StartLimitIntervalSec=1200
1115
StartLimitBurst=3
@@ -19,4 +23,4 @@ Restart=always
1923
RestartSec=30
2024

2125
[Install]
22-
WantedBy=multi-user.target
26+
WantedBy=sonic.target

files/build_templates/per_namespace/swss.service.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Requires=opennsl-modules.service
1212
Requires=updategraph.service
1313
After=updategraph.service
1414
After=interfaces-config.service
15+
BindsTo=sonic.target
16+
After=sonic.target
1517
Before=ntp-config.service pmon.service
1618
StartLimitIntervalSec=1200
1719
StartLimitBurst=3
@@ -26,4 +28,4 @@ Restart=always
2628
RestartSec=30
2729

2830
[Install]
29-
WantedBy=multi-user.target
31+
WantedBy=sonic.target

files/build_templates/per_namespace/syncd.service.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ After=nps-modules.service
1717
Requires=updategraph.service
1818
After=updategraph.service
1919
After=interfaces-config.service
20+
BindsTo=sonic.target
21+
After=sonic.target
2022
Before=ntp-config.service
2123

2224
[Service]
@@ -30,4 +32,4 @@ TimeoutStartSec=480
3032
{% endif %}
3133

3234
[Install]
33-
WantedBy=multi-user.target
35+
WantedBy=sonic.target

files/build_templates/per_namespace/teamd.service.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ After=topology.service
77
{% endif %}
88
Requires=updategraph.service
99
After=updategraph.service
10+
BindsTo=sonic.target
11+
After=sonic.target
1012
Before=ntp-config.service
1113
StartLimitIntervalSec=1200
1214
StartLimitBurst=3
@@ -20,4 +22,4 @@ Restart=always
2022
RestartSec=30
2123

2224
[Install]
23-
WantedBy=multi-user.target
25+
WantedBy=sonic.target

files/build_templates/pmon.service.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ After=database.service updategraph.service
55
{% if sonic_asic_platform == 'mellanox' %}
66
After=syncd.service
77
{% endif %}
8+
BindsTo=sonic.target
9+
After=sonic.target
810
Before=ntp-config.service
911
StartLimitIntervalSec=1200
1012
StartLimitBurst=3
@@ -18,4 +20,4 @@ Restart=always
1820
RestartSec=30
1921

2022
[Install]
21-
WantedBy=multi-user.target
23+
WantedBy=sonic.target

files/build_templates/radv.service.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Description=Router advertiser container
33
Requires=updategraph.service
44
After=updategraph.service swss.service syncd.service
55
Before=ntp-config.service
6+
BindsTo=sonic.target
7+
After=sonic.target
68
StartLimitIntervalSec=1200
79
StartLimitBurst=3
810

@@ -15,4 +17,4 @@ Restart=always
1517
RestartSec=30
1618

1719
[Install]
18-
WantedBy=multi-user.target
20+
WantedBy=sonic.target

files/build_templates/restapi.service.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Description=RestAPI container
33
Requires=updategraph.service
44
After=updategraph.service
5+
BindsTo=sonic.target
6+
After=sonic.target
57
Before=ntp-config.service
68

79
[Service]
@@ -13,4 +15,4 @@ Restart=always
1315
RestartSec=30
1416

1517
[Install]
16-
WantedBy=multi-user.target
18+
WantedBy=sonic.target

files/build_templates/sflow.service.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Description=sFlow container
33
Requisite=swss.service
44
After=swss.service syncd.service hostcfgd.service
5+
BindsTo=sonic.target
6+
After=sonic.target
57
Before=ntp-config.service
68
StartLimitIntervalSec=1200
79
StartLimitBurst=3
@@ -15,4 +17,4 @@ Restart=always
1517
RestartSec=30
1618

1719
[Install]
18-
WantedBy=multi-user.target
20+
WantedBy=sonic.target

files/build_templates/snmp.service.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ Description=SNMP container
33
Requires=updategraph.service
44
Requisite=swss.service
55
After=updategraph.service swss.service syncd.service
6+
BindsTo=sonic.target
7+
After=sonic.target
68
Before=ntp-config.service
7-
Conflicts=snmp.timer
89
StartLimitIntervalSec=1200
910
StartLimitBurst=3
1011

@@ -14,4 +15,3 @@ ExecStart=/usr/bin/{{docker_container_name}}.sh wait
1415
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
1516
Restart=always
1617
RestartSec=30
17-

files/build_templates/snmp.timer

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[Unit]
22
Description=Delays snmp container until SONiC has started
3-
Conflicts=snmp.service
3+
PartOf=snmp.service
44
After=swss.service
55

66
[Timer]

files/build_templates/sonic.target

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[Unit]
2+
Description=SONiC services target.
3+
4+
[Install]
5+
WantedBy=multi-user.target

files/build_templates/sonic_debian_extension.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,9 @@ sudo cp $BUILD_TEMPLATES/mgmt-framework.timer $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_S
682682
echo "mgmt-framework.timer" | sudo tee -a $GENERATED_SERVICE_FILE
683683
{% endif %}
684684

685+
sudo cp $BUILD_TEMPLATES/sonic.target $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
686+
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable sonic.target
687+
685688
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get purge -y python-dev python3-dev
686689
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get purge -y build-essential libssl-dev swig
687690
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

files/build_templates/telemetry.service.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Description=Telemetry container
33
Requires=database.service
44
After=database.service swss.service syncd.service
55
Before=ntp-config.service
6+
BindsTo=sonic.target
7+
After=sonic.target
68
StartLimitIntervalSec=1200
79
StartLimitBurst=3
810

@@ -13,4 +15,3 @@ ExecStart=/usr/bin/{{docker_container_name}}.sh wait
1315
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
1416
Restart=always
1517
RestartSec=30
16-

files/build_templates/telemetry.timer

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
[Unit]
22
Description=Delays telemetry container until SONiC has started
3+
PartOf=telemetry.service
34

45
[Timer]
6+
OnUnitActiveSec=0 sec
57
OnBootSec=3min 30 sec
68
Unit=telemetry.service
79

810
[Install]
9-
WantedBy=timers.target
11+
WantedBy=timers.target sonic.target

files/image_config/hostname/hostname-config.service

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
Description=Update hostname based on configdb
33
Requires=updategraph.service
44
After=updategraph.service
5+
BindsTo=sonic.target
6+
After=sonic.target
57

68
[Service]
79
Type=oneshot
10+
RemainAfterExit=yes
811
ExecStart=/usr/bin/hostname-config.sh
912

1013
[Install]
11-
WantedBy=multi-user.target
14+
WantedBy=sonic.target

files/image_config/interfaces/interfaces-config.service

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
Description=Update interfaces configuration
33
Requires=updategraph.service
44
After=updategraph.service
5+
BindsTo=sonic.target
6+
After=sonic.target
57

68
[Service]
79
Type=oneshot
10+
RemainAfterExit=yes
811
ExecStart=/usr/bin/interfaces-config.sh
912

1013
[Install]
11-
WantedBy=multi-user.target
14+
WantedBy=sonic.target

files/image_config/ntp/ntp-config.service

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
Description=Update NTP configuration
33
Requires=updategraph.service
44
After=updategraph.service
5+
BindsTo=sonic.target
6+
After=sonic.target
57
Before=ntp.service
68
StartLimitIntervalSec=0
79

810
[Service]
911
Type=oneshot
12+
RemainAfterExit=yes
1013
ExecStart=/usr/bin/ntp-config.sh
1114

1215
[Install]
13-
WantedBy=multi-user.target
16+
WantedBy=sonic.target

files/image_config/ntp/ntp.service

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Description=Network Time Service
33
Documentation=man:ntpd(8)
44
After=network.target
55
Conflicts=systemd-timesyncd.service
6+
BindsTo=sonic.target
7+
After=sonic.target
68
StartLimitIntervalSec=0
79

810
[Service]

files/image_config/rsyslog/rsyslog-config.service

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
Description=Update rsyslog configuration
33
Requires=updategraph.service
44
After=updategraph.service
5+
BindsTo=sonic.target
6+
After=sonic.target
57

68
[Service]
79
Type=oneshot
10+
RemainAfterExit=yes
811
ExecStart=/usr/bin/rsyslog-config.sh
912

1013
[Install]
11-
WantedBy=multi-user.target
14+
WantedBy=sonic.target

src/sonic-host-services-data/debian/sonic-host-services-data.caclmgrd.service

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Description=Control Plane ACL configuration daemon
33
Requires=updategraph.service
44
After=updategraph.service
5+
BindsTo=sonic.target
6+
After=sonic.target
57

68
[Service]
79
Type=simple
@@ -10,4 +12,4 @@ Restart=always
1012
RestartSec=30
1113

1214
[Install]
13-
WantedBy=multi-user.target
15+
WantedBy=sonic.target

src/sonic-host-services-data/debian/sonic-host-services-data.hostcfgd.service

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
Description=Host config enforcer daemon
33
Requires=updategraph.service
44
After=updategraph.service
5+
BindsTo=sonic.target
6+
After=sonic.target
57

68
[Service]
79
Type=simple
810
ExecStart=/usr/local/bin/hostcfgd
911

1012
[Install]
11-
WantedBy=multi-user.target
13+
WantedBy=sonic.target
14+

0 commit comments

Comments
 (0)