Skip to content

Commit b834c9f

Browse files
stepanblyschakabdosi
authored andcommitted
[services] make snmp.timer work again and delay telemetry.service (#3742)
Delay CPU intensive services at boot - How I did it Made snmp.timer work and add telemetry.timer. But this is not enough because it breaks the existing snmp dependency on swss. So, in this solution snmp timer is a wanted by swss service, but since OnBootSec timer expires only once it will not trigger snmp service, so I added line "OnUnitActiveSec=0 sec" which will start snmp service based on the last time it was active. On boot only OnBootSec will expire, on swss start/restarts only second timer will expire immediately and trigger snmp service. However, snmp service will not stop after "systemctl stop snmp" because of the second timer which will always expire when snmp service because unavailable. So there is a conflict which will be handled by systemd if we add "Conflicts=" line to both snmp.service and snmp.timer. So during boot: snmp does not start by default swss starts and starts snmp timer OnUnitActiveSec=0 does not expire since there is no snmp active OnBootSec expires and starts snmp service and snmp timer gets stopped During "systemctl restart swss" snmp stops because of Requisite on swss snmp unblocks snmp timer from running swss starts and starts snmp timer OnUnitActiveSec=0 expires imidiately and start snmp which stops snmp timer During "systemctl stop snmp" stop of snmp service unblocks snmp timer but no one starts the timer so it is not started by "OnUnitActiveSec=0"
1 parent 74b45be commit b834c9f

File tree

6 files changed

+20
-7
lines changed

6 files changed

+20
-7
lines changed

files/build_templates/snmp.service.j2

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Requires=updategraph.service
44
Requisite=swss.service
55
After=updategraph.service swss.service syncd.service
66
Before=ntp-config.service
7+
Conflicts=snmp.timer
78
StartLimitIntervalSec=1200
89
StartLimitBurst=3
910

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

17-
[Install]
18-
WantedBy=multi-user.target swss.service

files/build_templates/snmp.timer

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
[Unit]
22
Description=Delays snmp container until SONiC has started
3+
Conflicts=snmp.service
34

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

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

files/build_templates/sonic_debian_extension.j2

+6-2
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ EOF
341341
## Bind docker path
342342
if [[ $CONFIGURED_ARCH == armhf || $CONFIGURED_ARCH == arm64 ]]; then
343343
sudo mkdir -p $FILESYSTEM_ROOT/dockerfs
344-
sudo mount --bind dockerfs $FILESYSTEM_ROOT/dockerfs
344+
sudo mount --bind dockerfs $FILESYSTEM_ROOT/dockerfs
345345
fi
346346

347347
{% if installer_images.strip() -%}
@@ -358,7 +358,7 @@ sudo LANG=C chroot $FILESYSTEM_ROOT docker $SONIC_NATIVE_DOCKERD_FOR_DOCKERFS ta
358358
{% endif %}
359359
{% endfor %}
360360
if [[ $CONFIGURED_ARCH == armhf || $CONFIGURED_ARCH == arm64 ]]; then
361-
sudo umount $FILESYSTEM_ROOT/dockerfs
361+
sudo umount $FILESYSTEM_ROOT/dockerfs
362362
sudo rm -fr $FILESYSTEM_ROOT/dockerfs
363363
sudo kill -9 `sudo $SONIC_NATIVE_DOCKERD_FOR_DOCKERFS_PID` || true
364364
else
@@ -386,6 +386,10 @@ sudo LANG=C cp $SCRIPTS_DIR/syncd.sh $FILESYSTEM_ROOT/usr/local/bin/syncd.sh
386386
# It implements delayed start of services
387387
sudo cp $BUILD_TEMPLATES/snmp.timer $FILESYSTEM_ROOT/etc/systemd/system/
388388
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable snmp.timer
389+
{% if enable_system_telemetry == 'y' %}
390+
sudo cp $BUILD_TEMPLATES/telemetry.timer $FILESYSTEM_ROOT/etc/systemd/system/
391+
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable telemetry.timer
392+
{% endif %}
389393

390394
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get purge -y python-dev
391395
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get clean -y

files/build_templates/telemetry.service.j2

-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,3 @@ ExecStop=/usr/bin/{{docker_container_name}}.sh stop
1414
Restart=always
1515
RestartSec=30
1616

17-
[Install]
18-
WantedBy=multi-user.target

files/build_templates/telemetry.timer

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
Description=Delays telemetry container until SONiC has started
3+
4+
[Timer]
5+
OnBootSec=3min 30 sec
6+
Unit=telemetry.service
7+
8+
[Install]
9+
WantedBy=timers.target

slave.mk

+1
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
639639
export sonic_asic_platform="$(patsubst %-$(CONFIGURED_ARCH),%,$(CONFIGURED_PLATFORM))"
640640
export enable_organization_extensions="$(ENABLE_ORGANIZATION_EXTENSIONS)"
641641
export enable_dhcp_graph_service="$(ENABLE_DHCP_GRAPH_SERVICE)"
642+
export enable_system_telemetry="$(ENABLE_SYSTEM_TELEMETRY)"
642643
export shutdown_bgp_on_start="$(SHUTDOWN_BGP_ON_START)"
643644
export enable_pfcwd_on_start="$(ENABLE_PFCWD_ON_START)"
644645
export installer_debs="$(addprefix $(STRETCH_DEBS_PATH)/,$($*_INSTALLS))"

0 commit comments

Comments
 (0)