Manipulating the start and stop order of Linux services
This document (7002295) is provided subject to the disclaimer at the end of this document.
SUSE Linux Enterprise Desktop 10
- In some circumstances, the start and stop order of a service needs to be manipulated.
- How to add start and stop orders to a custom service
The start and stop scripts are found in /etc/init.d. In the header for the script, you should see something similar:
### BEGIN INIT INFO # Provides: myService # Required-Start: $network # Should-Start: # Required-Stop: # Should-Stop: # Default-Start: 2 3 5 # Default-Stop: # Description: Example Service ### END INIT INFO
The comments above are used by the insserv package to define what the service needs. The "Provides:" line is a pseudo name that can be referenced in other scripts in the "Required-Start,""Should-Start,""Required-Stop," and "Should-Stop" fields.
There are ways to manipulate certain services.
- "$" before a service name refers to a group of services that comprise the pseudo name. These are defined in /etc/insserv.conf.
- "$ALL" is a reserved name that will make a service run last
- "+" means that the service is optional or that failure of the service will not prevent the referencing service from starting or stopping
Do NOT modify the .depend.* files in /etc/init.d directly. Doing so can render a system unbootable.
In /etc/init.d/rc?.d directories have the order of the start and stop. The first letter and subsequent two numbers in the name of the file will define the start and stop order. For example, S05myService and S05myService2 would be started at the same time; S05myService and S06myService2 would mean that myService would start before myService2. There is a tendency to manipulate the number of these files directly. This IS NOT advised. Anytime you run "chkconfig" or "insserv" these files will be renamed. It is much better use the LSB method.
Here are few examples of how to manipulate the header of a service defined in /etc/init.d.
The following example will start Service "myService" after the network has loaded and will automatically start the service "myOtherService"
### BEGIN INIT INFO # Provides: myService # Required-Start: $network # Should-Start: myOtherService # Required-Stop: # Should-Stop: # Default-Start: 2 3 5 # Default-Stop: # Description: Example Service ### END INIT INFO
The following example will start the service "myService" last
### BEGIN INIT INFO # Provides: myService # Required-Start: $ALL # Should-Start: # Required-Stop: # Should-Stop: # Default-Start: 2 3 5 # Default-Stop: # Description: Example Service ### END INIT INFOThe following example will start the service "myService" after the network and the optional component "myOtherService"
### BEGIN INIT INFO # Provides: myService # Required-Start: $network +myOtherService # Should-Start: # Required-Stop: # Should-Stop: # Default-Start: 2 3 5 # Default-Stop: # Description: Example Service ### END INIT INFOdefining pseudo services
In /etc/insserv.conf, pseudo service that are referenced with the "$" in the service scripts are defined. In the event that you need to add a collection of service scripts and reference them only once, they can be added to the insserv.conf file. This is useful for customization to certain environments.
For example, if you want to run your firewall rule script every time the network is started, you can modify /etc/insserv.conf to make $network reference "network" and "myFirewall." Assuming that there is a valid script in /etc/init.d with the permissions of 0755, you would change it from:
There is one special keyword in the file -- <interactive>. Any service name with <interactive> will require user intervention.
making the services run sequentially
In order to speed the boot process, services are started and stopped in parallel. Under the vast majority, there is no reason to change this behavior. However, if there are problems with this you can change /etc/sysconfig/boot -- simply find the parameter RUN_PARALLEL="YES" to "NO"
making the changes effective
After changing the script, you need to run two commands. Replace "myService" with the name of the file you modified.
- insserv myService
- chkconfig myService on
When changing any provided script from a third-party, the changes may and most likely will be over written during a service pack upgrade or a new version of the service. Generally SUSE does not release a new version of the /etc/init.d scripts, but it may happen from time to time.
adding a custom script
When a custom script, the permissions of the file need to be 0755 (-rwxr-xr-x).
This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.
- Document ID:7002295
- Creation Date: 06-Jan-2009
- Modified Date:24-Feb-2021
- SUSE Linux Enterprise Desktop
- SUSE Linux Enterprise Real Time
- SUSE Linux Enterprise Server
For questions or concerns with the SUSE Knowledgebase please contact: email@example.com