Startup and shutdown scripts for HP-UX 11.x are based on a mechanism that separates the actual startup and shutdown scripts from configuration information. In order to modify the way your system starts or stops, you don't have to modify scripts, which in general is considered somewhat risky; you can instead modify configuration variables . The startup and shutdown sequence is based on an industry standard that is similar to many other UNIX-based systems, so your knowledge of HP-UX applies to many other systems. Startup and shutdown are going to become increasingly more important to you as your system administration work becomes more sophisticated. As you load and customize more applications, you will need more startup and shutdown knowledge. What I do in this section is give you an overview of startup and shutdown and the commands you can use to control your system. The following components are in the startup and shutdown model:
Figure 7-1 shows the directory structure for startup and shutdown scripts. Figure 7-1. Organization of Startup and Shutdown Files
Execution scripts perform startup and shutdown tasks . /sbin/rc invokes the execution script with the appropriate start or stop arguments, and you can view the appropriate start or stop messages on the console. The messages you see will have one of the three following values:
In order to start up a subsystem, you would simply edit the appropriate configuration file in /etc/rc.config.d . Let's take a look at an example startup and shutdown file for an application loaded onto an HP-UX system that is widely used for Internet applications called Cold Fusion. Like many applications loaded on HP-UX systems, Cold Fusion installs startup and shutdown scripts as a standard part of the installation of the product. As mentioned earlier, the script used as part of the startup and shutdown process is in /etc/init.d . In our case, the name of the program is /etc/init.d/coldfusion and is shown in the following listing: # cat /sbin/init.d/coldfusion #!/bin/sh # # Start the Cold Fusion servers # # set at install CFHOME=/apps/coldfusion CFBIN=$CFHOME/bin export CFHOME # # Start/stop processes for Cold Fusion # rval=0 case "" in start_msg) print "Starting ColdFusion Application Server" ;; stop_msg) print "Stopping ColdFusion Application Server" ;; 'start') #First, check "on/off switch", to set CF_AUTOSTART, in config.d file. RCFILE=/etc/rc.config.d/coldfusion if [ -f $RCFILE ] ; then . $RCFILE else print "Warning: $RCFILE defaults file missing." print " Starting ColdFusion by default." CF_AUTOSTART=1 fi # Start CF if switch is on. if [ "$CF_AUTOSTART" -eq 1 ]; then if [ -x $CFBIN/start ]; then $CFBIN/start rval=$? else print "Error: ColdFusion startup script $CFBIN/start missing." print " ColdFusion not started." rval=1 fi else print "Notice: ColdFusion startup disabled in $RCFILE" rval=2 fi ;; 'stop') if [ -x $CFBIN/stop ]; then $CFBIN/stop -force fi ;; *) echo "Usage: The startup and shutdown scripts in /etc/init.d generally perform both startup and shutdown functions. The startup and shutdown scripts, including the one in our example, recognize the following four arguments:
You may encounter problems during boot with one of the startup programs being hung. If this is the case Ctrl ( control and pipe ) keys will normally break out of the script and continue to the next script. All startup and shutdown scripts, including the one in the previous listing, obtain configuration data from variables in /etc/rc.config.d . Our example script checks the value of the "on/off" switch in /etc/rc.confi.d/coldfusion , which is shown in the following listing, to determine if Cold Fusion should be started: # cat /etc/rc.config.d/coldfusion # ColdFusion Application Server configuration file # CF_AUTOSTART=1 #Set to 1 to restart at boot time # The variable in this file is set to 1, so the application will start at the time of system boot. Startup and shutdown scripts are run based on the directory in which a link to the script appears. Our example script should be started at run level 3 . Therefore, a link to the script appears in the directory /sbin/rc3.d , shown as the third link in the following listing: [View full width]
We'll get to the significance of the naming of the link shortly. For the time being, it is sufficient to know that a link called /sbin/rc3.d/S790coldfusion points to our script /init.d/coldfusion . Applications are shut down in the opposite order from which they were started. This means that a link to the startup and shutdown script will appear in a lower-level directory for shutdown. In our example, the startup link appears in /sbin/rc3.d but the shutdown link appears in /etc/rc1.d , as shown in the following listing: # ls -l /sbin/rc1.d lrwxr-xr-x 1 root sys 17 Apr 26 14:52 K220slsd -> /sbin/init.d/slsd lrwxr-xr-x 1 root sys 18 Apr 26 14:45 K230audio -> /sbin/init.d/audio lrwxr-xr-x 1 root sys 21 Apr 26 14:46 K240auditing -> /sbin/init.d/auditing lrwxr-xr-x 1 root sys 17 Apr 26 14:43 K250envd -> /sbin/init.d/envd lrwxr-xr-x 1 root sys 17 Apr 26 14:43 K270cron -> /sbin/init.d/cron lrwxr-xr-x 1 root sys 15 Apr 26 14:45 K278pd -> /sbin/init.d/pd lrwxr-xr-x 1 root sys 15 Apr 26 14:45 K280lp -> /sbin/init.d/lp lrwxr-xr-x 1 root sys 21 Apr 26 14:49 K290hparamgr -> /sbin/init.d/hparamgr lrwxr-xr-x 1 root sys 20 Apr 26 14:43 K290hparray -> /sbin/init.d/hparray lrwxrwxrwx 1 root sys 20 May 16 20:57 K300coldfusion -> ../init.d/coldfusion . . . The link called /sbin/rc3.d/K300coldfusion points to our script /init.d/coldfusion . Startup for this application takes place at run level 3 and shutdown takes place at run level 1. There is significance associated with the names of the links shown in the previous two listings. Let's take a look at the startup link in our example: /sbin/rc3.d/S790coldfusion v script name - coldfusion in ex v sequence number - 790 in example v "S" for startup, "K" for shutdown v run level number - 3 in example This example is for our Cold Fusion startup script. Startup links begin with an "S" for startup . The shutdown script has a similar entry in /sbin/rc1.d , it but has a "K" as the first character of the link name to indicate kill . Scripts are executed in lexicographical order. Gaps are left between startup scripts at a given run level and between shutdown scripts at a given run level, so when additional scripts are added, you don't have to renumber any existing scripts within a run level. Because applications are shut down in the opposite order in which they are started, shutdown scripts do not usually have the same numbers as their startup counterparts. Two applications that start in a given order due to dependencies will usually be shut down in the opposite order in which they were started. In our example, the startup number is S790coldfusion and the shutdown number is K300coldfusion .
[View full width]
If you are booting your system to run level 3, then /sbin/rc will run the startup scripts present in /sbin/rc1.d , /sbin/rc2.d , and /sbin/rc3.d . I have mentioned run levels several times in this discussion. Both the startup and shutdown scripts described here, as well as the /etc/inittab file, depend on run levels. In HP-UX 11.x, the following run levels exist:
Entries in the /etc/inittab file have the following format:
Here is an example of an /etc/inittab entry:
The basics of system startup and shutdown described here are important to understand. You will be starting up and shutting down your system and possibly even modifying some of the files described here. Please take a close look at the startup and shutdown files before you begin to modify them. Now let's take a look at the commands you can issue to shut down your system. |