You are not logged in.
Hi Arch community!
Is there a way to prevent poweroff and reboot if some drive is mounted? Like if it is mounted, pressing "Power" button on system unit won't do anything, neither commands "poweroff" and "reboot" will. I need it because I have TrueCrypt volume. And it is supposed to be unmounted with "truecrypt" program. And I might forget to unmount it manually and power the machine down. It would be awesome if while this volume is mounted you couldn't turn off computer with any command/signal.
Last edited by Mr. Alex (2015-09-12 07:47:16)
Offline
Isn't systemd able to do that automatically with some configuration?
Edit: I mean that systemd unmounts the volume automatically
Last edited by rikn00 (2015-09-05 10:05:36)
Offline
Not TrueCrypt volume AFAIK.
Offline
You could create a systemd unit that runs some script that unmounts your truecrypt volum before shutdown
[Unit]
Description=Your description here
Before=shutdown.target
[Service]
ExecStart=/bin/true
ExecStop=/your/script/here
RemainAfterExit=yes
[Install]
WantedBy=multi-user.targetOffline
ugjka, thanks, but I would like exactly prevention of shutting down.
Offline
Assuming your WM or DE calls /usr/bin/poweroff to shut down (I don't know whether this is true or not) you could try something like creating the file /usr/local/bin/poweroff as executables in /usr/local/bin take precedence over those in /usr/bin. Then in that file you could add something along the lines of the following:
#!/bin/sh
if [ ! <volume is mounted> ]; then
/usr/bin/poweroff
fiI don't know what <volume is mounted> should be as I have no experience with TrueCrypt, you will probably know better than I. You can do the same for reboot as well. Like I said though, this may not work because your DE may not use /usr/bin/power or /usr/bin/reboot
EDIT: If it's a DE like Xfce for instance, you could try a similar approach, but overriding xfce4-session-logout instead.
Last edited by Chazza (2015-09-06 16:20:40)
Offline
Chazza, thanks, I got it. When I perform "poweroff", it doesn't call local bin first, goes straight to /usr/bin. But that can be fixed by aliasing. How do I configure power button on system unit that way? I use IceWM and no DE. If I can configure power button, the question will be solved. :-)
Offline
I think that logind handles the power key. I don't think you can tell logind to do anthing fancy like run a script though what you could do is stop logind from handling the power key altogether and then perhaps the power key can be handled some way from within icewm? Not too sure on that one but anyway - to stop logind from handling the power button, edit /etc/systemd/logind.conf and change the HandlePowerKey value to ignore and then restart the systemd-logind service.
Offline
Chazza, thanks, I got it working now! :-D
Offline
You should use systemd-inhibit to run a script. The system can't go poweroff / reboot until that script exits.
http://www.freedesktop.org/software/sys … hibit.html
That script could be:
#!/bin/bash
while (mount | grep <insert your mount point here> > /dev/null); do
sleep 1
done
BTW, if you run systemd-inhibit in some console/xterm in a desktop environment (e.g. KDE), and use DE's poweroff function, the system will go poweroff because DE kills xterm (along with systemd-inhibit) before calling poweroff. So you should either run the command outside of DE, or nohup, or as a systemd job.
Last edited by genericity (2015-09-12 08:41:24)
Offline