How to use the command 'chkconfig' (with examples)

How to use the command 'chkconfig' (with examples)

The ‘chkconfig’ command is used to manage the runlevel of services on CentOS 6. It allows users to view the runlevel of services, enable/disable services at boot, and specify which runlevels a service should start on.

Use case 1: List services with runlevel

Code:

chkconfig --list

Motivation:

This example is useful when you want to view all the services and their runlevels on the system.

Explanation:

The --list option is used to display a list of all services and their corresponding runlevels.

Example Output:

ntpd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
httpd           0:off   1:off   2:off   3:on    4:off   5:off   6:off

Use case 2: Show a service’s runlevel

Code:

chkconfig --list ntpd

Motivation:

This example is useful when you want to check the specific runlevel configuration of a service, in this case, ’ntpd’.

Explanation:

The --list option is used to display the runlevel configuration of a specific service.

Example Output:

ntpd            0:off   1:off   2:on    3:on    4:on    5:on    6:off

Use case 3: Enable service at boot

Code:

chkconfig sshd on

Motivation:

This example is useful when you want to enable the ‘sshd’ service to start automatically at boot.

Explanation:

The ‘sshd’ argument represents the service name, and the ‘on’ argument enables the service to start at boot time.

Example Output:

No output, as this command does not produce any output when successful.

Use case 4: Enable service at boot for runlevels 2, 3, 4, and 5

Code:

chkconfig --level 2345 sshd on

Motivation:

This example is useful when you want to specify specific runlevels in which the ‘sshd’ service should start automatically at boot.

Explanation:

The ‘–level 2345’ option specifies the runlevels for which the service should start, and the ‘on’ argument enables the service to start at boot time.

Example Output:

No output, as this command does not produce any output when successful.

Use case 5: Disable service at boot

Code:

chkconfig ntpd off

Motivation:

This example is useful when you want to disable the ’ntpd’ service from starting automatically at boot.

Explanation:

The ’ntpd’ argument represents the service name, and the ‘off’ argument disables the service from starting at boot time.

Example Output:

No output, as this command does not produce any output when successful.

Use case 6: Disable service at boot for runlevel 3

Code:

chkconfig --level 3 ntpd off

Motivation:

This example is useful when you want to specify a specific runlevel in which the ’ntpd’ service should not start automatically at boot.

Explanation:

The ‘–level 3’ option specifies the runlevel for which the service should be disabled, and the ‘off’ argument disables the service from starting at boot time.

Example Output:

No output, as this command does not produce any output when successful.

Conclusion:

The ‘chkconfig’ command is a useful tool for managing the runlevel of services on CentOS 6. It allows users to easily enable/disable services at boot and specify the runlevels for service startup. By understanding the various use cases and their corresponding commands, users can efficiently configure the behavior of services on their system.

Related Posts

Using CTest Command (with examples)

Using CTest Command (with examples)

CTest is a test driver program that comes with CMake, a popular build system generator.

Read More
How to use the command fileicon (with examples)

How to use the command fileicon (with examples)

The fileicon command is a tool used to manage custom file and folder icons on macOS.

Read More
How to use the command `cdk` (with examples)

How to use the command `cdk` (with examples)

The cdk command is a CLI (Command Line Interface) tool for the AWS Cloud Development Kit (CDK).

Read More