What command does the system execute when "shut down the system" is pressed? Is it possible to kill that process with root?
Asked
Active
Viewed 1,653 times
2
-
1I think the command depends on DE. There're multiple ways: `systemctl poweroff`, `shutdown -h now`, also dbus has something. I assume you might try to filter out commands to `systemctl`, e.g. swap `systemctl` with a script that if it has argument `poweroff`, do nothing, otherwise call the real `systemctl`. Why would you want this in the first place? – Hi-Angel Jun 05 '17 at 21:50
-
These options seem plausible but the one which interests me the most is surely the "swap systemctl with a script that if it has argument poweroff do X". How would I go about that one? Regarding your question about my motives, I would have to say that I want a particular bundle of script to run when the computer receives the order to shutdown (The time the scripts take to complete can vary drastically so I would have to prevent the system from shutting down until it's completed). – ulovah Jun 05 '17 at 22:51
-
There's no reason to think the GUI runs any command. It's highly likely it will make use of the appropriate library calls, or pass dbus messages to another process which has the relevant privileges. – muru Jun 06 '17 at 01:26
-
@ulovah then you don't want to cancel shutdown, you just want to run a script before system shutdown. You need to [create and enable a systemd unit](https://unix.stackexchange.com/a/41756/59928) which would run your script, and for shutdown to not happen before your script exited [set the `TimeoutStopSec=infinity`](https://www.freedesktop.org/software/systemd/man/systemd.service.html#TimeoutStopSec=). – Hi-Angel Jun 06 '17 at 04:41
-
Ah, don't forget to add to the unit what other units your script might depend upon. E.g. if your script is using network, add `Requires=network.target` *(multiple units separated by space if I'm not mistaken)*. – Hi-Angel Jun 06 '17 at 05:20
1 Answers
0
shutdown -h now most likely.
I don't believe you can cancel it. That's like cancelling the stopping of a service.
You don't want that.
Ali Razmdideh
- 5,710
- 2
- 34
- 51
Stan Smulders
- 101
- 1
-
1Well, not exactly cancelling, but it's possible to configure AppArmor or SELinux to not allow running a process with specific args. – Hi-Angel Jun 05 '17 at 22:26