What is the simplest way to disable or temporarily suspend reboot/shutdown when an important process is running? The process takes too long to finish and cannot be paused/resumed so I like to avoid shutting down the pc while it is running. It is run from cron so unless I manually check for running processes, I wouldn't know that it is running. Thanks.
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.
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'.
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
I would disable the command in the /etc/sudoers file so that only root can execute it.
# Cmnd alias specification Cmnd_Alias SHUTDOWN = /sbin/shutdown # User privilege specification root ALL=(ALL:ALL) ALL vmule ALL=(ALL:ALL) ALL, !SHUTDOWN
and when I try to run the command:
vmule@debian:~$ sudo /sbin/shutdown -r now Sorry, user vmule is not allowed to execute '/sbin/shutdown -r now' as root on debian.vm
I wanted to prevent a local user to shutdown a laptop during an upgrade. Disabling the input device was the best way to go. For me it was sufficient to disable the mouse, but the keyboard can be disabled as well.
Of course there's a drawback, the computer can't be used during this period.
shutdown is technically an application too, which you can remove. Run
which is a command which shows you the path of an application. In my case the output is
/sbin/shutdown. It's a file so you can just do
rm shutdown. Or if you want to disable it temporarily copy it, change the name and remove the original file.
You must have the sufficient permissions if you want to do
rm shutdown. It's read-only, hence why you may get an error. Try removing it as
root or if necessary try using the command