UNIX Hints & Hacks

ContentsIndex

Chapter 1: Topics in Administration

 

Previous ChapterNext Chapter

Sections in this Chapter:

1.1 Collecting System Information

 

1.7 Swap on-the-Fly

 

1.13 Remove the ---- Dashes ----

1.2 Backup Key Files!

 

1.8 Keep It Up with nohup

 

1.14 echo Does ls

1.3 Execution on the Last Day of a Month

 

1.9 Redirecting Output to Null

 

1.15 Building Large Dummy Files

1.4 Dealing with Unwanted Daemons

 

1.10 Keeping Remote Users Out

 

1.16 Burning-in Disk Drives

1.5 Keep Those Daemons Running

 

1.11 Rewinding Tapes Fast

 

1.17 Bringing a System Down

1.6 fuser Instead of ps

1.12 Generating a Range of Numbers

 

 

1.17 Bringing a System Down

1.17.1 Description

1.17.1 Description

There are seven ways to bring down a system, but in the end you really have only two choices: You can do it gracefully or you can do it the hard way!

Reason

Why not always use a graceful method? Well, naturally you would want to try to bring any system down in a graceful manner. But not all UNIX systems allow a clean shutdown all the time. Sometimes while the system is processing through a clean shutdown procedure it hangs. Some circumstances lead to bringing the system down in a hard way. Here is a small list of reasons that can lead you to bring the system down in a not-so-graceful way:

You really should do two things before you initiate any command to bring down your system: verify the hostname of the system you want to shut down and sync your disk!

In a networked UNIX environment with multiple shells to remote systems, make sure you're on the right system by using the hostname command. It takes only a second. If you support 50-100 systems, the odds are that you will shut down the wrong system at least once a year. It will happen when you are tired or not paying attention.

When you sync the disks, you flush all modified inodes, data block cache, and superblock cache to disks. Running sync before the system is brought down minimizes the amount of damage that could occur if the system were to crash or have to be taken down in a hard way.

# hostname
rocket
# sync # sync

Line 1: Verify the correct host to shutdown.

Line 4: The first sync begins flushing operation of inodes and cache, but it might not be finished by the time it returns a shell prompt.

Line 5: This sync does not start until the previous sync has completed. This guarantees that all data is flushed.

Always run sync twice if you really want to be sure that everything has been flushed. A daemon called update will get started at boot time to automatically run sync every 30 seconds. This doesn't mean that you don't have to run the sync command. It takes less than a second for there to be inconsistencies in the filesystem. The update daemon can be somewhat of an insurance daemon. If the system crashes, update might have had enough time to sync the disks.

Bringing down a system depends on the system itself. Only you can determine which method is right for the system in your environment. Workstations typically do not have applications that contain a large amount of open files, such as database servers. Larger servers are susceptible to major problems if a system crash were to occur. Here is a list of ways a system can be taken down, from safe and graceful to hard crash:

Real World Experience

shutdown  This command should always be on any server with multiple users and sensitive applications that need to be shutdown gracefully.

halt  Typically, this command is used on single user workstations and standalone systems. It is used rarely on servers with multiple users.

reboot  This is generally used on an individual workstation by the user. This command is also often used remotely over a network on a user's workstation when the UNIX administrator is confident that the system will boot up without any incidents.

Fasthalt and fastboot  These commands are good to use on highly utilized systems when there is a system that needs rebooting in the least amount of time. Candidates are any system that provides a service such as mail, news, DNS, or NIS. Database servers are not good candidates for these commands. This command is good for large fileservers with over 50GB of space. If the filesystem is corrupted and doesn't mount when the server comes up, you can always run a filesystem check on the corrupted area, but the rest of the system would be up and running.

telinit  If all the other commands fail, this should be the next in line to try. The odds are that this command will not work, though, because it is similar in function to shutdown.

Power button, switch, or key  If bringing the system down through the software doesn't work, there is no alternative but to hit the power button, flip the key, or hit the power switch.

Power cord  Usually this is kicked by a user or someone working around a workstation and the infamous call comes in: "All of a sudden, my computer has no power!" Most vendors have designed their systems so administrators will never have to deal with this situation. However, I still see one or two workstations where pulling out the power cord was necessary, but never any server-level systems.

Other Resources

Man pages:

fasthalt, halt, hostname, reboot, shutdown, sync, telinit

UNIX Hints & Hacks

ContentsIndex

Chapter 1: Topics in Administration

 

Previous ChapterNext Chapter

Sections in this Chapter:

1.1 Collecting System Information

 

1.7 Swap on-the-Fly

 

1.13 Remove the ---- Dashes ----

1.2 Backup Key Files!

 

1.8 Keep It Up with nohup

 

1.14 echo Does ls

1.3 Execution on the Last Day of a Month

 

1.9 Redirecting Output to Null

 

1.15 Building Large Dummy Files

1.4 Dealing with Unwanted Daemons

 

1.10 Keeping Remote Users Out

 

1.16 Burning-in Disk Drives

1.5 Keep Those Daemons Running

 

1.11 Rewinding Tapes Fast

 

1.17 Bringing a System Down

1.6 fuser Instead of ps

1.12 Generating a Range of Numbers

 

 

© Copyright Macmillan USA. All rights reserved.