Score:0

Systemd restart rate limiting

jp flag

I'd like to set up a systemd service so that it restarts quickly at first, but slows down after a short while. The reason is that a service might temporarily fail and come back up quickly for highest availability. But should the issue persist longer, this will generate lots of log entries. In that case the restart interval should be longer to not cause such a load but still come back if the issue resolves at some time.

This is my current service file:

[Unit]
StartLimitIntervalSec=120
StartLimitBurst=4

[Service]
ExecStart=/root/test.sh
Restart=always
RestartSec=10

The test script loops as long as /root/test.run exists, then exits with an error code. I can cause the service to fail by deleting that file.

This is what I observed:

  • Starting the service without the run file, it immediately fails. Then it retries 4 times and then fails forever. It will never try to start again.
  • Starting the service with the run file, it runs at first. After deleting the file, the service fails. Then it restarts as above: 4 times and then never again.

This clearly isn't a rate limiting, it's just a limiting.

What do I have to change to get a rate limiting? After 4 restarts within 120 seconds have failed, the service should still try to start at a lower rate.

Running on latest Raspberry Pi OS, but this should apply to any Linux OS with systemd.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.