Use molly-guard to protect your Linux/Unix machines from being mistakenly shut down/restarted

Source: Internet
Author: User

Use molly-guard to protect your Linux/Unix machines from being mistakenly shut down/restarted

I am going! Again. I thought I was logged on to my home server. As a result, the database server is restarted. In addition, I sometimes enter the "shutdown-h 0" command in the wrong terminal. I know that some people often make this mistake.

My anger is intolerable

Is there a way to solve this problem? Is it true that I can only endure the pain of random restart and shutdown? Although people always make mistakes, they cannot make mistakes again.

Recently, I complained on tweet:

I always make the same mistake over and over again: (I should have entered:sudo virsh reboot d1

But I always lost or restarted my computer.sudo reboot d1

-- NixCraft (@ nixcraft) February 19,7 7

Some suggestions were received. Let's give it a try.

 

Introduce molly guard to you

Molly-Guard tries to prevent you from accidentally shutting down or restarting the Linux server. The package description In Debian/Ubuntu is as follows:

This package will install a shell script to block existingshutdown/reboot/halt/poweroff/coldreboot/pm-hibernate/pm-suspend*Command.molly-guradA series of scripts will be run first. The real commands will be called only when all scripts return success. One script checks whether an SSH session exists. If the command is called through an SSH Session, the shell script prompts you to enter the name of the host to close. This should be enough to prevent unexpected shutdown or restart.

It seems that molly-guard is still a proprietary term Jargon File:

A barrier used to prevent a barrier from being clumsy or accidentally touched by a red switch. The organic glass, which was initially referred to as a temporary big red button on IBM 4341, was restarted twice in a day by a programmer's toddler daughter (Molly. Later, it was used to cover the stop/restart buttons on disks and network devices. In the hardware directory, you rarely see a boring description like "guarded button ".

 

How to install molly guard

Useapt-getCommand oraptCommand to search for and install molly-guard:

  1. $ apt search molly-guard
  2. $ sudoapt-get install molly-guard

Result:

Fig.01: Installing molly guard on Linux

 

Test

InputrebootCommands andshutdownCommand:

  1. $ sudoreboot
  2. #reboot
  3. $ shutdown-h 0
  4. #sudoshutdown-h 0
  5. ### running wrong command such as follows instead of
  6. ### sudo virsh reboot vm_name_here
  7. $ sudoreboot vm_name_here

Result:

Fig.02: Molly guard saved my butt ;\)

I like molly-guard very much. Therefore, I add downstream contentapt-debian-ubuntu-common.ymlFile:

  1. - apt:
  2. name: molly-guard

Yes. I used Ansible to automatically install it on all Debian and Ubuntu servers.

Related: My 10 major UNIX Command Line errors

 

What if I don't have molly-guard on Linux distributions or Unix systems (such as FreeBSD?

Don't worry, set the shell alias:

  1. ##bash shell example ###
  2. aliasreboot="echo 'Are you sure?' If so, run /sbin/reboot"
  3. aliasshutdown="echo 'Are you sure?' If so, run /sbin/shutdown"

You can also temporarily cancel the alias mechanism to run real commands. For example, you can run reboot as follows:

  1. # \reboot

Or

  1. # /sbin/reboot

In addition, you can write a shell/perl/python script to call these commands and request confirmation.reboot/halt/shutdown.

Via: https://www.cyberciti.biz/hardware/how-to-protects-linux-and-unix-machines-from-accidental-shutdownsreboots-with-molly-guard/

Author: Vivek Gite Translator: lujun9972 proofreaders: wxy

This article was originally compiled by LCTT and launched with the honor of Linux in China

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.