System Shutdown
One of the most important factors in the health of a system is ensuring that the data and configuration it contains are protected from corruption. It is therefore important to ensure that all applications have terminated successfully and that all their respective files are properly closed. All this must happen before the system unmounts the associated drives and powers off.
Most device input/output is handled in a similar matter across the server. Improperly closed files will not contain the information expected. This could lead to the improper functioning of applications dependent on said files.
One of the most common mistakes on Linux/Unix systems is to manually eject removable media before it is dismounted (umount). When this is done, data still stored in the buffers of the device driver cannot be written to the device. Even immediately reinserting the media might not maintain the proper machine state, and the data is therefore lost. To make matters worse, in many cases, the directory structure itself is memory resident. Not writing this structure back to the device properly could mean compromising the directory’s contents as well.
The same phenomenon happens with nonremovable media if the system is shut down abruptly. Great strides have been made with new file systems to protect from such losses. Consistency checks at boot time can also repair some of the damage. It is best, however, to perform an orderly shutdown at all times.
Two methods can be used to properly shut down a server. The first method is to use the init command with a parameter of zero, as shown in Table 3.1. Though this method stops all processes, it should be used only in extreme circumstances because the shutdown is rather abrupt.
A more graceful way to bring down the system is to use the shutdown command. This command brings down the system in a more orderly fashion, gives end users a proper notification of the shutdown, and forewarns other running applications to close open files. Once shutdown has been invoked, new login sessions are refused. A simplified format of the shutdown command is
shutdown [-h or -r] time [shutdown message]
In this example, the -h implies that the system will be halted after the shutdown and -r indicates that you would like to reboot. The time parameter in the command is a required field and can be the keyword now, a time specified in hh:mm format, or a specific number of minutes from now in +mm format. When a delay is specified in the command, shutdown will create an /etc/nologin file. Users will also be reminded of the shutdown every time half of the remaining uptime has expired. As an example, a time period of 10 minutes will see a message broadcast to interactive sessions at one-minute intervals. If the keyword now is used on the command line, no warnings, other than the first, are issued.
The last parameter is an optional message that will be sent to all currently logged-on users informing them of the shutdown. The content of the message is at your discretion.
Listing 3.4 shows a comment entered at the console by the root user as well as a notification received by all logged-on users.
LISTING 3.4: COMMENT ENTERED AT THE CONSOLE
Athena:/etc # shutdown -h +10 "Memory upgrade. Please log off" Broadcast message from root (pts/1) (Mon Mar 21 10:38:58 2005): Memory upgrade. Please log off The system is going DOWN for system halt in 10 minutes!
The proper shutdown of a system is necessary to minimize difficulties when you restart it. Using init 0 to shut down the system does not allow other running processes sufficient time to apply any pending changes and close their files properly. This can lead to file corruption and data loss. The preferred method would be to use the shutdown command.
The interpretation of keystroke sequences is dependent on physical access to the server as well as which version of Linux is being run. In SUSE LINUX, it is possible to use YaST to configure a response to the Ctrl+Alt+Del sequence. This should be disabled as it is preferred, in almost all cases, to control the shutdown through software instead of hardware.