United States (change)
Shortcuts: Downloads Fedora Red Hat Network
Account Links: Cart Your Account Logout
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.