11. Boot and Shutdown Procedures
When Solaris UNIX boots up and shuts down it refers to the following files:
When Booting |
When Shutting down |
/etc/rc2.d | /etc/rc0.d |
/etc/rc5.d | |
/etc/rc3.d |
Below is a listing of initialization states used within UNIX and what type of level that init state will take you to.
Initialization States |
|
Level | Use for Level |
0 |
Prom/OK prompt (You are not in UNIX, but in a special hardware mode) |
1 |
Single user mode (root only) console (only four processes running in this mode, is good for troubleshooting) |
2 |
Client mode almost never used |
3 |
Normal mode (if you are using it, then this is probably what init state you are in) |
4 |
Dedicated for future use |
5 |
Off |
6 |
Reboots, and goes to run level 3 |
0,5, and 6 are hardware states. What processes running is what distinguishes different levels. |
Here are some ways to manipulate these files if you want certain things to happen at boot or shutdown:
for f in /etc/rc2.d/k*
do
$f stop (turns off a service)
done
The above script will run all k* (files that begin with k will stop when you are in init state (discussed later) 2 for f in /etc/rc2.d/s* do $f start (start begins a service) done The above script will run all s* files with start when you start in init state 2) (/etc/rc2.d is for init state 2, /etc/rc5.d is for init state 5, /etc/rc3.d is for init state 3, and /etc/rc0.d is for init state 0)
Who r shows run level. The following is the information shown when you use this command:
. run-level 3 Jan 14 15:17 3 0 5
The run-level 3 shows your current run level, the Jan 14 15:17 shows when your machine started at the current run level, the 3 is the run level again, the 0 is for the times the machine has been in this run level, and the 5 is where the last run level would be.
last reboot shows history of reboots
There are many ways to change the run level, and they are as follows: <stop> a, halt, power off, and reboot (ones in bold are actual commands). The preceding are not preferred because they dont save work in progress. The preferred way is to use the init command.
To use the init command, type init [run level you want] (i.e. init 6 for reboot) to run init you must be in root. Another safe way to shut the computer down is to do the command shutdown (this command warns users and gives a time delay) syntax of shutdown command: shutdown g [time period in seconds] y i [init run level, only 0,1,5,6 can be used]. The y tells the computer to do it, this is needed (sample command: shutdown g 300 y i 6 this command would take the computer to run level 6 (init state) in 300 seconds.
/etc/init.d holds service file info
/etc/acct holds login, logout info to start
To start any service go into /etc/init.d and type [service name] start, or to stop type [service name] stop (i.e. /etc/init.d/lp stop would stop the printing service). /etc/init.d doesnt hold service files, just how to start and shut services down. /etc/init.tab defines run levels and actions. Basically, this tells UNIX which services are to run at which init level. The format for the /etc/init.tab file is: 53:23:wait:/sbin/rc3 the 53 is a unique identifier between 1-9999, the : separates the fields, the next field (23) is the run level field, in this case the line will apply to run level 2 and 3, the next field is argument field (the different arguments are wait, foreground-run in top window, respawn-will make the service run in the background, respawn bg will never allow the command to die, sysinit will run the service only when the system is powering up, initdefault will set the default run level, powerfail sets the time to stop which is used with a UPS (universal power supply), the last field is what to run. The first services to run are ones with sysinit, then initdefault, then whatever is in its default (i.e. 3), then it will run commands that have run level 3 in the run level field. To see what information is in this file, do cat /etc/inittab | more. Usually when you run level [0,1,2,3,5 or 6] you will run the rc[0,1,2,3,5 or 6] script with the same number (i.e. you are at run level 3, so you will be running the rc3 script (in /etc). rd5 and rc6 refer to rc0 (not well known, this is an internet daemon to be a web server)
Sample services that are running under different run levels:
Run level |
Service |
|
LP | Htpd | |
0 | Stop | Stop |
2 | Stop | Stop |
3 | Start | Stop |
5 | Start | Start |
/etc/rc0.d/k01lp--> this file is just a link to /etc/init.d
/etc/ro0.d/k02httpd (same as above)
The underlined from the above, k means kill, an s would mean start the service. The number immediately after the k is the order to run in. So to edit what services run at what levels, you will edit the /etc/rc0.d/K01lp (in the part after rco.d, the K01lp, the K is for kill line printing service (an S would start) first (the K or S must be in caps), when the machine is put in init state (or run level) 0. All of this is the same as typing /etc/init.d/lp stop. To run a service (lets use the imaginary service New UNIX Service or nus) you need to decide what run levels you want it to start and stop at. So in our example we dont want it run at init state 0 or 5, and we want it to run at init state 2 and 3. We would edit (make the file in /etc/rc[init level].d dir), i.e. /etc/rc0.d/k01nus, /etc/rc5.d/K01nus, /etc/rc2.d/S01nus, and /etc/rc3.d/S01nus. Next we would need to provide a link for our file, so ln [what service to add] [which rc to move to then K or S to kill or start, the order to run service] i.e.: ln /etc/init.d/nus /etc/rc0.d/K00nus
ln /etc/init.d/nus /etc/rc2.d/S99nus
When starting services you want them after 60 80 in the order listed. To see the changes you make look up in directory
/etc/init.d
/etc/rc2.d
Type init 6 to reboot
Go to Chapter 10
Go to Index
Go to Chapter 12