Linux systemd--Start/stop/restart service in Rhel/centos 7

Source: Internet
Author: User

One of the major changes in Rhel/centos 7.0 is the switch to systemd. It is used to replace SYSV and upstart in previous versions of Red Hat Enterprise Linux and to manage systems and services. SYSTEMD is compatible with startup scripts for SYSV and Linux standard groups.

Systemd is a system and service Manager under a Linux operating system. It is designed to be backwards compatible with SYSV startup scripts and provides a number of features, such as starting system services in parallel when booting, starting daemons on demand, supporting system state snapshots, or relying on dependent service control logic.

Previous Red Hat Enterprise Linux versions using SYSV initialization or upstart were managed using the Bash init script located in the/etc/rc.d/init.d/directory. In Rhel 7/centos 7, these startup scripts were replaced by service units. The service unit ends with a. service file extension, providing the same purpose as the initialization script. To view, start, stop, restart, enable, or disable system services, you use SYSTEMCTL instead of the old service commands.

Note: For backwards compatibility, the old service command is still available in CentOS 7, which redirects all commands to the new Systemctl tool.

Use Systemctl to start/stop/restart services

To start a service, you need to use the following command:

    1. # Systemctl Start Httpd.service

This will start the httpd service, as far as we are concerned, the Apache HTTP server.

To stop it, you need to use the command as root:

    1. # Systemctl Stop Httpd.service

To restart, you can use the Restart option, which will restart the service if the service is running, and it will start if the service is not running. You can also use the Try-start option, which restarts the service only when the service is already running. Also, the reload option you can have, it will reload the configuration file.

    1. # systemctl Restart Httpd.service
    2. # Systemctl Try-restart Httpd.service
    3. # Systemctl Reload Httpd.service

The commands in our example will look like this:

Check Service status

To check the status of the service, you can use the status option to see here:

    1. # SYSTEMCTL Status Httpd.service

The output is like this:

It tells you every aspect of the service that you are running.

Use the Enable/disable service to control boot boot

You can also use the enable/disable option to control whether a service starts up, with the following command:

    1. # Systemctl Enable Httpd.service
    2. # systemctl Disable Httpd.service

Output results See here:

You can also use the command is-enabled to query whether the service is powered on and started, as follows:

1.# Systemctl is-enabled Servicename.service

Although the adoption of SYSTEMD has been controversial over the past few years, most mainstream distributions have been gradually adopted or intended to be used in the next release. So, it's a useful tool and we need to get familiar with it.

Linux systemd--Start/stop/restart service in Rhel/centos 7

Related Article

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.