sections in this module | City
College of San Francisco - CS260A Unix/Linux System Administration Module: StartupShutdown II |
module list |
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:
the ttys job shuts down logins on virtual consoles
the prefdm job shuts down the window manager
If the new runlevel is 0 or 6, the killall subsystem is started, followed by
the halt
subsystem with the appropriate next state of halt (0) or reboot (6). This
syncs and unmounts the disks.
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
-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
a standard linux time, HH:MM
+N, where N is the number of minutes from now
now
For example,
# shutdown -r +5 "Emergency maintenance required. Please log-off"
results in the following message displayed on the terminal of all users
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:
Prev | This page was made entirely
with free software on linux: Kompozer and Openoffice.org |
Next |