14.8 Adding a Program to Run at Boot Time

   

To add a program to your system so that it executes at a particular runlevel involves a few steps. First, an execution script for starting and stopping a program is installed in the /sbin/init.d directory. This directory contain scripts for all daemons and services. The execution script contains the four major parts that are passed as command line arguments to these scripts.

start_msg Displayed on the console when starting the script.
stop_msq Displayed on the console at stop time of the script.
start Command to start the program.
stop Command to stop the program.

These scripts have configuration files in the /etc/rc.config.d directory that are used for setting the appropriate variables and options for these scripts. You must place a configuration file for the execution script in this directory. An execution script for the cron daemon (used for scheduling jobs) is /sbin/init.d/cron and is shown here.

 #!/sbin/sh # Start cron case  in 'start_msg')         echo "Start clock daemon"         ;; 'stop_msg')         echo "Stop clock daemon"         ;; 'start')         if [ -f /etc/rc.config.d/cron ] ; then                 . /etc/rc.config.d/cron         fi         if [ $CRON -eq 1 ] ; then                 /usr/sbin/cron         fi         ;; 'stop')         PID=`ps -el  grep croncut -c 10-14`         Kill $PID ;; *)         echo "usage: 
 #!/sbin/sh # Start cron case $1 in 'start_msg') echo "Start clock daemon" ;; 'stop_msg') echo "Stop clock daemon" ;; 'start') if [ -f /etc/rc.config.d/cron ] ; then . /etc/rc.config.d/cron fi if [ $CRON -eq 1 ] ; then /usr/sbin/cron fi ;; 'stop') PID=`ps -el  grep croncut -c 10-14` Kill $PID ;; *) echo "usage: $0 {startstop}" ;; esac exit 
{startstop}" ;; esac exit

Once the script is installed, you need to decide at which runlevel it should be activated. HP-UX has directories with names /sbin/rc n .d , where n represents a runlevel. These directories are called sequencer directories. You place a link to your script in these directories. If you want to start your script at runlevel 3, you will place a link in the /sbin/rc3.d directory. You have to put one link for starting the script and another one for stopping it.

Sequencer Directories

A sequencer directory represents a particular runlevel. For example, /sbin/rc2.d contains links to scripts that need to be started or stopped when the system moves to runlevel 2. Every link starts with the S or K character. The files starting with S show that the scripts will be started when the system enters in this runlevel, while those scripts starting with K show that it will be stopped ( killed ). After the S or K character, there is a number that shows the sequence in which the script will be started or stopped. A typical link for starting the cron daemon is:

 /sbin/rc2.d/S730cron 

This shows that cron will be started in runlevel 2. The number 730 is the sequence number.

HP-UX executes scripts in the sequencer directories in the order of the sequence number. A script having a sequence of less than 730 will be executed earlier than the cron .

A typical sequencer script to stop the cron daemon is as follows .

 /sbin/rc1.d/K270cron 

It is located in the rc1.d directory showing that it will be executed when the system goes to runlevel 1. It starts with K , representing that it is a stop (kill) script. As you can see, the start and stop sequence numbers need not be the same. The "kill" links should be one runlevel behind the corresponding "start" link.

Configuration Files

Script configuration files are placed in the /etc/rc.config.d directory. These files are used by the sequencer scripts to check configuration for a particular daemon and usually have the same name as their corresponding script in the /sbin/init.d directory. The configuration file for the cron daemon is:

 #!/sbin/sh # @(#) $Revision: 72.3 $ # Cron configuration.  See cron(1m) # # CRON:         Set to 1 to start cron daemon # CRON=1 

When this file is sourced by its execution script, it assigns the value 1 to the CRON variable, showing that the cron daemon is enabled. Assigning a value 0 means that the daemon is disabled. If you make a change to a configuration file and later want to restore it, you can copy the original file from the /usr/newconfig/etc/rc.config.d directory.


   
Top


HP Certified
HP Certified: HP-UX System Administration
ISBN: 0130183741
EAN: 2147483647
Year: 2000
Pages: 390
Authors: Rafeeq Rehman

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net