Information Technology Reference
In-Depth Information
S
at the beginning of an
rc
script causes the
rc
program to start the service
at the particular run level (in this example, run level 2) by calling the
rc
script
with the start argument.
Likewise, the same
cron rc
script is copied (or linked) into the
/etc/rc0.d
,
/etc/rc1.d
, and
/etc/rcS.d
directories and given the name K40cron. The
K
at the beginning of an
rc
script causes the
rc
program to stop the service at
the particular run level by calling the
rc
script with the
stop
argument.
Note that the number included in the names of the
cron rc
script files are
different. The number provides a method for the
rc
program to start or stop
services in a particular and consistent order. The
rc
scripts with lower num-
bers are executed before the
rc
scripts with higher numbers. This is neces-
sary, as some services might require the presence of other services to operate
properly.
For example, a networking application requires that the networking services
be available. This means that the
rc
script to start the application should
have a higher number than the
rc
script to start the networking. In addition,
services should be stopped in reverse order. In the case of a networking appli-
cation, the
rc
script to stop the application should have a lower number than
the
rc
script to stop the networking.
A copy of all
rc
scripts is placed in the
/etc/init.d
directory. To start or stop
a particular service, the system administrator only has to locate the appro-
priate
rc
script in a single directory.
Adding rc Scripts
The following procedure should be used to add
rc
scripts to a new service:
1.
Write a shell script that will accept the command-line arguments
start
and
stop
along with the appropriate actions to perform those func-
tions.
2.
As the superuser, copy the new
rc
script to the
/etc/init.d
directory.
3.
Determine the run level at which to start the service (typically 2).
4.
Determine the two-digit number to control the start sequence (00
through 99). Look at the other startup
rc
scripts in the appropriate
rc
directory and choose a number that is greater than any required servic-
es but less than any services that will use the new service.
5.
Copy or link the new script from the
/etc/init.d
directory to the
appropriate
rc
directory, giving it a name starting with
S
followed by
the selected two-digit number and then the service name.