What is graceful system shutdown?

Ungraceful shutdown is when the Linux system is suddenly and/or forcefully halted. This could be due to a power supply interruption or software stack crash. A graceful shutdown, on the other hand is when you switch off your Linux system using embedded software functions while allowing the OS to finalise and close remaining tasks and save any in-flight data to the disks. This is also called Planned Shutdown.

Although Linux is famous for its ability to run for years without a need for a single reboot, sometimes you might need to shut down your server and, assuming you have SSH access to the machine, here is the proper way to do it.

Commands to gracefully shutdown Linux

Shut down gracefully and immediately

$ shutdown -h now

Shut down gracefully after X number of minutes

$ shutdown -P +30 (P stands for Power Off)

This will shut the machine down after 30 minutes. 

To shut down at a specific hour run;

$ shutdown -P 3:00

This will shut the machine down at 3:00 AM

To cancel a pending/scheduled shutdown just do;

$ shutdown -c

The shutdown command will trigger the proper Init level resulting in the OS gracefully stopping all running services. Any stuck processes will be terminated using a kill -9 command then the machine will halt. It is also important to note that, when the time argument is used, 5 minutes before the system goes down the system will create a /run/nologin file to prevent users from logging into the system as it prepares for shutdown.

The halt, poweroff and reboot commands can also be used to shut the machine down.

$ reboot -P (P also stands for Power Off)
$ halt

If you want to forcefully halt the machine you can do;

$ halt -f or reboot -f

Are you looking for an interesting and inspiring training position? Want to learn a thing or two about Linux and the leading Open-Source storage technologies? Starline is always looking for new members to join its team of Open-Source enthusiasts.