14.1. Orderly vs. Disorderly Shutdown
Unlike machines running DOS, Unix machines do not take kindly to a
sudden loss of power.
Instead, they need to be shut down in an orderly manner. This is because
of a number of reasons such as uncommitted filesystem writes,
the need to proplerly shut down running services
(especially large databases), user notification about the
impending shutdown, etc.
While Unix machines today are not as vulnerable to sudden loss of
power as they were a decade ago, it is still not a good idea to simply
yank the power. This desperate measure should be reserved for
extreme situations where the machine locks up completely and is
totally inaccessible (if the console is locked up, try
getting to it via the network).
While the actual details vary from vendor to vendor, a proper
Unix shutdown changes the system from a multiuser
run level
to a run level where it is safe to power the machine off.
The usual shutdown sequence goes something like this:
- All logged on users are warned about the impending shutdown
and given a chance to close files and to log out.
- Further login may be blocked.
- init is asked to
change the run level from the multiuser state
the either a single user or a safe-to-power-off state.
- All running processes are notified that the system is
going down by the signal SIGTERM (this allows a number of
programs to save vital information to disk).
- The system goes through the appropriate shutdown
scripts to shut down running services and daemons.
- The filesystems on disks are synchronized (more popularly known as
sync'ed), i.e. unwritten buffers are committed to disk.
- Machine may be powered off.