You are not logged in.

#1 2024-07-04 11:28:55

fira959
Member
Registered: 2024-07-04
Posts: 1

Systemd timer - trigger after running for X hours

Hi,

I am trying to create a systemd timer that runs its associated service every 10 hours of system activity. Downtime should be ignored and the timer should be persistent over reboots.

Example:
The system runs 3 hours on Monday, 6 hours on Tuesday and 12 hours on Wednesday
The timer should trigger on Wednesday after running for 1 hour and then again on the same day after the next 10 hours of active runtime has passed

The problem I have is that there is no persistent setting other then for OnCalendar timers.

I am currently using this:

[Unit]
Description=Execute test service
Requires=mytest.service

[Timer]
OnUnitActiveSec=10h

[Install]
WantedBy=timers.target

But this timer actually resets at every boot and starts every day.
How do I keep a persistent timer that actually depends on the time the unit was active and persists over reboots?

Offline

#2 2024-07-10 14:44:28

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,304

Re: Systemd timer - trigger after running for X hours

Hello for your first post.
You can keep the active time in a file running the uptime command before shutting down.
Then you have to write a script to use this to obtain what you want.
It can be a good exercise, when something doesn't exist do it yourself !

Offline

Board footer

Powered by FluxBB