How to disable shutdown so that an important process cannot be interrupted?

For newer systems with systemd this has been solved by systemd-inhibit. Example of usage:

systemd-inhibit --why="Doing weekly backup" bash my-backups.sh

Then, if a user attempts to shutdown it will not be allowed unless forced.

❯ systemctl poweroff
Operation inhibited by "bash my-backups.sh" (PID 2414 "systemd-inhibit", user ntrrgc),
reason is "Doing weekly backup".
Please retry operation after closing inhibitors and logging out other users.
Alternatively, ignore inhibitors and users with 'systemctl poweroff -i'.

Run which shutdown to see where the path to the shutdown program is. You can rename the file, although I recommend against it.

Another (safer) method. Use an alias: alias shutdown=' ' Something like this is more reversible. If you're trying to prevent shutdown from all users, add the alias globally.


Disable the "shutdown/reboot/poweroff/halt/hostname" like commands in mission critical servers

chmod 0 /sbin/shutdown

then if you need to use it, chmod it back to chmod 0755.

Tags:

Linux

Shutdown