Linux Kernel EMD -- start/stop/restart the service in RHEL/CentOS 7
One of the major changes in RHEL/CentOS 7.0 is switching to systemd. It is used to replace SysV and Upstart in the previous versions of Red Hat Enterprise Edition Linux to manage systems and services. Systemd is compatible with the startup scripts of SysV and Linux Standard groups.
Systemd is a system and service manager in a Linux operating system. It is designed to be backward compatible with the SysV STARTUP script and provides a large number of features, such as parallel startup of system services at startup, startup of daemon as needed, and support for system status snapshots, or dependency-based service control logic.
In the previous Red Hat Enterprise Linux version that uses SysV initialization or Upstart, use the bash initialization script in the/etc/rc. d/init. d/directory for management. In RHEL 7/CentOS 7, these startup scripts are replaced by service units. The service unit ends with the extension of the. service file and provides the same purpose as the initialization script. To view, start, stop, restart, enable, or disable system services, use systemctl instead of the old service command.
Note: For backward compatibility, the old service command is still available in CentOS 7, And It redirects all commands to the new systemctl tool.
Use systemctl to start/stop/restart the service
To start a service, run the following command:
- # Systemctl start httpd. service
This will start the httpd service, as far as we are concerned, the Apache HTTP Server.
To stop it, use this command as root:
- # Systemctl stop httpd. service
To restart, you can use the restart option. if the service is running, it restarts the service. If the service is not running, it starts. You can also use the try-start option to restart the service only when the service is running. You can also have the reload option, which reloads the configuration file.
- # Systemctl restart httpd. service
- # Systemctl try-restart httpd. service
- # Systemctl reload httpd. service
The commands in our example will look like the following:
Check service status
To check the service status, you can use the status option. Here:
- # Systemctl status httpd. service
The output result is as follows:
It tells you all aspects of the running service.
Use enable/disable services to control startup
You can also use the enable/disable option to control whether a service is started upon startup. The command is as follows:
- # Systemctl enable httpd. service
- # Systemctl disable httpd. service
The output result is as follows:
Although the adoption of systemd has been controversial over the past few years, most mainstream releases have gradually adopted or intend to use it in the next release. Therefore, it is a useful tool and we need to be familiar with it.
Linux boot mode: systemd upstart sysV
Why is systemd so quickly adopted?