Saturday, 22 March 2014

Starting and Stopping Software via RC Directories

 STARTING AND STOPPING SOFTWARE VIA RC DIRECTORIES

Question

How can I start up and stop my software on AIX?

Answer:

Starting and Stopping Software via RC Directories

This document describes how to start and stop software using run level directories via /etc/inittab. A run level is a software configuration that allows only a selected group of processes to exist.

For another method to start or stop an application during a reboot or shutdown, refer to the document, Automated Startup and Shutdown of Custom Software. 

The objective of run level script feature is to allow customers to start and stop selected applications by changing the run level. The directories are provided for customers to place their own stop and start scripts.



Background:


During system startup, after the root file system has been mounted in the pre-initialization process, the init command is run as the last step of the startup process. The init command attempts to read the /etc/inittab file. If the file exists, init attempts to locate an initdefault in /etc/inittab. If initdefault entry exists, the init command uses the specified run level as the initial system run level. Run level 2 is defined by default to contain all of the terminal processes and daemons that are run in the multiuser environment. This can be seen in the /etc/inittab file:
 # lsitab init:
init:2:initdefault:
NOTE: Booting the system into mulitiuser mode using a runlevel other than the default, 2, is not supported by IBM. For a list of valid run levels, see man pages for init or telinit.

Upon the installation of the feature, the following are added to your system:

  1. Nine directories:
    /etc/rc.d
    /etc/rc.d/rc2.d
    /etc/rc.d/rc3.d
    /etc/rc.d/rc4.d
    /etc/rc.d/rc5.d
    /etc/rc.d/rc6.d
    /etc/rc.d/rc7.d
    /etc/rc.d/rc8.d
    /etc/rc.d/rc9.d
  2. Eight new entries are added to your /etc/inittab
    l2:2:wait:/etc/rc.d/rc 2
    l3:3:wait:/etc/rc.d/rc 3
    l4:4:wait:/etc/rc.d/rc 4
    l5:5:wait:/etc/rc.d/rc 5
    l6:6:wait:/etc/rc.d/rc 6
    l7:7:wait:/etc/rc.d/rc 7
    l8:8:wait:/etc/rc.d/rc 8
    l9:9:wait:/etc/rc.d/rc 9
    The system will automatically run the "K" or kill scripts when entering a given run level, then proceed to run all "S" or start scripts to start up the applications necessary at that level. In this manner, some applications could be stopped while others started when entering a run level.

  3. When shutting down the system or rebooting using the /usr/sbin/shutdown command, all "K" or kill scripts for every run level will be run. This ensures all custom applications are finished before fully shutting down AIX. 

  4. /etc/rc.d/rc script - This script is designed to use the input run level to visit the appropriate /etc/rc.d/rc.d. It first executes scripts in this directory starting with K to stop the applications. Then, it executes scripts starting with S to start the applications.
Sample scripts are provided in the /etc/rc.d/samples directory. See the Commands Reference for information about /etc/inittab, telinit, and init command.

Scripts to stop or start applications


  1. Create a shell script that includes the commands (provided by the application vendor) to stop or start that program. To use the scripts, the user must copy them to the appropriate /etc/rc.d/rc.d directory. The /etc/rc.d/rc shell script will only vist the directory structures under rc.d.

  2. NOTE: The script name must start with a K to stop or an S to start the application.

  3. Make the script executable by running the chmod command.
  4. In both cases, it is adviseable to use a file naming convention with a numeric after the K or S, and a short description of the process or service to be killed or started. The controlling RC script will run these in numeric order as it finds them. For example, a script to stop and start lpd daemon can be named K70lpd and S70lpd, respectively.

  5. The run level can be changed by running:
  6.  telinit 
    
    This tells the init command to place the system in one of the run levels. When the init command requests a change to run levels 0-9, it kills all processes at the current run levels and then restarts any processes associated with the new run levels.

    To check current run level, run who -r. It will return something similar to the following output:
     run level 2 Oct 4 14:23  2 0 S
    In this example, the system is running at the default run level 2.

0 blogger-disqus:

Post a comment