System Administration Guide: Basic Administration

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 that is 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 that are used to start and stop processes for run level 2.


# ls /etc/rc2.d
K03samba*          S20sysetup*        S72slpd*            S88utmpd*
K06mipagent*       S21perf*           S73cachefs.daemon*  S89PRESERVE*
K07dmi*            S30sysid.net*      S73nfs.client*      S89bdconfig@
K07snmpdx*         S40llc2*           S74autofs*          S90wbem*
K16apache*         S42ncakmod*        S74syslog*          S91afbinit*
K21dhcp*           S47pppd*           S74xntpd*           S91gfbinit*
K26sshd*           S69inet*           S75cron*            S91ifbinit*
K27boot.server*    S70sckm*           S75flashprom*       S92volmgt*
K28kdc*            S70uucp*           S75savecore*        S93cacheos.finish*
K28kdc.master*     S71ldap.client*    S76nscd*            S94ncalogd*
K28nfs.server*     S71rpc*            S77sf880dr*         S95IIim*
README             S71sysid.sys*      S80lp*              S95svm.sync*
S01MOUNTFSYS*      S72autoinstall*    S80spc*             S98efcode*
S05RMTMPFILES*     S72directory@      S85power*           S99audit*
S10lu*             S72inetsvc*        S88sendmail*        S99dtlogin*

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

[KS][0-9][0-9]*

Files that begin with K are run to terminate (kill) a system service. Files that begin with S are run to start a system service.

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

The actions of each run control script are summarized in the following section.

Run Control Script Summaries

The following sections summarize the run control scripts that are used to start and stop system services when you change run levels.

The /sbin/rc0 Script

The /sbin/rc0 script runs the /etc/rc0.d scripts to perform the following tasks:

The /sbin/rc1 Script

The /sbin/rc1 script runs the /etc/rc1.d scripts to perform the following tasks:

The /sbin/rc2 Script

The /sbin/rc2 script runs the /etc/rc2.d scripts to perform the following tasks, grouped by function:

Local system-related tasks:

Network service or security-related tasks:

Install-related tasks:

Hardware-related tasks:

Transitions the following services between run-level changes:


Note –

Many of the system services and applications that are started at run level 2 depend on what software is installed on the system.


The /sbin/rc3 Script

The /sbin/rc3 script runs the /etc/rc3.d scripts to perform the following tasks:

The /sbin/rc5 and /sbin/rc6 Scripts

The /sbin/rc5 and /sbin/rc6 scripts run the /etc/rc0.d/K* scripts to perform the following tasks:

The /sbin/rcS Script

The /sbin/rcS script runs the /etc/rcS.d scripts to bring the system up to run level S. The following tasks are performed by these scripts:

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 stop system services without changing a system's run level.

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

  1. Become superuser.

  2. Stop the system service.


    # /etc/init.d/filename stop
    
  3. Restart the system service.


    # /etc/init.d/filename start
    
  4. Verify that the service has been stopped or started.


    # pgrep -f service
    

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

For example, you can stop the NFS server daemons by typing the following:


# /etc/init.d/nfs.server stop
# pgrep -f nfs
#

Then, you can restart the NFS server daemons by typing the following:


# /etc/init.d/nfs.server start
# pgrep -f nfs 
141 143 245 247
# pgrep -f nfs -d, | xargs ps -fp
daemon   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

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. Then, create links in the rcn.d directory where you want the service to start and stop.

See the README file in each /etc/rcn.d directory for more information on naming run control scripts. The following procedure 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
    # chmod 0744 /etc/init.d/filename
    # chown root:sys /etc/init.d/filename
    
  3. Create links to the appropriate rcn.d directory.


    # cd /etc/init.d
    # ln filename /etc/rc2.d/Snnfilename
    # ln filename /etc/rcn.d/Knnfilename
    
  4. 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

The following example shows how to add a run control script for the xyz service.


# cp xyz /etc/init.d
# chmod 0744 /etc/init.d/xyz
# chown root:sys /etc/init.d/xyz
# 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

You can disable a run control script by renaming it with an underscore (_) at the beginning of the file name. Files that begin with an underscore or 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 an underscore (_) to the beginning of the new file.


    # cd /etc/rcn.d
    # mv filename _filename
    
  3. Verify that the script has been renamed.


    # ls _*
    # _filename
    

Example—Disabling a Run Control Script

The following example shows how to rename the S100datainit script.


# cd /etc/rc2.d
# mv S100datainit _S100datainit
# ls _*
# _S100datainit