Contents
Why do I need to use systemd timers?
Sometimes you have to face nasty service crashes, e.g. due to memory leaks (yes, logstash, I’m talking about you). Using the systemd timers feature is a handy and idiomatic way to restart systemd services (ofc we could use cron, but that’s not what this is about anyway).
How to restart systemd service after startlimitinterval?
Before systemd-230 it was called just StartLimitInterval: This worked worked for me for a service that runs a script using Type=idle. Note that StartLimitIntervalSec must be greater than RestartSec * StartLimitBurst otherwise the service will be restarted indefinitely.
When to restart service unit in Windows 10?
The restart service unit file looks straightforward: However, I struggled a bit on how to restart the service every 4 hours after activation. I did not want to use the OnCalendar option because that would be akin to using cron and wouldn’t leverage the granularity of systemd timer functions.
How to restart service 3 times at 90 second intervals?
To have a service restart 3 times at 90 second intervals include the following lines in your systemd service file: Before systemd-230 it was called just StartLimitInterval: This worked worked for me for a service that runs a script using Type=idle.
How often should I restart my systemd service?
However, everyone knows by now that systemd can be mystical sometimes and its arcanes are somehow complex to understand. That being said, I want to restart my logstash service 4 times after it’s been started.
Can a timer be set to expire more than once?
Note that timers do not necessarily expire at the precise time configured with this setting, as it is subject to the AccuracySec= setting below. May be specified more than once. Although this post is a little old, I would like to point out that there are several ways to declare it in the same timer:
How is the time stored on a timer?
The timer needs to be told to activate again after its initial activation with the OnUnitActiveSec directive. Eventually, the time when the timer was activated can be stored on disk and that can be done with the Persistent option.
Is there a way to restart systemd services?
Using the systemd timers feature is a handy and idiomatic way to restart systemd services (ofc we could use cron, but that’s not what this is about anyway). However, everyone knows by now that systemd can be mystical sometimes and its arcanes are somehow complex to understand.