3

I have a system where a service (nginx for example) is sometimes restarted excessively by 'systemd restart nginx' (as result from other scripts, eg. to apply a new configuration or rotate logs).

Even when restarting a service "manually" this way, systemd fails with restart rate limit. Also it is not useful to restart nginx 10 times in a certain second of course.

So how to limit the services manual restart rate? Is there something like a restart-cooldown that would also apply to manual restart requests? The usual settings all apply to automatic restarting by systemd it seems.

dronus
  • 1,238

2 Answers2

2

You can achieve this with StartLimitIntervalSec and StartLimitBurst.

From the systemd unit man page:

StartLimitIntervalSec=interval, StartLimitBurst=burst

Configure unit start rate limiting. Units which are started more than burst times within an interval time span are not permitted to start any more. Use StartLimitIntervalSec= to configure the checking interval and StartLimitBurst= to configure how many starts per interval are allowed.

interval is a time span with the default unit of seconds, but other units may be specified, see systemd.time(5). Defaults to DefaultStartLimitIntervalSec= in manager configuration file, and may be set to 0 to disable any kind of rate limiting. burst is a number and defaults to DefaultStartLimitBurst= in manager configuration file.

These configuration options are particularly useful in conjunction with the service setting Restart= (see systemd.service(5)); however, they apply to all kinds of starts (including manual), not just those triggered by the Restart= logic.

Note that units which are configured for Restart=, and which reach the start limit are not attempted to be restarted anymore; however, they may still be restarted manually or from a timer or socket at a later point, after the interval has passed. From that point on, the restart logic is activated again. systemctl reset-failed will cause the restart rate counter for a service to be flushed, which is useful if the administrator wants to manually start a unit and the start limit interferes with that. Rate-limiting is enforced after any unit condition checks are executed, and hence unit activations with failing conditions do not count towards the rate limit.

A. Darwin
  • 632
0

What release of operating system are you using? Was nginx package installed using the repository of the Linux distribution or from source code?

Maybe answers to these questions can help determine the possible path needed to fix the issue.

Abhi
  • 1