SUSE Support

Here When You Need Us

Manipulating the start and stop order of Linux services

This document (7002295) is provided subject to the disclaimer at the end of this document.

Environment

SUSE Linux Enterprise Server 11
SUSE Linux Enterprise Server 10

Situation

  • 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

Resolution

Under the LSB (Linux Standards Base), the start and stop order of services is controlled using the "insserv" package. Unlike Netware, DOS and other operating systems, SUSE calculates the start and stop orders based on dependencies. This idiosyncrasy of Linux has the distinct advantage of providing a faster boot time, but does make things a little more complex. 

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
If the script lacks the information above (such as a custom script) then you can add it. All LSB-compliant scripts should have a similar header. The only files that should not have this header are any of the .depend.* and boot.local, and after.local.

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
warning

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.
 

Additional Information

examples

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 INFO
The 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 INFO
defining 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:
$network   network
to
$network   network   myFirewall

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.
  1. insserv myService
  2. chkconfig myService on
changing third-party provided services

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).

Disclaimer

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:15-Aug-2022
    • SUSE Linux Enterprise Desktop
    • SUSE Linux Enterprise Real Time
    • SUSE Linux Enterprise Server

< Back to Support Search

For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com

tick icon

SUSE Support Forums

Get your questions answered by experienced Sys Ops or interact with other SUSE community experts.

tick icon

Support Resources

Learn how to get the most from the technical support you receive with your SUSE Subscription, Premium Support, Academic Program, or Partner Program.

tick icon

Open an Incident

Open an incident with SUSE Technical Support, manage your subscriptions, download patches, or manage user access.