Gentoo Archives: gentoo-user

From: "Canek Peláez Valdés" <caneko@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] systemd boot timer
Date: Fri, 01 Oct 2021 21:54:27
Message-Id: CADPrc81oppoY9R-smcAvX742pfDUGN7rYfOcojYMsmuk8rM3jw@mail.gmail.com
In Reply to: [gentoo-user] systemd boot timer by antlists
1 On Fri, Oct 1, 2021 at 3:37 PM antlists <antlists@××××××××××××.uk> wrote:
2
3 > I'm trying to get a systemd unit to fire on boot once a week. Reading up
4 > on timer units, I can't work out how to get it to work.
5 >
6 > This is tied up with my earlier systemd mount post - I've now got that
7 > sorted - I've got dm-integrity to fire before fstab.
8 >
9 > I now want to run lvm snapshot on the first boot of the weekend. Writing
10 > a unit to do the snapshot seems pretty easy, but obviously I don't want
11 > it firing every boot, if I stick the date in the volume name I don't
12 > want it colliding with an earlier run the same day, etc etc.
13 >
14 > The question really is - if I have a weekly timer fire and activate the
15 > unit, is the activation going to survive the reboot to run on the next
16 > boot?
17 >
18 > The problem I'm having is that all the stuff I've seen about timers says
19 > you have two lines - activate on Saturdays, and activate on boot. Snag
20 > is, they seem to be independent such that EITHER condition will activate
21 > the service. As I say, I want BOTH. I don't want the service running
22 > while the system is up and running.
23 >
24
25 I'm not sure timer units have enough flexibility to do what you want.
26
27 I think it would be much simpler to have a Type=oneshot service at boot,
28 and the Exec= line to call a script. You can store the timestamp of the
29 last time it was called someplace in the filesystem (say,
30 /var/lib/my-script or something), and if the timestamp doesn't exists or is
31 older than one week, the scripts executes lvm snapshot and updates the
32 timestamp; otherwise it ends without doing anything.
33
34 The timer units are very similar to cron, and I believe what you want
35 cannot be done with cron either; you need special logic and state ("I'm
36 booting AND haven't run this in at least a week"), so a script is necessary
37 (I think). Luckly, systemd allows you to smartly manage your scripts and
38 impose dependencies on them (you need /var in my example, and you can set
39 it to run before starting X).
40
41 Regards.
42 --
43 Dr. Canek Peláez Valdés
44 Profesor de Carrera Asociado C
45 Departamento de Matemáticas
46 Facultad de Ciencias
47 Universidad Nacional Autónoma de México

Replies

Subject Author
Re: [gentoo-user] systemd boot timer antlists <antlists@××××××××××××.uk>