1. Introduction

chkconfig is a command line utility that manages services on a Linux deployment with a System V initialization manager. It enables us to list available services, enable and disable services, and add or remove services. Additionally, chkconfig enables us to configure which services start at each run level.

However, chkconfig is no longer available as an Ubuntu package by default. This is because Ubuntu transitioned from System V to Upstart in earlier versions (around 10.04) and then to systemd in later releases (around 15.04).

In this article, we’ll explore how chkconfig was used to manage services and the current alternatives to chkconfig on Ubuntu.

2. Managing Services With chkconfig

The chkconfig command utility has a fairly straightforward syntax:

chkconfig [options] [service] [arguments]

Let’s look at some operations with the chkconfig utility.

To begin with, we list all services:

$ chkconfig --list

After that, we can enable, disable, and reset the status of a service at all runlevels with the the respective commands:

$ chkconfig <service> on
$ chkconfig <service> off
$ chkconfig <service> reset

Further, we enable and disable a service at a specific runlevel via the respective on and off operations:

$ chkconfig --level <runlevel> <service> on
$ chkconfig --level <runlevel> <service> off

A runlevel (numbers, 0 to 6) defines different system states on Debian operating systems such as Ubuntu. Runlevels 2 through 5 are for multi-user operations. In contrast, runlevel 0 halts the system, runlevel 1 enables single-user mode access, and runlevel 6 triggers rebooting.

Finally, we can add or remove a service from start-up at all runlevels using the –add and –del flags, respectively:

$ chkconfig --add <service>
$ chkconfig --del <service>

The above commands show some common operations with the chkconfig utility on systems that still run System V init.

Since chkconfig is no longer supported in recent Ubuntu releases that operate on systemd, we can turn to some alternatives:

In the following sections, we provide detailed explanations for each alternative.

3. update-rc.d

In most Linux environments, scripts in /etc/init.d/ enable us to start, stop, or restart services.

Further, during system boot or switching between runlevels, init accesses the scripts from /etc/rcX.d/, where X signifies the runlevel number.

3.1. update-rc.d Example

For instance, let’s install nginx:

$ sudo apt install nginx

Then, we start the nginx service:

$ sudo service nginx start

However, the nginx service remains started even on reboot. To disable this service on boot-up, we can use update-rc.d.

One advantage of update-rc.d is that it automatically handles adding or removing necessary links within /etc/init.d/. To illustrate this, let’s see how /etc/rcX.d/ looks for the nginx service:

$  ls -l /etc/rc?.d/*nginx
lrwxrwxrwx 1 root root 15 Apr 13 12:18 /etc/rc0.d/K01nginx -> ../init.d/nginx
lrwxrwxrwx 1 root root 15 Apr 13 12:18 /etc/rc1.d/K01nginx -> ../init.d/nginx
lrwxrwxrwx 1 root root 15 Apr 13 12:18 /etc/rc2.d/S01nginx -> ../init.d/nginx
lrwxrwxrwx 1 root root 15 Apr 13 12:18 /etc/rc3.d/S01nginx -> ../init.d/nginx
lrwxrwxrwx 1 root root 15 Apr 13 12:18 /etc/rc4.d/S01nginx -> ../init.d/nginx
lrwxrwxrwx 1 root root 15 Apr 13 12:18 /etc/rc5.d/S01nginx -> ../init.d/nginx
lrwxrwxrwx 1 root root 15 Apr 13 12:18 /etc/rc6.d/K01nginx -> ../init.d/nginx

As we can see from the output, the links to the nginx service control scripts in /etc/init.d/ begin with either S or K:

  • S configures the service to start at a given runlevel
  • K means a service is stopped at a certain runlevel

For example, runlevels 0, 1, and 6 within the output, feature a link starting with K, while runlevels 2, 3, 4, and 5 have an S at the beginning of the link.

3.2. Installing update-rc.d

update-rc.d usually comes preinstalled by default on Ubuntu.

If it’s not installed, we get the usual error when trying to run it:

$ update-rc.d
Command 'update-rc.d' not found

In this case, we can install the init-system-helpers package via apt:

$ sudo apt install init-system-helpers

Thus, we install the update-rc.d utility.

3.3. Removing and Adding a Service

To remove a service with update-rc.d, the general syntax uses the remove keyword:

update-rc.d [-f] <service> remove

For instance, disabling the nginx service would require us to delete all its links in the /etc/rcX.d/ directory. Yet, with update-rc.d, we can do this with the remove keyword:

$ sudo update-rc.d -f nginx remove

The -f flag with update-rc.d ensures the removal of links to nginx in the /etc/rcX.d/ directories, even if the original script at /etc/init.d/nginx still exists.

On the other hand, to add a service with update-rc.d, the general syntax uses the defaults keyword:

update-rc.d [-f] <service> defaults

Now, if we want to bring back the nginx service and have it start during boot, we use update-rc.d with the defaults keyword:

$ update-rc.d nginx defaults

This command automatically adds the links for the nginx service.

3.4. Enable and Disable a Service

To disable or enable a service with update-rc.d, the general syntax is:

update-rc.d <service> disable|enable [S|2|3|4|5]

The update-rc.d command with the disable or enable options and runlevels manages the services.

4. systemctl

systemctl is a command-line tool used to manage services under systemd, the init system of modern Linux distributions, including Ubuntu. It replaces the older chkconfig utility used in System V init. As such, it’s a widely recommended alternative to chkconfig on Ubuntu.

systemd includes the systemctl command by default, enabling us to manage services without extra installations.

4.1. Managing Services With systemctl

To start, stop, and restart systemd services with systemctl, we execute the command with the respective subcommand:

$ sudo systemctl start <service>
$ sudo systemctl stop <service>
$ sudo systemctl restart <service>

Then, to control which service starts at boot time, we can enable or disable the service:

$ sudo systemctl enable <service>
$ sudo systemctl disable <service>

Finally, the status subcommand of systemctl enables us to retrieve information regarding a service state, including its process ID (PID), memory consumption, and active configuration:

$ sudo systemctl status <service>

The above commands show how we can use systemctl to manage services fully.

4.2. Managing Targets (Runlevels) With systemctl

systemd employs targets as an alternative to traditional runlevels. These targets define different operational states the system can boot into, similar to how runlevels function in System V init. systemctl provides options to manage these targets.

First, let’s see a table showing System V runlevels and their equivalent target names:

Runlevels Target Units
0 poweroff.target
1 rescue.target
2 multi-user.target
3 multi-user.target
4 multi-user.target
5 graphical.target
6 reboot.target

Let’s look at runlevel (target) operations we can perform with systemctl.

To begin with, we list all target units:

$ sudo systemctl list-units --type target --all

After that, we can get the default target:

$ sudo systemctl get default

Of course, we change the default target with the set-default option:

$ sudo systemctl set-default target_name.target

Finally, we can switch the current target with the isolate command:

$ sudo systemctl isolate target_name.target

The isolate command switches to the target and halts any service associated with that target.

5. Conclusion

In this article, we learned about how chkconfig was used on older Ubuntu releases to manage services. Then, we mentioned and went into detail about two alternatives to chkconfig: update-rc.d and systemctl.

However, while understanding tools like update-rc.d is important, it’s recommended to utilize systemctl as Ubuntu has transitioned to systemd for its service management.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.