I tried to restrict the number of a service (in a container) restart. The OS version is centos-release-7-5, the service file is pretty much as below (removed some parameters for reading convenience). It should be pretty straight forward as some other posts pointed out (Post of Server Fault restart limit 1 , Post of Stack Overflow restart limit 2 ). Yet StartLimitBurst and StartLimitIntervalSec never works for me.
I tested with several ways: (1) I check the service PID, kill the service with "kill -9 ****" several times. The service always gets restarted after 20s! (2) I also tried to mess up the service file, make the container never runs. Still, it doesn't work, the service file just keep restarting.
[Unit] Description=Hello Fluentd After=docker.service Requires=docker.service StartLimitBurst=2 StartLimitIntervalSec=150s [Service] EnvironmentFile=/etc/environment ExecStartPre=-/usr/bin/docker stop "fluentd" ExecStartPre=-/usr/bin/docker rm -f "fluentd" ExecStart=/usr/bin/docker run fluentd ExecStop=/usr/bin/docker stop "fluentd" Restart=always RestartSec=20s SuccessExitStatus=143 [Install] WantedBy=multi-user.target