System Shutdown

Solaris has been designed to run continuously—seven days a week, 24 hours a day. Occasionally, however, you need to shut down the system to carry out administrative tasks. At other times, an application might cause the system to go awry, and the operating system must be stopped to kill off runaway processes and then be restarted.

You can shut down the system in a number of ways using various UNIX commands. With Solaris, taking down the operating system in an orderly fashion is important. When the system boots, several processes are started. These must be shut down before you power off the system. In addition, information has been cached in memory and has not yet been written to disk. The process of shutting down Solaris involves shutting down processes, flushing data from memory to the disk, and unmounting file systems.

Caution

Shutting down the system improperly can result in loss of data and the risk of corrupting the file systems.


Tip

To avoid having your system shut down improperly during a power failure, use an uninterruptible power supply (UPS) capable of shutting down the system cleanly before the power is shut off.


Commands to Shut Down the System

When preparing to shut down a system, you need to determine which of the following commands is appropriate for the system and the task at hand:

/usr/sbin/shutdown 
/sbin/init 
/usr/sbin/halt 
/usr/sbin/reboot 
/usr/sbin/poweroff 

Stop+A or L1+A (to be used as a last resort; see the following Caution)

Caution

Using the Stop+A key sequence (or L1+A) abruptly breaks execution of the operating system and should be used only as a last resort to restart the system.


The first three commands initiate shutdown procedures, kill all running processes, write data to disk, and shut down the system software to the appropriate run level. The /usr/sbin/reboot command does all of these tasks, but it then boots the system back to the state defined as initdefault in /etc/inittab. The /usr/sbin/poweroff command is equivalent to init 5. The last command, which is really a series of keystrokes, stops the system unconditionally.

/usr/sbin/shutdown

Use the shutdown command when shutting down a system that has multiple users. The shutdown command sends a warning message to all users who are logged in, waits for 60 seconds (the default), and then shuts down the system to single-user state. A command option (-g) lets you choose a different default wait time. The -i option lets you define the init state to which the system will be shut down. The default is run level S.

The shutdown command performs a clean system shutdown, which means that all system processes and services are terminated normally and file systems are synchronized. You need superuser privileges to use the shutdown command.

When the shutdown command is initiated, all logged-in users and all systems mounting resources receive a warning about the impending shutdown, and then they get a final message. For this reason, the shutdown command is recommended over the init command on a server with multiple users.

Tip

When using either shutdown or init, you might want to give users more advance notice by sending an email message about any scheduled system shutdown. See Chapter 5, “Communicating with Other Users,” for methods of doing this.


Exercise 9.3 Shutting Down the System

1.
As superuser, type the following to find out if users are logged in to the system:

# who 

2.
A list of all logged-in users is displayed. You might want to send an email or broadcast a message to let users know that the system is being shut down.

3.
Shut down the system by using the shutdown command:

# shutdown -i<init-state> -g<grace-period> -y 

The following describes the options for the shutdown command:

-i<init-state> Brings the system to an init state different from the default of S. The choices are 0, 1, 2, 5, and 6.
-g<grace-period> Indicates a time (in seconds) before the system is shut down. The default is 60 seconds.
-y Continues to shut down the system without intervention; otherwise, you are prompted to continue the shutdown process after 60 seconds. If you use the shutdown -y command, you are not prompted to continue; otherwise, you are asked, “Do you want to continue? (y or n).”

/sbin/init

Use the init command to shut down a single-user system or to change its run level. The syntax is as follows:

init <run level> 

<run level> is any run level described in Table 10.2. In addition, <run level> can be a, b, or c, which tells the system to process only /etc/inittab entries that have the a, b, or c run level set. These are pseudo states, which can be defined to run certain commands but which do not cause the current run level to change. <run level> can also be the keyword Q or q, which tells the system to reexamine the /etc/inittab file.

You can use init to place the system in power-down state (init 0) or in single-user state (init 1). For example, to bring the system down to run level 1 from the current run level, type the following:

init 1 

The system responds with this:

INIT: New run level: 1 
Changing to state 1. 
Unmounting remote filesystems: /vol nfs done. 
System services are now being stopped. 
Mar 14 13:13:22 unknown /usr/sbin/vold[475]: problem unmounting /vol; 
Interrupted system call 
Mar 14 13:13:22 unknown pseudo: pseudo-device: tod0 
Mar 14 13:13:22 unknown genunix: tod0 is /pseudo/tod@0 
Mar 14 13:13:22 unknown pseudo: pseudo-device: pm0 
Mar 14 13:13:22 unknown genunix: pm0 is /pseudo/pm@0 
Print services stopped. 
Mar 14 13:13:22 unknown syslogd: going down on signal 15 
Killing user processes: done. 
Change to state 1 has been completed. 
Type control-d to proceed with normal startup, 
(or give root password for system maintenance): 

As another example, maybe you made a change to the /etc/inittab file, and you want to have the system reread /etc/inittab and implement the change. Type the following:

init q 

No system messages will be displayed, and the inittab file will be reexamined.

Note

The telinit command is available for compatibility. It is simply a link to the /usr/sbin/init command.


/usr/sbin/halt

Use the halt command when the system must be stopped immediately and it is acceptable not to warn current users. The halt command shuts down the system without delay and does not warn other users on the system of the shutdown.

/usr/sbin/reboot

Use the reboot command to shut down a single-user system and bring it into multiuser state. reboot does not warn other users on the system of the shutdown.

The Solaris reboot and halt commands perform an unconditional shutdown of system processes. These commands shut down the system much more quickly than the shutdown command, but they do not do so as gracefully because they do not run the kill scripts located in /etc/rc<n>.d. No messages are sent to users. reboot and halt do not notify all logged-in users and systems mounting resources of the impending shutdown, but they do synchronize file systems.

The quickness of such a reboot is useful in certain circumstances, such as when rebooting from the single-user run state. Also, the capability to pass arguments to OpenBoot via the reboot command is also useful. For example:

reboot -- -rs 

This will reboot the system into run level s and reconfigure the device tables.

/usr/sbin/poweroff

The poweroff command is equivalent to the init 5 command.

Note

init and shutdown are the most reliable ways to shut down a system because they use rc scripts to kill running processes and shut down the system with minimal data loss. The halt and reboot commands do not run the rc scripts properly and are not the preferred method of shutting down the system.


Stopping the System for Recovery Purposes

Occasionally, the system might not respond to the init commands specified earlier. A system that doesn’t respond to anything, including reboot or halt, is called a “crashed” or “hung” system. If you try the commands just discussed but get no response, you can press Stop+A or L1+A to get back to the boot PROM. (The specific Stop key sequence depends on your keyboard type.) On terminals connected to the serial port, press the Break key.

Note

The sequence to stop the system is Return+Tilde+Ctrl+B and is equivalent to Stop+A. An interval of more than 0.5 seconds must exist between characters, and the entire string must be entered in less than 5 seconds. This is true only with serial devices acting as consoles and not for systems with keyboards of their own. If your console is connected to the serial port via a modem, you can send a break (Stop+A or L1+A) through the Tip window by typing ~# (tilde and then pound sign).


The following is an example of how to break out of a hung system:

Exercise 9.4 Breaking Out of a Hung System

1.
Use the abort key sequence for your system (Stop+A or L1+A).

The monitor displays the ok PROM prompt.

2.
Type the sync command to synchronize the disks:

ok sync 

3.
When you see the syncing file systems message, press the abort key sequence for your system again.

4.
Type the appropriate reset command to reset the hardware and start the boot process:

ok reset 

5.
After you receive the login: message, log in and type the following to verify that the system is booted to the specified run level:

# who –r 

6.
The system responds with the following:

run-level 3  Jun 9 09:19  3   0  S 

Turning Off the Power

Only after shutting down the file systems should you turn off the power to the hardware. Turn off power to all devices after the system is shut down. If necessary, also unplug the power cables. When power can be restored, use the following steps to turn on the system and devices.

Exercise 9.5 Turning On the Power

1.
Plug in the power cables.

2.
Turn on all peripheral devices such as disk drives, tape drives, and printers.

3.
Turn on the CPU and monitor.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset