Personal tools
     DOCUMENTATION

FAQ:Changing Service Startup Behavior

From rPath Wiki

Jump to: navigation, search
FAQ
Question: How can I change service startup behavior in rPath Linux?

Contents


You can control the startup behavior of services running on your derivative distribution or software appliance with chkconfig overrides, which are files containing the start and stop settings and runlevels for a particular service. (controlled by the initialization scripts in /etc/init.d)

These override files must be located in the /etc/chkconfig.d directory, and should be named like the service's init script, located in /etc/init.d. For example, to change the startup behavior of the OpenSSH server, sshd, you would create a package that includes the sshd chkconfig override file and installs it to /etc/chkconfig.d.

Create a file, named sshd with you preferred editor, and insert the following line:

# chkconfig: 2345 40 45

The above example sets sshd to run in runlevels 2,3,4, and 5, and also adjusts the priorities down to 40 for activation and 45 for deactivation.

Create a Package

To implement chkconfig overrides in your project, create a new package, edit the recipe using the example provided here to get started.

Once you have saved the recipe, cook it to check for errors, then commit and cook the package to your project's repository.

Finally, add the package to your project's group, cook the group and the override will occur in builds generated from the newly cooked group.

In this example, we'll be creating an override for the Samba service, smb.

Create the package:

[you@yourhost projdir]$ cvc newpkg chkconfig-overrides

Change into the package directory, and edit the override file using your editor of choice:

[you@yourhost projdir]$ cd chkconfig-overrides
[you@yourhost chkconfig-overrides]$ nano smb

The Samba service is disabled by default, with a dash (-) character where the runlevels should be. In this example, we'll start and stop smb in runlevels 2,3,4, and 5 while leaving the priorities at the default settings of 91 and 35.

# chkconfig: 2345 91 35

Save this file, and proceed to creating a chkconfig-overrides.recipe file within the newly created package directory:

[you@yourhost chkconfig-overrides]$ nano chkconfig-overrides.recipe

Use the example recipe content as a start, and modify the values as directed below:

Example Recipe

 
class ChkConfigOverrides(PackageRecipe):
    name = 'chkconfig-overrides'
    version = '1.0'
 
    buildRequires = ['chkconfig:runtime']
 
    def setup(r):
        r.addSource('smb')
        r.Install('smb', '%(sysconfdir)s/chkconfig.d/')
  • Change the class name to something appropriate for your requirements
  • Change name to the name of your package
  • Change the version to suite your requirements
  • Replace occurrences of smb with your actual service name

Cook and Commit Package

Now, cook the recipe:

[you@yourhost chkconfig-overrides]$ cvc cook chkconfig-overrides.recipe

The cook should be successful; if it is not, correct the cause of the error, and try the cook again. When the cook is successful, add the recipe and the override files to the package:

[you@yourhost chkconfig-overrides]$ cvc add chkconfig-overrides smb

Commit and cook the package into your project repository:

[you@yourhost chkconfig-overrides]$ cvc commit --message new override
[you@yourhost chkconfig-overrides]$ cvc cook chkconfig-overrides

Finally, add the new package to your project's group using rBuilder Online or by editing your group recipe, cook the group and generate a new build. Builds and releases including this override package will start and stop the affected services as you have specified in the override files.