What is graceful shutdown in Linux

I have heard that "shutdown -h now" is not a graceful shut down command because it does something akin to "kill -9" for all processes, as opposed to "kill -15".

Is this true, and if so, what is a more graceful way of shutting down to ensure everything has time to clean up after its self?

P.s. Using CentOS, Ubuntu, and Debian mainly.

HopelessN00b

53.4k32 gold badges133 silver badges208 bronze badges

asked Nov 4, 2011 at 11:59

What is graceful shutdown in Linux

2

shutdown -h now will call /etc/rc.d/rc or /etc/init.d/rc. The rc script will call the kill scripts for the new runlevel (0 for -h, 6 for -r), followed by any start scripts.

You'll see S30killprocs or S00killall or something like that depending on your distro. This comes after all the kill scripts have been called to attempt to stop each service gracefully in turn. It will try kill -15 first, followed by kill -9.

Short answer: shutdown -h now or shutdown -r now are graceful. halt and reboot used to be non-graceful, but they will just call shutdown for you unless you use the -f option.

answered Nov 4, 2011 at 12:18

CakemoxCakemox

24.4k6 gold badges41 silver badges67 bronze badges

No that is not true. shutdown changes init level which then runs all the shutdown scripts. What these scripts do depends on the script. But they normally don't terminate processes but send them the signal to end.

So this is the manual excerpt for shutdown:

   shutdown  brings  the system down in a secure way.  All logged-in users
   are notified that the system is going down, and  login(1)  is  blocked.
   It is possible to shut the system down immediately or after a specified
   delay.  All processes are first notified that the system is going  down
   by the signal SIGTERM.  This gives programs like vi(1) the time to save
   the file being edited, mail and news processing programs  a  chance  to
   exit  cleanly,  etc.   shutdown  does  its  job  by signalling the init
   process, asking it to change the runlevel.  Runlevel 0 is used to  halt
   the  system, runlevel 6 is used to reboot the system, and runlevel 1 is
   used to put to system into a state where administrative  tasks  can  be
   performed; this is the default if neither the -h or -r flag is given to
   shutdown.  To see which actions are taken on halt  or  reboot  see  the
   appropriate entries for these runlevels in the file /etc/inittab.

answered Nov 4, 2011 at 12:05

mailqmailq

16.9k2 gold badges36 silver badges67 bronze badges

2

Graceful shutdown and hard shutdown are two opposing methods of turning off a computer. A graceful shutdown is when a computer is turned off by software function and the operating system (OS) is allowed to perform its tasks of safely shutting down processes and closing connections. A hard shutdown is when the computer is forcibly shut down by interruption of power.

Graceful shutdowns are generally performed intentionally by users, as a part of their daily routines, at the end of a work day or when finished with home use of a computer. Hard shutdowns maybe unintentional due to power disconnects, electronic protection circuits or hardware failures. In the case of some safety issues like computer fires or security issues like malware or hacked computers, hard shutdowns may be as a safety precaution by users or IT departments.

Generally, a graceful shutdown is preferable in the case of any OS that saves its state. When the standard shutdown procedures are not done with these OSs, the result can be data corruption of program and operating system files. The result of the corruption can be instability, incorrect functioning or failure to boot.

Many modern OSs and other software are fault tolerant and generally handle the odd power interruption without issue. Both Bare metal and virtualized systems can be affected by hard shutdowns, so they should be avoided when unnecessary. Virtual machines (VM) may need to be restored from backups, while bare metal systems may even require a full reinstall.

This was last updated in October 2018

Continue Reading About graceful shutdown and hard shutdown

  • Emergency power systems in data center disaster recovery planning
  • Build a data center shutdown procedure to prepare for the worst
  • How to Select an Uninterruptible Power Supply (UPS) for Your Computer
  • Are you shutting down your computer correctly? Here's why it matters
  • How UPS devices can protect a virtualization host

What is graceful shutdown?

A graceful shutdown is when a computer is turned off by software function and the operating system (OS) is allowed to perform its tasks of safely shutting down processes and closing connections. A hard shutdown is when the computer is forcibly shut down by interruption of power.

Why is graceful shutdown important?

Graceful shutdown means that the OS (operating system) can safely shut down its processes and close all connections, however long that takes. This helps to prevent accidental data loss or other unexpected problems if the shutdown is performed intentionally by the user.

What command is used to shutdown a Linux system gracefully?

Shut down the system The shutdown command features two options: --halt and --poweroff . The --halt option stops the operating system while the --poweroff option turns off the system. [ Free download: Advanced Linux commands cheat sheet. ]

What does shutdown in Linux do?

The shutdown command brings the system down in a secure way. All logged-in users are notified that the system is going down, and login operations are blocked. It is possible to shut the system down immediately, or after a specified delay.