<div dir="ltr"><font face="courier new, monospace">Hi</font><div><font face="courier new, monospace"><br></font></div><div style><font face="courier new, monospace">How do I start a service on shutdown that will start and finish before any of the mount points being unmounted?</font></div>
<div style><font face="courier new, monospace"><br></font></div><div style><font face="courier new, monospace">As it is explained here (<a href="http://lists.freedesktop.org/archives/systemd-devel/2012-November/007558.html">http://lists.freedesktop.org/archives/systemd-devel/2012-November/007558.html</a>) the shutdown order is the reverse of startup order though it is not clear what is happening when a service that is not in the startup sequence is being started. Following is a sample unit file I have been working on.</font></div>
<div style><font face="courier new, monospace"><br></font></div><div style><font face="courier new, monospace">[Unit]</font></div><div style><font face="courier new, monospace">Description=Taking Long Time</font></div><div style>
<font face="courier new, monospace">DefaultDependencies=no</font></div><div style><font face="courier new, monospace">Before=shutdown.target</font></div><div style><font face="courier new, monospace"><br></font></div><div style>
<font face="courier new, monospace">[Service]</font></div><div style><font face="courier new, monospace">Type=oneshot</font></div><div style><font face="courier new, monospace">ExecStart=/bin/sleep 60</font></div><div style>
<font face="courier new, monospace"><br></font></div><div style><font face="courier new, monospace">[Install]</font></div><div style><font face="courier new, monospace">WantedBy=shutdown.target</font></div><div style><font face="courier new, monospace"><br>
</font></div><div style><font face="courier new, monospace">Before=shutdown.target ensures that shutdown.target is not reached before the service is finished since it's type is "oneshot". But if I add "Before=umount.target" or "Before=basic.target" to the service file, the requested shutdown order is not obeyed.</font></div>
<div style><font face="courier new, monospace"><br></font></div><div style><font face="courier new, monospace">Output snipped:</font></div><div style><font face="courier new, monospace"><br></font></div><div style><font face="courier new, monospace">[OK] Stopped target Local File Systems</font></div>
<div style><font face="courier new, monospace"> Unmounting /usr/local...</font></div><div style><font face="courier new, monospace"> Unmounting /lib/persistent...</font></div><div style><font face="courier new, monospace"> Starting Taking Long Time</font></div>
<div style><font face="courier new, monospace">[OK] Unmounted /usr/local</font></div><div style><font face="courier new, monospace">[OK] Unmounted /lib/persistent</font></div><div style><font face="courier new, monospace"><br>
</font></div><div style><font face="courier new, monospace">What am I trying to achieve:</font></div><div style><font face="courier new, monospace"><br></font></div><div style><font face="courier new, monospace">I would like to start a service on shutdown/restart. This service accesses (read/write) to the file systems and for that reason I don't want any of the file systems unmounted by systemd before the service completes.</font></div>
<div style><font face="courier new, monospace"><br></font></div><div style><font face="courier new, monospace">Thank you,</font></div><div style><font face="courier new, monospace">Umut</font></div><div style><font face="courier new, monospace"><br>
</font></div><div style><br></div></div>