Crmgo Blog

Autostart in CentOS

Autostart in CentOS

In CentOS, the chkconfig service is used to add services (applications) to the autostart. This applies to services installed from the repository using the yum command. To enable autostart, i.e., to ensure that the application starts when the server boots (when the operating system loads), you need to execute the following...

Autostart in CentOS

In CentOS, the chkconfig service is used to add services (applications) to the startup sequence, provided that these services were installed from the repository using the yum command.
To enable autostart, i.e., to ensure that the application starts when the server boots (during the operating system startup), you need to execute the following command:

# chkconfig  имя_службы on

However, the capabilities of the chkconfig command are not limited to this. First, let's check if the httpd server, for example, is enabled for autostart:

# chkconfig  --list  httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

In the server's response, we see several runlevels. For some, httpd is enabled, and for others, it is not.

Runlevels in CentOS

Runlevel 0 — system halt — the system's operation must be stopped;
Runlevel 1 — single-user mode — the system initializes a minimal set of services and provides the command line to a single user (usually the superuser) without authentication. Typically, this mode is used for system recovery;
Runlevel 2 — multi-user mode — users can work on different terminals, with system login involving authentication;
Runlevel 3 — multi-user networked mode — unlike the previous level, network configuration is performed and various network services are started; (primarily used on server systems)
Runlevel 4 — has no standard definition and is rarely used;
Runlevel 5 — graphical subsystem startup — compared to runlevel 3, the X11 graphical subsystem is also started, and system login occurs in graphical mode;
Runlevel 6 — system reboot — when this mode is enabled, all running programs are stopped, and the system is rebooted.
To find out the current runlevel, simply execute the runlevel command.

# runlevel
N 3

In my example, the server is at runlevel 3, which is its normal operating mode.

Autostart for specific Linux runlevels

By default, the chkconfig command adds services to autostart for runlevels 2, 3, 4, and 5. If you need to change this order, use the following parameters:

# chkconfig  --level 35 httpd on

Now, the chkconfig command will add the httpd daemon only to runlevels 3 and 5.

Short list of useful applications for the chkconfig utility

Add to autostart

# chkconfig  --add имя_службы

Check if a service is enabled for autostart

# chkconfig  --list имя_службы

Enable a service at all runlevels (2, 3, 4, 5)

# chkconfig  имя_службы on

Enable a service at specific runlevels

# chkconfig  --level 35 имя_службы on

Disable a service at all runlevels (2, 3, 4, 5)

# chkconfig  имя_службы off

Disable a service at specific runlevels

# chkconfig  --level 35 имя_службы off

Remove a service from autostart

# chkconfig  --del имя_службы

Note: This post may be AI-assisted and then human-edited. Editorial responsibility: Dmytro Lomaka, Kaltenkirchen.