RHEL7.0 Series Service Control

Source: Internet
Author: User

SYSTEMD is an init program for Linux, which can be used as an alternative to sysvinit and Upstat.

The primary command for RHEL7 to monitor and control systemd is Systemctl, which can be used to view system status and manage systems and services.

RHEL7 Service systemctl script is stored in:/usr/lib/systemd/, the system and the users (user) points, such as the need to boot without logging on to run the program, there are system services, namely:/usr/lib/systemd/ The system directory. Each service ends with a. Service and is typically divided into 3 parts: [Unit], [service], and [Install]

650) this.width=650; "Style=" border-bottom:0px; border-left:0px; border-top:0px; border-right:0px "title=" image "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M02/6E/66/ Wkiom1v62cgj0vitaafzhg-tbc0188.jpg "" "height=" 377 "/>

The [Unit] section is primarily a description of the service, including description and after,description for describing the service, after which is used to describe the service category

The [Service] section is the service of the key, is the service of some specific operating parameters of the settings, here type=forking is the form of the background run, Pidfile for the file path to store the PID, Execstart for the service of the specific Run command, Execreload is the overloaded command, Execstop is the Stop command, note: The [Service] section of the start, restart, stop command all require absolute path, use relative path will be error!

The [Install] section is a set of settings for a service installation that can be set to multi-user.

Note: If the service does not have an install paragraph, it generally means that they should be automatically called through other services

Note: The user-defined service script, as written above, is saved in the/usr/lib/systemd/system directory with 754 permissions, and the dependencies can be configured with Systemctl:

When using SYSTEMD, you can resolve their dependencies by writing the unit configuration file correctly. Typically, unit a requires unit B to run before a starts. In this case, add requires=b and after=b to the [unit] segment in the cell a configuration file. If this dependency is optional, you can add wants=b and after=b. Note that wants= and requires= do not imply after=, that is, if the after= option is not established, the two units will be started in parallel. Dependencies are typically used on services (service) rather than targets.

Starting mode:

When you write a custom service file, you can choose several different ways to start your services. The startup mode can be set through the type= parameter in the configuration file [Service] segment. Refer to man systemd.service for specific parameter descriptions.

Type=simple:systemd that the service will start immediately. If the service is to start another service, do not use this type to start unless the service is socket-activated.

Type=forking:systemd believes that when the service process is fork and the parent process exits, the service starts successfully. For a regular daemon (daemon), use this type to start. Use this startup type to specify pidfile= at the same time so that SYSTEMD can track the main process of tracking.

Type=oneshot: This option applies to services that perform only one task and then exit. You may need to set remainafterexit=yes at the same time so that Systemd still thinks the service is active after the service process exits.

Type=notify: Same as Type=simple, but the contract service sends a signal to SYSTEMD when it is ready. The implementation of this notification is provided by libsystemd-daemon.so.

Type=dbus: If started in this manner, when the specified busname appears on the Dbus system bus, SYSTEMD considers the service ready.

We are not unfamiliar with the service and chkconfig two commands, the RHEL7 system Systemctl is the main tool of the control service, it integrates the Chkconfig and service functions in one.

The basic operation format of the SYSTEMCTL command is:

Systemctl Action Service name.

Take a look at--help's information

SYSTEMD provides a better framework to represent the dependencies between system services to implement parallel startup of services when the system is initialized, and to reduce the overhead of the shell, systemd the goal is to start fewer processes as much as possible, and to start more processes in parallel.

SYSTEMD unit Type (systemctl--type= unit type, used to filter units):

Service: Manage the back-office service;

Mount (Mount) auto Mount (automount): Used to mount the file system;

Target: operational level;

Socket (socket): Used to create a socket, and immediately after accessing the socket, using the dependency relationship to start another unit indirectly;

Analyze System Status:

Systemctl or Systemctl list-units #输出激活的单元

Systemctl list-units--type=service #列出active状态的服务

Systemctl list-unit-files List all installed services

Systemctl--failed #显示启动失败的服务

SYSTEMD-CGLS lists the running processes in a tree, which can recursively display control group content

All available cell files are stored in the/usr/lib/systemd/system/and/etc/systemd/system/directories (the latter with higher precedence)

Use the unit:

A unit can be a system service (. Service), Mount Point (. Mount), sockets (. Sockets).

When using the Systemctl control unit, you typically need to use the full name of the cell file, including the extension (for example, Sshd.service). However, some units can use shorthand in Systemctl. If there is no extension, systemctl defaults to the extension as. Service. For example, sshd and Sshd.service are equivalent.

The mount point is automatically converted to the corresponding. Mount unit. For example,/home is equivalent to Home.mount.

The device is automatically converted to the corresponding. Device unit, so/dev/sda2 is equivalent to Dev-sda2.device.

Systemctl Start < units > #立即启动单元

Systemctl Stop < unit > #立即停止单元

Systemctl Restart < units > #重启单元

Systemctl Reload < units > #重新读取单元配置

Systemctl Status < units > #输出单元运行状态

Systemctl is-enabled < units > #检查单元是否配置为自动启动

Systemctl Enable < units > #开机自动启动单元

Systemctl Disable < units > #取消开机自动激活单元

Systemctl is-active< units > #查看单元是不是正在运行

Systemctl daemon-reload #重新载入 systemd, scan for new or changed units

Power Management:

Systemctl reboot #重启

Systemctl Poweroff #退出系统并停止电源

For example:

Systemctl is-enabled Iptables.service
Systemctl is-enabled Servicename.service #查询服务是否开机启动
Systemctl Enable *.service #开机运行服务
Systemctl Disable *.service #取消开机运行
Systemctl Start *.service #启动服务
Systemctl Stop *.service #停止服务
Systemctl Restart *.service #重启服务
Systemctl Reload *.service #重新加载服务配置文件
Systemctl Status *.service #查询服务运行状态

Systemctl Mask *.service #禁用指定服务

Systemctl unmask *.service #激活指用服务

Note: * Represents the name of a service, such as HTTP service name httpd

Case:

View the status of a service

650) this.width=650; "Style=" border-bottom:0px; border-left:0px; border-top:0px; border-right:0px "title=" image "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M00/6E/66/ Wkiom1v62cgtx8-jaaeukg4obyu177.jpg "" "height=" 168 "/>

Stop the SSHD service and view the status

650) this.width=650; "Style=" border-bottom:0px; border-left:0px; border-top:0px; border-right:0px "title=" image "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M01/6E/66/ Wkiom1v62chc8od6aafbmj9iewc408.jpg "" "height=" 183 "/>

The status indicates that the dead service has stopped.

Disable service, no boot autorun

650) this.width=650; "Style=" border-bottom:0px; border-left:0px; border-top:0px; border-right:0px "title=" image "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M02/6E/62/wKioL1V622qzS3q_ Aae561ffxza787.jpg "" "height=" 174 "/>

Boot auto-load and start the service

650) this.width=650; "Style=" border-bottom:0px; border-left:0px; border-top:0px; border-right:0px "title=" image "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M02/6E/66/ Wkiom1v62chqc-isaacqcir2uwg565.jpg "" Height= "/>"

Disable the service through mask so that once the service terminates, it can no longer be started and must be de-disabled by unmask to run the service using SYSTEMCTL start sshd

650) this.width=650; "Style=" border-bottom:0px; border-left:0px; border-top:0px; border-right:0px "title=" image "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M00/6E/66/ Wkiom1v62cljbj1waafnlzjyaqe674.jpg "" "height=" 242 "/>

In addition to the basic functionality mentioned above, SYSTEMCTL can also query the currently loaded module unit, noting that the suffix service is the one we need to manage

650) this.width=650; "Style=" border-bottom:0px; border-left:0px; border-top:0px; border-right:0px "title=" image "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M01/6E/62/ Wkiol1v622rjyp3xaaev8zcfzw8501.jpg "" "height=" 185 "/>

You can filter out other types of cells by type

Systemctl List-unit-files–type Service

RHEL7.0 Series Service Control

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.