Account Links: Cart | Your Account | Logout

Skip to content

Red Hat Knowledgebase

Red Hat Knowledgebase Search:

Updated Within the Last:

New Solutions within the last day New Solutions within the last week New Solutions within the last month

Browse by topics:


Click to View a Topic
Red Hat Applications > Developer Suite > Issue <<  13 of 22 >>

Solution Tools:


Email a Solution Postcard Printer version Submit a comment on this answer Update notifications Request an answer Back

Article Reference

Article ID: 5733
Last update: 07-07-05
Issue:
How do I enable a script to start and stop a service at different runlevels using chkconfig?
Resolution:

In order for a script to interact with chkconfig and the automatic starting and stopping of services at different run levels, it needs two key components.

The first is a commented section that allows the script to be managed by the chkconfig tool. Here is an example:

#!/bin/bash

#
# chkconfig 345 10 90
# description This is where you put a description of your service

In this example, the numbers 345 after the chkconfig directive represent the runlevels that the service will be enabled for by default. In this example the service will be enabled by default for runlevels 3, 4, and 5.

The 10 is the start priority. The lower the number the higher the priority and the sooner a service will be started. The 90 is the stop priority. The lower the number the higher the priority and the sooner a service will be stopped when changing runlevels.

The second essential component is that the script must support being called with the arguments "start" and "stop". The script will be called with "start" as an argument when the service is being started at a given runlevel and "stop" when it is being stopped. Within these functions the script should touch a lock file in the /var/lock/subsys folder. If this is not done, the script will automatically start, but will not stop automatically. This should be done in the following manner:

start() {
  ...
  touch /var/lock/subsys/servicename

}

stop() {
  ...
  rm -f /var/lock/subsys/servicename
}

Once you have created a script that conforms to these two requirements, place a copy of it into the /etc/init.d directory and execute the command:

chkconfig --add servicename

This will register the service and create the necessary links in the appropriate rcX.d directories. You can now administer this service using chkconfig command.


How well did this entry answer your question?


good wrong incomplete out of date
Red Hat Applications > Developer Suite > Issue <<   13  of  22  >>