I'm looking for a practical way to avoid shutting down or rebooting the wrong server. What safeguards are worth using?
How do you prevent accidental shutdowns on Linux servers?
Answers
For production, make shutdown part of a procedure rather than relying on a prompt alone. Have a second person check the target server, then remove it from service first, for example by failing over the cluster or taking it out of the load balancer.
A confirmation prompt can catch a quick mistake, but it doesn't establish that the server is ready to go offline.
Reply to this answer
A hostname confirmation prompt can still be useful, even if the hostname is displayed right there. It adds a pause before a command runs, which might catch an accidental selection from shell history. I wouldn't treat it as a substitute for checking the target, though.
Reply to this answer
Make production shells visually obvious. A bright red prompt alongside the environment name won't prevent a shutdown, but it's a useful reminder when switching between servers and might make you stop before running the command.
Reply to this answer
For a manual reboot, schedule it a minute ahead with shutdown -r +1 instead of rebooting immediately. That gives you a short window to catch a mistake before the machine goes down.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions