Conditional hibernate with systemd in Linux

1

I use to have one Linux pm-utils’ script that unmounts my mounted USB disks partitions, triggered by hibernation process. Script returned a failure exit code when unmount failed, so hibernation process gets cancelled.

I know how to trigger an script (my USB unmount process) using systemd (either by using a “RequiredBy” service or a script in /lib/systemd/system-sleep [debian] or a /usr/lib/systemd/system-sleep [other distributions]). But I can’t achieve the “cancellation part.”

Any thoughts about how to achieve a hibernate cancellation based on an script exit code or a similar mechanism?

Tried using ConditionPathExists, but apparently it's evaluation is made before any other action.

Federico Valido

Posted 2015-03-05T20:46:23.083

Reputation: 11

Please edit your question to address these issues. Your question makes a lot of assumptions. Such as: Do any of us know or understand what OS you are on? What are you trying to achieve? Creating a Bash script perhaps? Please clarify your question. – JakeGould – 2015-03-05T20:53:26.050

Also, what is the purpose of the unmount? AFAIK, suspending already flushes the write caches, so it would be safe to unplug without unmounting anyway. – user1686 – 2015-03-05T21:59:33.543

Hi @JakeGould and thank you. I thought it was clear that linux was my OS. I don't know if I tagged it as linux in the first place or if Kevin did it, but now it's clear. I think that script language it's unrelevant. I just want to know the systemd mechanism to achieve a "dynamic conditional" execution of a service (or "dynamic cancellation"). And I am particular interested in Hibernate/Sleep systemd. – Federico Valido – 2015-03-06T21:20:50.157

Hi @grawity ! Didn't know for sure about the auto flush during Hibernate process, but it sounds logical. But I think that ntfs volumes may be marked as dirty even if all writes where flushed. There are other situations where I want to know that the drive couldn't be unmounted before hibernate, but it's out of the scope of my question.

Despite of that, "dynamic conditional execution" (or "dynamic cancellation") mechanism in systemd is not clear in the documentation (or I couldn't figure out how to do it). So, I think that this question may help other with usb unrelated problems. Thank you! – Federico Valido – 2015-03-06T21:33:43.050

BTW, you might want to try asking on [unix.se] If you don't get an answer here. Best way would be probably be flag your own question, reason other, and ask for it to be moved. – derobert – 2015-03-07T02:07:22.047

No answers