<div dir="ltr"><div dir="ltr">On Thu, 11 Mar 2021 at 11:00, Patrick O'Callaghan <<a href="mailto:pocallaghan@gmail.com">pocallaghan@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Apologies in advance if this is a FAQ, or if there is a more<br>
appropriate list for this question. I'm looking for a step-by-step<br>
guide for the following situation:<br>
<br>
I have an external 2-bay USB3 drive enclosure, configured as an MD<br>
Raid-1 device. This works without issue.<br>
<br>
I normally only use the device for nightly backups, so would prefer to<br>
leave it powered off until needed.<br>
<br>
I have scripts to power it up (creating the appropriate /dev/md entry<br>
and mounting the drive) and down (unmounting, removing the /dev/md<br>
entry and sending a magic signal to the USB device so it powers itself<br>
down after 30 minutes).<br>
<br>
Unfortunately a system reboot always leaves it in the 'powered up and<br>
present in /dev/md' state, so I have to manually run the power-down<br>
script every time I reboot. This is inelegant.<br>
<br>
I would much prefer to have this all handled automagically by systemd,<br>
but I need guidance on how to configure it. If it weren't for the power<br>
question, I know I can just use automount (and have managed to get this<br>
far on my own), but I don't know where or how to insert the power<br>
scripts. My reading of the systemd docs leads me to think that<br>
ExecStart/Stop might be the way, but where do I put this? Do I need a<br>
specific foo.mount unit (I'm currently using /etc/fstab)?<br></blockquote><div><br></div><div>After a good deal of thrashing around, I settled on using "inotify -e unmount" to detect when automount unmounted the drive, and used that to trigger the power-down script.</div><div><br></div><div>poc<br></div></div></div>