You are not logged in.
I need a service/timer combo that will run every 6 hours and again at a system reboot or shutdown. I didn't see this exact setup within the systemd.timer and systemd.service man pages, nor from googling. I have an existing service and timer.
Can I accomplish this with a single timer and a single service? If so, how? Changing the service to include an ExecStop= directive doesn't seem right. I tried adding the reboot.target to the WantedBy= directive but that did not work. Thanks for pointers.
Last edited by graysky (2020-04-06 11:54:28)
Offline
Hi!
You could use OnBootSec for the first start after boot and your OnUnitActiveSec for the 6h-rule like this
…
[Timer]
OnBootSec=2min # delay after boot
OnUnitActiveSec=6h # every 6h after first activation
Unit=/what/ever/should/run
…Offline
Yes, but that doesn't cover the on reboot. I'm thinking it's the service that needs to handle this rather than the timer.
Offline
It should start 2 minutes after reboot. A full working example I'm currently using looks like this:
[Unit]
Description=Share battery state with home-server
[Timer]
OnBootSec=120
OnUnitActiveSec=120
Unit=BatteryWatcher.service
[Install]
WantedBy=timers.targetThe service-unit itself has only a description and an ExecStart-line.
Offline
If you don't have an ExecStart line;
RemainAfterExit=true
ExecStop=/usr/bin/modprobed-db storesilentif you have (I saw you have..)
ExecStop=/usr/bin/modprobed-db storesilentor add to your reboot script/alias
/usr/bin/modprobed-db storesilent && systemctl rebootOffline
Thanks for the replies, all. Incorporating these suggestions seems to work as expected, although the journalctl seem to be getting spammed with extra messages now:
% journalctl --user -u modprobed-db
Apr 06 07:37:57 ankh systemd[826]: Finished Modprobed-db.
Apr 06 07:39:48 ankh systemd[826]: Stopping Modprobed-db...
Apr 06 07:39:48 ankh modprobed-db[896]: No new modules detected
Apr 06 07:39:48 ankh systemd[826]: modprobed-db.service: Succeeded.
Apr 06 07:39:48 ankh systemd[826]: Stopped Modprobed-db.
Apr 06 08:03:21 ankh systemd[994]: Finished Modprobed-db.
<< set reboot here >>
Apr 06 08:13:26 ankh systemd[994]: Stopping Modprobed-db...
Apr 06 08:13:26 ankh modprobed-db[1123]: No new modules detected
Apr 06 08:13:26 ankh systemd[994]: modprobed-db.service: Succeeded.
Apr 06 08:13:26 ankh systemd[994]: Stopped Modprobed-db.
-- Reboot --
Apr 06 08:15:11 ankh systemd[842]: Finished Modprobed-db.Last edited by graysky (2020-04-06 12:35:36)
Offline
Yes, it's default these messages are 'spammed' to your journal..
There is a way to push these messages to a different log file if you wish;
Something like:
StandardInput=journal
StandardOutput=file:/path/to/log
StandardError=syslog (edit)
SyslogIdentifier=/usr/bin/modprobed-db storesilentThis may not enough to make it working but in the right direction anyway,
(see) https://www.freedesktop.org/software/sy … put/Output
&
https://www.freedesktop.org/software/sy … put/Output
edit: forget the above code mostly, unless you want to use syslog, this should be enough to put in your timer;
StandardError=file:/path/to/modprobed.log
StandardOutput=file:/path/to/modprobed.logI never used this approach and I'm not going to, but it is working...
Usually I grep what I like to see and never scroll trough the entire journal..
Last edited by qinohe (2020-04-06 19:33:57)
Offline