Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
linux:debian:systemd-command-periodically [2024/12/25 14:08] – removed - external edit (Unknown date) 127.0.0.1linux:debian:systemd-command-periodically [2024/12/25 14:08] (current) – ↷ Page moved from linux:linux-tutorials:systemd-command-periodically to linux:debian:systemd-command-periodically Zyzonix
Line 1: Line 1:
 +===== Run command with systemd periodically =====
 +
 +If you wish to run a command periodically with ''systemd'' create a service with the following content:
 +<code bash>
 +[Unit]
 +Description=Autorun command
 +After=network.target network-online.target
 +
 +[Service]
 +RestartSec=30
 +Restart=always
 +User=<user>
 +ExecStart=/command/to/be/run
 +
 +[Install]
 +WantedBy=multi-user.target
 +</code>
 +
 +Edit ''RestartSec'' for the time (in seconds) between each run.
 +
 +=== Restart service automatically after a pre-defined interval ===
 +Therefore add the following line to the ''system'' section of the service:
 +
 +<code bash>
 +RuntimeMaxSec=180s
 +</code>
 +
 +**It's required that ''Restart=always'' otherwise the service will just be interupted but won't restarted!**
 +Adjust the runtime-interval by changing the ''180s''.