<div class="gmail_quote"><div dir="ltr">On Tue, Mar 20, 2018, 21:09 Colin Walters <<a href="mailto:walters@verbum.org">walters@verbum.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm working on: <a href="https://github.com/ostreedev/ostree/issues/545" rel="noreferrer" target="_blank">https://github.com/ostreedev/ostree/issues/545</a><br>
TL;DR:<br>
libostree is an image-like update system, and I want to take some<br>
actions at system shutdown time, specifically performing a "snapshot+merge"<br>
of /etc after most other services are shut down. The way ostree<br>
handles /etc (IMO a lot more correctly) is a major distinguishing point from a lot<br>
of other image-like systems out there.<br>
<br>
What I have so far is this (distilled into a simple easily tested unit not tied to ostree):<br>
<br>
[Unit]<br>
Description=cgwalters-shutdown<br>
DefaultDependencies=no<br>
After=shutdown.target<br>
Before=final.target<br>
# FIXME<br>
# Before=sysroot.mount<br>
[Service]<br>
Type=oneshot<br>
RemainAfterExit=yes<br>
ExecStart=/bin/sh -c 'sleep 5 && ls -ald /sysroot/ostree/repo'<br>
[Install]<br>
WantedBy=final.target<br>
<br>
I modeled this after `halt-local.service`. But as you<br>
might infer from the FIXME, the problem I'm hitting is that the /sysroot<br>
mount is unmounted before this service is started. I think the problem<br>
I'm hitting is this bit from `man systemd.unit`:<br>
<br>
> Given two units with any ordering dependency between them, if one unit is shut down and the other is started up, the shutdown is ordered before the start-up.<br>
<br>
Which does sort of make sense to me in general; but is problematic for<br>
this "start service on shutdown" case. I was looking a bit at the way plymouth<br>
hooks into shutdown, but it seemed complex, and as plymouth doesn't (AFAIK)<br>
have any real dependencies on the filesystem state I'm not sure it matches what I need.<br>
<br>
I can think of ways to hack around this, by e.g. having the service start up on<br>
shutdown, take a snapshot of a private mount namespace, have it be excluded<br>
from the Conflicts=shutdown.target, then have a unit that triggers before final.target<br>
(like the above) that sends an IPC to actually do what I want. But that adds a notable<br>
amount of complexity, and I'd like to have this process feel as obvious/transparent as possible.<br>
<br>
Another way I've thought about handling this is to basically invert things so that<br>
we have a "stub" unit that starts on bootup, and its ExecStop does the real work:<br>
<br>
[Unit]<br>
Description=cgwalters-startstop<br>
ConditionPathExists=/run/ostree-booted<br>
DefaultDependencies=no<br>
RequiresMountsFor=/sysroot<br>
After=basic.target<br>
Before=multi-user.target<br>
Conflicts=final.target<br>
Before=final.target<br>
<br>
[Service]<br>
Type=oneshot<br>
RemainAfterExit=yes<br>
ExecStart=/usr/bin/true<br>
ExecStop=/usr/bin/sh -c 'sleep 5 && ls -ald /ostree/repo'<br>
<br>
[Install]<br>
WantedBy=multi-user.target<br>
<br>
Which seems to work but feels...a bit ugly?<br></blockquote></div><div><br></div><div>Currently this is the recommended method; it's a little ugly indeed but fits quite well into the shutdown process. Recent systemd versions should let you skip the dummy ExecStart.</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><p dir="ltr">Mantas Mikulėnas <<a href="mailto:grawity@gmail.com">grawity@gmail.com</a>><br>
Sent from my phone</p>
</div></div>