3

After trying the solutions posted here (Prevent systemd timer from running on startup), I thought I had my systemd timer problems corrected. However, after my last reboot, my service fired off during boot (evidently making up for a missed event).

Here are the files in question:

btrfs_backup.timer

[Unit]
Description=Create mirror of current state of all BTRFS snapshots
Requires=btrfs_backup.service

[Timer]
# hourly, with a 5-minute delay, as to not interfere with the
# snapper-timeline.service.
Unit=btrfs_backup.service
OnCalendar=*-*-* *:05:00
Persistent=false

[Install]
WantedBy=timers.target

btrfs_backup.service

[Unit]
Description=Create mirror of current state of all BTRFS snapshots
Wants=btrfs_backup.timer

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/btrfs_backup
Environment="DISPLAY=:0.0"
Environment="XDG_RUNTIME_DIR=/run/user/0"

I basically copied these (2) files from snapper's timeline systemd files, so I don't understand why this setup is not working. I even looked into the suggestion of removing the [Install] section from the timer, but every timer on my system (including the snapper one) have an [Install] section.

Everything else works great - service completes correctly, notifications are seen on the desktop.

UPDATE #1: journal entries for the last couple of hours that surround the problem event:

Mar 01 14:05:09 dss-mint systemd[1]: Starting Create mirror of current state of all BTRFS snapshots...
Mar 01 14:05:09 dss-mint systemd[1]: btrfs_backup.service: Succeeded.
Mar 01 14:05:09 dss-mint systemd[1]: Finished Create mirror of current state of all BTRFS snapshots.
Mar 01 15:05:09 dss-mint systemd[1]: Starting Create mirror of current state of all BTRFS snapshots...
Mar 01 15:05:09 dss-mint systemd[1]: btrfs_backup.service: Succeeded.
Mar 01 15:05:09 dss-mint systemd[1]: Finished Create mirror of current state of all BTRFS snapshots.
Mar 01 16:05:09 dss-mint systemd[1]: Starting Create mirror of current state of all BTRFS snapshots...
Mar 01 16:05:09 dss-mint systemd[1]: btrfs_backup.service: Succeeded.
Mar 01 16:05:09 dss-mint systemd[1]: Finished Create mirror of current state of all BTRFS snapshots.
-- Reboot --
Mar 01 17:24:01 dss-mint systemd[1]: Starting Create mirror of current state of all BTRFS snapshots...
Mar 01 17:24:01 dss-mint systemd[1]: btrfs_backup.service: Succeeded.
Mar 01 17:24:01 dss-mint systemd[1]: Finished Create mirror of current state of all BTRFS snapshots.
Mar 01 18:05:19 dss-mint systemd[1]: Starting Create mirror of current state of all BTRFS snapshots...
Mar 01 18:05:19 dss-mint systemd[1]: btrfs_backup.service: Succeeded.
Mar 01 18:05:19 dss-mint systemd[1]: Finished Create mirror of current state of all BTRFS snapshots.

UPDATE #2: OK, powered on the PC this morning. While the service ran soon after the boot was complete, the timer was not triggered:

$ ls-timers
NEXT                        LEFT          LAST                        PASSED       UNIT                         ACTIVATES                     
Tue 2021-03-02 08:43:16 PST 12min left    n/a                         n/a          systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
Tue 2021-03-02 09:00:00 PST 29min left    n/a                         n/a          snapper-timeline.timer       snapper-timeline.service      
Tue 2021-03-02 09:01:57 PST 31min left    n/a                         n/a          btrfs_backup.timer           btrfs_backup.service          
Tue 2021-03-02 11:17:38 PST 2h 46min left Mon 2021-03-01 19:30:22 PST 13h ago      fwupd-refresh.timer          fwupd-refresh.service         
Tue 2021-03-02 16:53:23 PST 8h left       Mon 2021-03-01 12:52:17 PST 19h ago      motd-news.timer              motd-news.service             
Wed 2021-03-03 00:00:00 PST 15h left      Tue 2021-03-02 08:28:52 PST 1min 53s ago logrotate.timer              logrotate.service             
Wed 2021-03-03 00:00:00 PST 15h left      Tue 2021-03-02 08:28:52 PST 1min 53s ago man-db.timer                 man-db.service                
Sun 2021-03-07 03:10:21 PST 4 days left   Sun 2021-02-28 08:27:47 PST 2 days ago   e2scrub_all.timer            e2scrub_all.service           
Mon 2021-03-08 00:00:00 PST 5 days left   Mon 2021-03-01 08:33:26 PST 23h ago      fstrim.timer                 fstrim.service                
n/a                         n/a           Tue 2021-03-02 08:30:06 PST 39s ago      anacron.timer                anacron.service               
n/a                         n/a           Tue 2021-03-02 08:28:52 PST 1min 53s ago snapper-boot.timer           snapper-boot.service

I don't understand this - I've never enabled the service so that it would only be triggered by the timer:

$ systemctl status btrfs_backup.service
● btrfs_backup.service - Create mirror of current state of all BTRFS snapshots
     Loaded: loaded (/etc/systemd/system/btrfs_backup.service; static; vendor preset: enabled)
     Active: inactive (dead) since Tue 2021-03-02 08:35:24 PST; 1min 8s ago
TriggeredBy: ● btrfs_backup.timer
    Process: 1206 ExecStart=/usr/local/sbin/btrfs_backup (code=exited, status=0/SUCCESS)
   Main PID: 1206 (code=exited, status=0/SUCCESS)
6
  • Was the boot at 5 after the hour? Have you tried using the hourly option rather then specifying the time. Commented Mar 2, 2021 at 2:29
  • No - see my update. Commented Mar 2, 2021 at 2:31
  • I have gone through everything I have and from what I can see your correct it should be working I would try changing it to hourly to see if that helps but otherwise it looks right. Commented Mar 2, 2021 at 2:54
  • I really only need to run it once a day, really doesn't matter when except for (2) conditions: 1) during boot, or 2) during snapper-timeline execution. There must be another way to do this. Commented Mar 2, 2021 at 2:57
  • you could always do it the old school way and setup up a cron job takes basically no system resources to run cron Commented Mar 2, 2021 at 3:19

1 Answer 1

2

Try taking the Requires=btrfs_backup.service out of the timer.

The systemd.unit(5) man page says Requires= will activate the requirements as well.  So activating the Timer will activate the requirement of btrfs_backup.service.

2
  • YES!!! That was the final step! After getting the timer to obey, this got the service to do the same. Commented Mar 3, 2021 at 2:24
  • so glad to hear i could help!
    – gmcc
    Commented Mar 3, 2021 at 3:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .