System Administration Guide

Run Control Scripts

The Solaris software environment provides a detailed series of run control (rc) scripts to control run level changes. Each run level has an associated rc script located in the /sbin directory:

For each rc script in the /sbin directory, there is a corresponding directory named /etc/rcn.d that contains scripts to perform various actions for that run level. For example, /etc/rc2.d contains files used to start and stop processes for run level 2.


# ls /etc/rc2.d
K20spc@             S70uucp*            S80lp*
K60nfs.server*      S71rpc*             S80spc@
K76snmpdx*          S71sysid.sys*       S85power*
K77dmi*             S72autoinstall*     S88sendmail*
README              S72inetsvc*         S88utmpd*
S01MOUNTFSYS*       S73nfs.client*      S89bdconfig@
S05RMTMPFILES*      S74autofs*          S91leoconfig*
S20sysetup*         S74syslog*          S92rtvc-config*
S21perf*            S74xntpd*           S92volmgt*
S30sysid.net*       S75cron*            S93cacheos.finish*
S47asppp*           S76nscd*            S99audit*
S69inet*            S80PRESERVE*        S99dtlogin*

The /etc/rcn.d scripts are always run in ASCII sort order. The scripts have names of the form:

[K,S][0-9][0-9][A-Z][0-99]

Files beginning with K are run to terminate (kill) a system process. Files beginning with S are run to start a system process.

Run control scripts are also located in the /etc/init.d directory. These files are linked to corresponding run control scripts in the /etc/rc*.d directories.

The actions of each run control script are summarized in Table 6-5.

Using a Run Control Script to Stop or Start Services

One advantage of having individual scripts for each run level is that you can run scripts in the /etc/init.d directory individually to turn off functionality without changing a system's run level.

How to Use a Run Control Script to Stop or Start a Service

  1. Become superuser.

  2. Turn off functionality.


    # /etc/init.d/filename stop
    
  3. Restart functionality.


    # /etc/init.d/filename start
    
  4. Use the ps and grep commands to verify whether the service has been stopped or started.


    # ps -ef | grep service
    

Example--Using a Run Control Script to Stop or Start a Service

Turn off NFS server functionality by typing:


# /etc/init.d/nfs.server stop
# ps -ef | grep nfs
#

Restart the NFS services by typing:


# /etc/init.d/nfs.server start
# ps -ef | grep nfs
root   141     1 40   Jul 31 ?     0:00 /usr/lib/nfs/statd
root   143     1 80   Jul 31 ?     0:01 /usr/lib/nfs/lockd
root   245     1 34   Jul 31 ?     0:00 /usr/lib/nfs/nfsd -a 16
root   247     1 80   Jul 31 ?     0:02 /usr/lib/nfs/mountd
root  1324  1318 11 13:29:52 pts/0 0:00 grep nfs

Adding a Run Control Script

If you want to add a run control script to start and stop a service, copy the script into the /etc/init.d directory and create links in the rc*.d directory you want the service to start and stop.

See the README file in each /etc/rc*.d directory for more information on naming run control scripts. The procedure below describes how to add a run control script.

How to Add a Run Control Script

  1. Become superuser.

  2. Add the script to the /etc/init.d directory.


    # cp filename /etc/init.d
    
  3. Create links to the appropriate rc*.d directory.


    # cd /etc/init.d
    # ln filename /etc/rc2.d/Snnfilename
    # ln filename /etc/rcn.d/Knnfilename
    
  4. Use the ls command to verify that the script has links in the specified directories.


    # ls /etc/init.d/ /etc/rc2.d/ /etc/rcn.d/
    

Example--Adding a Run Control Script


# cp xyz /etc/init.d
# cd /etc/init.d
# ln xyz /etc/rc2.d/S100xyz
# ln xyz /etc/rc0.d/K100xyz
# ls /etc/init.d /etc/rc2.d /etc/rc0.d

Disabling a Run Control Script

Disable a run control script by renaming it with a dot (.) at the beginning of the new file name. Files that begin with a dot are not executed. If you copy a file by adding a suffix to it, both files will be run.

How to Disable a Run Control Script

  1. Become superuser.

  2. Rename the script by adding a dot (.) to the beginning of the new file.


    # cd /etc/rcn.d
    # cp filename .filename
    
  3. Verify the script has been renamed.


    # ls -a 
    # .filename
    

Example--Disabling a Run Control Script

The following example changes the K00ANNOUNCE script name but saves the original script.


# cd /etc/rc0.d
# cp K00ANNOUNCE .K00ANNOUNCE