Add a package to startup on Debian/ Ubuntu/ Red Hat/ CentOS

Add a package to startup on Debian/ Ubuntu/ Red Hat/ CentOS

Get Social!

Linux penguin Most versions and distributions of Linux today have a start up manager application to easily set which programs are started when your Linux machine boots up. There are two distinct flavours of start up applications and a manual method for distributions without this feature installed.

Using a terminal and the command chkconfig on CentOS, Red Hat and Oracle Enterprise Linux; and update-rc.d on Debian and Ubuntu you can control which packages are available as services and which packages start with your computer.

Run Level

Before looking at the commands used to control startup services in Linux, it’s important to understand when a program should be running in relation to the current operating system state. For example, you probably don’t want your Apache service being started before you have networking.

Linux has the concept or a runlevel which dictates the state of the operating system as a number between 0 and 6 inclusive.

See my post on runlevels to understand when your application or service should be asked to start.

Start up with Red Hat, CentOS and Oracle Enterprise Linux

Controlling startup services in Linux distributions such as Red Hat Enterprise Linux (RHEL), CentOS and Oracle Enterprise Linux (OEL) is done using the chkconfig command.

See my chkconfig cheat sheet for more information on controlling startup services on RHEL based Linux.

Start up with Debian and Ubuntu

Debian and Ubuntu based Linux distributions use the command update-rc.d to control which services are started during machine boot.

For details of controlling such services, see my update-rc.d cheat sheet.

Start up for manually setting the start up services

For operating systems that are not managed by an application, such as upstart on Ubuntu, you will need to manually add the /etc/init.d/ start up script to the /etc/rc.local file.

The /etc/rc.local file contains a reference to all the services which are required on machine boot.

Run the below echo command to add a manual start up application. The application name must be the same as the /etc/init.d/ file which must exist.

To remove a service, edit the /etc/rc.local file and manually remove the service name.


Linux Runlevels explained

Tags :

Category : Knowledge

Get Social!

Linux penguinA Linux runlevel dictates the state that the machine is currently operating, and what applications or services should be running at that time. The runlevel is specified as a number between 0 and 6 inclusive.

As your system starts up, it will move up through the runlevels until it reaches it’s desired state. Generally headless installs will be considered fully started at 2 or 3, and desktop GUIs usually at 4 or 5. The following details what each of the default runlevels represent. These are the standard definitions which may be slightly different depending on your Linux distribution.

  • 0 – is described as Halt. your machine will halt when the runlevel is set to 0.
  • 1 – is single-user Mode which is used for administrative tasks before the non-essential services are started.
  • 2 – is the first multi-user mode runlevel and will start some non-essential services. This may, or may not contain networking depending on your Linux distribution.
  • 3 – is a multi-user mode which headless servers usually run at. All essential and non-essential services such as Apache HTTP Server should be running.
  • 4 – is a multi-user mode runlevel which is not used by the default operating system and can be used for user defined purposes.
  • 5 – is when GUI desktops are loaded such as Gnome or KDE.
  • 6 – is the reboot runlevel. the operating system will reboot when runlevel 6 is issued.

You can check your current runlevel with the runlevel command. the below example shows a runlevel of 2.

You can also change the current runlevel manually using the the init command. As an example, your machine will restart if you set the runlevel to 6. Use the following init command to set the runlevel to 6.

Each available runlevel has it’s own directory under /etc staring with rc. Inside the folder is a file, or symlink which controls the respective service. When you add a new service to your operating system startup you are simply adding the services control file to one or more of the runlevel folders.

 


Visit our advertisers

Search

Quick Poll

Which type of virtualisation do you use?
  • Add your answer

Visit our advertisers