The replacement of service and Chkconfig in Linux Systemctl

Source: Internet
Author: User
Tags centos

The Systemctl command was discovered recently while playing Ubuntu and openSUSE, and later found in the demo Centos7, Systemctl is a tool under SYSTEMD. The order has been in existence for a long time. This command is used to replace the service and chkconfig two commands---although the individual feels that the latter is useful.

In order to adapt to the development of time, summed up here. In many new Linux distributions, the system does not use the SystemV form for the Daemon startup management method, but uses the SYTEMD architecture to manage daemon startup.

One, runlevel to target change

In the SYSTEMD management system, the concept of the previous run level (RunLevel) was replaced by a new operating target (target). Tartget's name is similar to the multi-user.target, such as the original run Level 3 (RUNLEVEL3) corresponds to the new multiuser target (multi-user.target), run levels 5 is equivalent to Graphical.target.

Because the Runlevle concept is no longer used,/etc/inittab is no longer used by the system---No wonder inittab files are not found in the new version of Ubuntu.
In the SYSTEMD management system, the default target (equivalent to the previous default run level) is implemented through a soft chain. Such as:

Ln-s/lib/systemd/system/runlevel3.target/etc/systemd/system/default.target
The purpose of defining runlevelx.target files under/lib/systemd/system/is primarily to be able to manage methods that are compatible with previous run level levels. In fact,/lib/systemd/system/runlevel3.target is also a soft connection to multi-user.target.

Note: Under the openSUSE is under the/usr/lib/systemd/system/directory.

Second, Unit control (units)

In the SYSTEMD management system, the daemon that calls for management are units (unit). The management of Units (unit) is controlled by command Systemctl. For example, displays the current running state of the unit (that is, daemon), such as:

#systemctl
#systemctl--all
#systemctl list-units--type=sokect
#systemctl list-units--type=service
Note: Types that can be followed by type can be viewed by help

361way:~ # SYSTEMCTL-T Help
Available Unit Types:
Service
Socket
Target
Device
Mount
AutoMount
Snapshot
Timer
Swap
Path
Slice
Scope
Iii. systemctl Usage and examples

The difference between Chkconfig, service command and Systemctl command is shown in the following table:

Task Old instructions New instructions
Make a service start automatically Chkconfig--level 3 httpd on Systemctl Enable Httpd.service
Make a service not start automatically Chkconfig--level 3 httpd off Systemctl Disable Httpd.service
Check Service status Service httpd Status

Systemctl status httpdservice (Services details)

Systemctl is-active Httpd.service (show whether active only)

Add Custom Service Chkconfig--add Test Systemctl Load Test.service
Delete Service Chkconfig--del XXX Deactivate the application, and delete the corresponding configuration file
Show all started services Chkconfig--list Systemctl list-units--type=service
Start a service Service httpd Start Systemctl Start Httpd.service
Stop a service Service httpd Stop Systemctl Stop Httpd.service
Restart a service Service httpd Restart Systemctl Restart Httpd.service

Note: The service name after Systemctl can be viewed in the/usr/lib/systemd/system directory (openSUSE), and other distributions are located under/lib/systemd/system/.

openSUSE under
361way:~ # SYSTEMCTL Status Network.service
Network.service-lsb:configure network interfaces and set up routing
Loaded:loaded (/usr/lib/systemd/system/network.service; enabled)
Active:active (exited) since Mon 2014-09-01 CST; 2h 14min ago
process:1022 execstart=/etc/init.d/network Start (code=exited, status=0/success)
Sep 20:05:15 LINUX-PNP8 systemd[1]: Starting Lsb:configure network and set up interfaces ...
Sep 20:05:15 LINUX-PNP8 network[1022]: Setting Up network interfaces:
Sep 20:05:15 linux-pnp8 network[1022]: Lo
Sep 20:05:15 linux-pnp8 network[1022]: Lo IP ADDRESS:127.0.0.1/8
Sep 20:05:45 LINUX-PNP8 network[1022]:.. Done.. Done..  Donesetting up service network.  .  .  .  .  .  .  .  .  .  .  . . Done
Sep 20:05:45 LINUX-PNP8 systemd[1]: Started Lsb:configure network and set up interfaces.
CentOS under
# SYSTEMCTL Status Httpd.service
Httpd.service-the Apache HTTP Server (prefork MPM)
loaded:loaded (/lib/systemd/system/httpd.service; disabled)
Active:inactive (dead) <--indicates not started
Cgroup:name=systemd:/system/httpd.service
The above two commands are equivalent to/etc/init.d/network status and/etc/init.d/httpd Status,opensuse and CentOS, except that the paths are displayed differently. Other operations are similar.

Iv. Service configuration Files

As an example of the Httpd.service configuration mentioned above, the following lines can be found in the Httpd.service file:

[Install]
Wantedby=multi-user.target
Indicates that it starts automatically when a multiuser target (multi-user.target, equivalent to LEVEL3) is started. If you want to start from under RunLevel 5, you can change the configuration to read as follows:

[Install]
Wantedby=multi-user.target Graphical.target
Once the automatic startup (Enbale) is set up, a httpd.service soft connection is built under the/etc/systemd/system/.wants/, which is connected to the corresponding service under/lib/systemd/system/. So the unit (similar to the results of the Chekconfig--list command) showing the auto start state can be found in the following ways:

#ls/etc/systemd/system/multi-user.target.wants/
Systemctl's summary is written here, which is a tool in the SYSTEMD package and is the most commonly used tool in the package. Back to Systemd to do a summary.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.