sections in this module City College of San Francisco - CS260A
Unix/Linux System Administration

Module: StartupShutdown II
module list

Shutdown

Everyone knows that you should always shut down a system by telling it to do so. It is never a good idea to just turn the system off. The major reason for this was to ensure that the filesystem structure was in a consistent state when the machine was powered off. In fact, as with other systems, it can be signicantly slower to power on a linux system after an ungraceful shutdown.

Although current systems are more resilient to sudden loss of power, graceful sthutdowns are still important. They protect against data loss and avoid the necessity to examine the filesystem when the system is restarted.

A graceful shutdown involves using telinit to change the system state to one of 1, 0 or 6. telinit then emits the runlevel event, which causes certain upstart jobs to shut down:

Then the following runlevel-dependent events occur

All of this is accomplished by the simplest of shutdown methods, simply invoking telinit with the new runlevel. Although this method is acceptible for your personal system, it does not win any awards for tact if used on multiuser systems, as the users get no warning. In these situations, the shutdown command should be used.

The shutdown command

Prior to invoking telinit to change state, shutdown disables logins (by creating the /etc/nologin file) and delays a specified amount of time, broadcasting warning messages to all users periodically.

The synopsis for running the shutdown command is 

shutdown [ -r | -h ] time "message"

-r or -h are required to indicate reboot or halt. If you don't specify either -r or -h, the next state is runlevel 1 or maintenance mode. This is probably not what you want.

The message is the message to broadcast to all users. It is also placed in the /etc/nologin file so that any users that attempt to log in will see it, although on current systems this does not occur until at least one minute after the command is issued and the time to shutdown is less than five minutes away.

The time argument is when to shut down. The most commonly-used formats are

For example,

# shutdown -r +5 "Emergency maintenance required. Please log-off"

results in the following message displayed on the terminal of all users

Broadcast message from root (pts/2) (Fri Mar  6 17:56:29 2009):

Emergency maintenance required. Please log-off
The system is going DOWN for reboot in 5 minutes!

You can also specify a longer period to delay between init's sending the TERM and KILL signals using -t N, where N is in seconds, but this is often confused with the time to shutdown argument time, so I did not include it in the synopsis.

Triggering shutdown with keystroke

The control-alt-delete key sequence, when typed on a virtual console, is evidently turned into an event by upstart and can be used to reboot the system using the control-alt-delete upstart job:

$ cat control-alt-delete.conf
# control-alt-delete - emergency keypress handling
#
# This task is run whenever the Control-Alt-Delete key combination is
# pressed.  Usually used to shut down the machine.

start on control-alt-delete

exec /sbin/shutdown -r now "Control-Alt-Delete pressed"


Prev This page was made entirely with free software on linux:  
Kompozer
and Openoffice.org      
Next

Copyright 2011 Greg Boyd - All Rights Reserved.
Document
                    made with Kompozer