You are not logged in.

#1 2022-01-03 21:18:30

jfabernathy
Member
From: North Carolina
Registered: 2019-01-03
Posts: 95

[SOLVED] need systemd daily service/timer to not run but once a day

I have a daily service timer pair that work fine if I don't reboot the system. It normally runs at 5:30am.  If I have to reboot the PC several times that afternoon the service runs after each reboot. I need to find a solution. Here are the .service and .timer files:

Timer

 # This timer unit is for database-backup
[Unit]
Description=start mythtv-database-backup
Requires=mythtv-database-backup.service

[Timer]
Unit=mythtv-database-backup.service
OnCalendar=*-*-* 05:30:00
Persistent=true

[Install]
WantedBy=timers.target

Service

 [Unit]
Description=Backup MythTV Database 'mythconverg'
Wants=mythtv-database-backup.timer
Requires=mysql.service
After=mysql.service
After=local-network-pingable.service

[Service]
Type=oneshot
ExecStart=/usr/local/bin/mythtv-database-backup.sh 

[Install]
WantedBy=multi-user.target

Could this because the Service is enabled?  Would the timer only need to be enabled??

Last edited by jfabernathy (2022-01-03 21:50:26)

Offline

#2 2022-01-03 21:22:55

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,382

Re: [SOLVED] need systemd daily service/timer to not run but once a day

jfabernathy wrote:

Could this because the Service is enabled?  Would the timer only need to be enabled??

Correct.
https://wiki.archlinux.org/title/System … rvice_unit


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#3 2022-01-03 21:31:26

jfabernathy
Member
From: North Carolina
Registered: 2019-01-03
Posts: 95

Re: [SOLVED] need systemd daily service/timer to not run but once a day

Slithery wrote:
jfabernathy wrote:

Could this because the Service is enabled?  Would the timer only need to be enabled??

Correct.
https://wiki.archlinux.org/title/System … rvice_unit

I have read that page and I have disabled the service and only enabled the timer.  But when I reboot, the service runs every time. I only want it to run once early in the morning.

Offline

#4 2022-01-03 21:32:19

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 27,093
Website

Re: [SOLVED] need systemd daily service/timer to not run but once a day

More specifically it's due to the symlink created by the combination of 1) being inabled and 2) the service file having an [Install] section.  Why is there even an install section - was this from an AUR package?

EDIT: does the timer status show that it was triggered by the timer, or is something else triggering it at boot up?  EDIT 2: see below.

Last edited by Trilby (2022-01-03 21:33:27)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2022-01-03 21:32:47

Raynman
Member
Registered: 2011-10-22
Posts: 1,442

Re: [SOLVED] need systemd daily service/timer to not run but once a day

The second problem is that your timer Requires the service. The timer is activated on boot by timers.target, which then also activates the service.

Last edited by Raynman (2022-01-03 21:33:22)

Offline

#6 2022-01-03 21:45:25

jfabernathy
Member
From: North Carolina
Registered: 2019-01-03
Posts: 95

Re: [SOLVED] need systemd daily service/timer to not run but once a day

Raynman wrote:

The second problem is that your timer Requires the service. The timer is activated on boot by timers.target, which then also activates the service.

You are right removing the requires from the timer solved it. I also removed the install section from the service.
New files:
Service

# This service unit is for backing up the mythtv database called mythconverg
#
[Unit]
Description=Backup MythTV Database 'mythconverg'
Wants=mythtv-database-backup.timer
Requires=mysql.service
After=mysql.service
After=local-network-pingable.service

[Service]
Type=oneshot
ExecStart=/usr/local/bin/mythtv-database-backup.sh 

Timer

[Unit]
Description=start mythtv-database-backup

[Timer]
Unit=mythtv-database-backup.service
OnCalendar=*-*-* 05:30:00
Persistent=true

[Install]
WantedBy=timers.target

Offline

#7 2022-01-03 21:49:41

jfabernathy
Member
From: North Carolina
Registered: 2019-01-03
Posts: 95

Re: [SOLVED] need systemd daily service/timer to not run but once a day

Thanks for the help. I've rebooted several more times and no triggering of the service.

Offline

#8 2022-01-04 10:58:59

jfabernathy
Member
From: North Carolina
Registered: 2019-01-03
Posts: 95

Re: [SOLVED] need systemd daily service/timer to not run but once a day

All this discussion made me research some more and I wondered why my service had this line in is:

Wants=mythtv-database-backup.timer

The timer is what is triggering the service so at best it's irrelevant. So I removed it and all it still well.

Offline

#9 2022-01-04 11:55:41

schard
Member
From: Hannover
Registered: 2016-05-06
Posts: 1,418
Website

Re: [SOLVED] need systemd daily service/timer to not run but once a day

On a side-note: Since your timer is configured as "persistent", it will also start the corresponding service, if you e.g. boot your machine after 05:30:00. Just be aware of that.


Солідарність з Україною

Offline

#10 2022-01-04 12:17:09

jfabernathy
Member
From: North Carolina
Registered: 2019-01-03
Posts: 95

Re: [SOLVED] need systemd daily service/timer to not run but once a day

schard wrote:

On a side-note: Since your timer is configured as "persistent", it will also start the corresponding service, if you e.g. boot your machine after 05:30:00. Just be aware of that.

since this server is on 24/7, it's only the reboot that concerns me

Offline

Board footer

Powered by FluxBB