I've made a systemd service with a timer that should run the script every hour, but it's not running every hour.
% cat /etc/systemd/system/myservice.service
[Unit]
Description=Run script after network established
Requires=network-online.target
After=network-online.target
[Service]
Type=simple
RemainAfterExit=yes
ExecStart="/srv/script"
[Install]
WantedBy=multi-user.target
% cat /etc/systemd/system/myservice.timer
[Unit]
Description=Run script every hour
[Timer]
OnBootSec=15min
OnUnitActiveSec=1h
[Install]
WantedBy=timers.target
It does run the script after the network is established, but it doesn't continue to run every hour after that.
sudo systemctl status myservice.{service,timer}
...shows that both are active
and enabled
.
How do I make the time file reference the service file?
More info:
% systemctl list-timers --system --all
NEXT LEFT LAST PASSED UNIT ACTIVATES
~~~~~~~~~~~~~~~~
Sun 2023-09-24 03:10:54 BST 3 days left Sun 2023-09-17 03:10:50 BST 3 days ago e2scrub_all.timer e2scrub_all.service
- - - - fstrim.timer fstrim.service
- - Wed 2023-09-20 17:28:10 BST 2h 27min ago myservice.timer myservice.service
systemctl list-timers --system --all
return?systemctl cat fstrim.{service,timer}
. For the service, remove the[install]
section; for the timer, addPersistent=True
under the[Timer]
section. Then reload withsystemctl daemon-reload
.[Install]
section doesn't seem to make any improvement but addingPersistent=True
makes the timer run after one hour once, and then nothing after that.RemainAfterExit=yes
entry is the culprit.