Crmgo Blog

Autostart in CentOS

Autostart in CentOS

In CentOS gibt es den Dienst chkconfig, um Dienste (Anwendungen) zur Autostart-Liste hinzuzufügen. Dies gilt unter der Voraussetzung, dass diese Dienste aus dem Repository mit dem Befehl yum installiert wurden. Um den Autostart zu aktivieren, also damit die Anwendung beim Starten des Servers (beim Booten des Betriebssystems) gestartet wird, muss der folgende Befehl ausgeführt werden…

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 via 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 a service, for example, httpd, 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

Level 0 — system halt — the system's operation must be stopped;
Level 1 — single-user mode — the system initializes a minimum number of services and provides the command line to a single user (usually the superuser) without authentication. Typically, this mode is used for system recovery;
Level 2 — multi-user mode — users can work on different terminals, with system login involving authentication;
Level 3 — multi-user networked mode — unlike the previous level, network configuration is performed and various network services are started; (primarily used on server systems)
Level 4 — has no standard definition and is rarely used;
Level 5 — graphical subsystem startup — compared to level 3, the X11 graphical subsystem is also started, and the system login occurs in graphical mode;
Level 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 of 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 имя_службы

Hinweis: Dieser Beitrag kann KI-unterstützt erstellt und anschließend redaktionell geprüft worden sein. Verantwortlich: Dmytro Lomaka, Kaltenkirchen.