1 |
Am Wed, 25 Feb 2015 07:01:59 -0500 |
2 |
schrieb Rich Freeman <rich0@g.o>: |
3 |
|
4 |
> On Wed, Feb 25, 2015 at 2:50 AM, Marc Joliet <marcec@×××.de> wrote: |
5 |
> > Am Tue, 24 Feb 2015 16:44:59 -0500 |
6 |
> > schrieb Rich Freeman <rich0@g.o>: |
7 |
> > |
8 |
> >> > === Timers === |
9 |
> >> > |
10 |
> >> > Can a systemd timer depend on a mount point such that it waits until the mount |
11 |
> >> > point exists before running? Or will it fail after a timeout? I want to |
12 |
> >> > research this myself, but haven't gotten around to it yet. |
13 |
> >> |
14 |
> >> So, timer units are units, and units can have dependencies, and mounts |
15 |
> >> can be dependencies since mounts are units. However, if you set the |
16 |
> >> dependency on the timer itself, then the timer won't start running |
17 |
> >> until the mount exists. You probably want the depencency to be on the |
18 |
> >> service started by the timer (so the timer is watching the clock, but |
19 |
> >> the service won't start without the mount). |
20 |
> > |
21 |
> > Wait, so the timer won't start watching the clock until its dependencies are |
22 |
> > met (i.e, the mount point appears)? Is that what you mean? Because that might |
23 |
> > be more in line with what I want (though I'm not sure yet). |
24 |
> |
25 |
> If you set the dependency on the timer, then the timer doesn't start |
26 |
> watching the clock until they're met. If you set the dependency on |
27 |
> the service started by the timer then it will watch the clock but not |
28 |
> launch the service if the dependency isn't met. You can set the |
29 |
> dependency in either or both places. The timer and the service are |
30 |
> both units. |
31 |
|
32 |
OK, I think I got it. |
33 |
|
34 |
> > |
35 |
> >> If you set a |
36 |
> >> Requires=foo.mount and After=foo.mount, then the service shouldn't run |
37 |
> >> unless foo.mount is available. I suspect systemd will attempt to |
38 |
> >> mount the filesystem when it runs the service, and you'll get units in |
39 |
> >> the failed state if that doesn't work. |
40 |
> >> |
41 |
> >> However, I haven't tested any of this. I suspect it wouldn't take |
42 |
> >> much to work this out. I have a mount dependency in one of my |
43 |
> >> services. Just look at the mount units in /run/systemd/generator for |
44 |
> >> the name of the mount unit systemd is creating from fstab. |
45 |
> > |
46 |
> > Right, so IIUC, I would have a oneshot service that does the backup, and the timer |
47 |
> > runs that, and of course the timer can depend on the mount point. And if the |
48 |
> > mount point doesn't exist, then the service started by the timer will fail. |
49 |
> > |
50 |
> > What I would prefer to have is a timer that only runs if *both* the time *and* |
51 |
> > mount conditions are met. Skimming the man page, this does not seem possible. |
52 |
> > I suppose it would be nice if timers learned "conditions" on which they should |
53 |
> > wait in addition to the time condition, but maybe that's outside the scope of |
54 |
> > systemd? |
55 |
> |
56 |
> I think if you just set the dependency on the service you'll get the |
57 |
> behavior you desire. Systemd will try to mount the backup filesystem, |
58 |
> and if that fails it won't run the backup. |
59 |
> |
60 |
> You can set conditions on units as well, like only running if they're |
61 |
> on AC power or on amd64 or to run one unit the first time you start a |
62 |
> service and a different unit every other time. Some of that was |
63 |
> designed to implement some of the stateless system features they're |
64 |
> adding to systemd. |
65 |
|
66 |
Right, I'll have a look at them. |
67 |
|
68 |
Thanks |
69 |
-- |
70 |
Marc Joliet |
71 |
-- |
72 |
"People who think they know everything really annoy those of us who know we |
73 |
don't" - Bjarne Stroustrup |