TranslateProject/sources/tech/20140819 Linux Systemd--Start or Stop or Restart Services in RHEL or CentOS 7.md
2014-08-19 16:22:50 +08:00

3.6 KiB
Raw Blame History

Linux Systemd - Start/Stop/Restart Services in RHEL / CentOS 7

One of the major changes in RHEL / CentOS 7.0 is the swtich to systemd, a system and service manager, that replaces SysV and Upstart used in previous releases of Red Hat Enterprise Linux. systemd is compatible with SysV and Linux Standard Base init scripts.

Systemd is a system and service manager for Linux operating systems. It is designed to be backwards compatible with SysV init scripts, and provides a number of features such as parallel startup of system services at boot time, on-demand activation of daemons, support for system state snapshots, or dependency-based service control logic.

Previous versions of Red Hat Enterprise Linux, which were distributed with SysV init or Upstart, used init scripts written in bash located in the /etc/rc.d/init.d/ directory. In RHEL 7 / CentOS 7, these init scripts have been replaced with service units. Service units end with the .service file extension and serve a similar purpose as init scripts. To view, start, stop, restart, enable, or disable system services you will use the systemctl instead of the old service command.

Note: for backwards compatibility the old service command is still available in CentOS 7 and it will redirect any command to the new systemctl utility.

Start/Stop/Restart Services with systemctl

To start a service with systemctl you will need to use the command like this:

# systemctl start httpd.service

This will start the httpd service, in our case Apache HTTP Server.

To stop it use this command as root:

# systemctl stop httpd.service

To restart you can use either the restart options, it will restart the service if its running or start it if its not running. You can also use the try-restart option that will restart the service only if its already running. Also you have the reload option that will reload the configuration files.

# systemctl restart httpd.service
# systemctl try-restart httpd.service
# systemctl reload httpd.service

The commands in our example look like this:

systemctl start-stop-restart

Checking the status of a service

To check the status of a service you can use the status option like this:

# systemctl status httpd.service

And the output should look like this:

systemctl status

Informing you of various aspects of the running service.

Enable / Disable services to run at boot time

You can also use the enable / disable options to make a service run at boot time, using the command like this:

# systemctl enable httpd.service
# systemctl disable httpd.service

The output looks like this:

systemctl-enable

Although the adoption of systemd has been very controversial in the last few years, slowly most of the major Linux distributions have either adopted or are planning to have it in the next point release, so its a useful tool to get used to.


via: http://linoxide.com/linux-command/start-stop-services-systemd/

作者:Adrian Dinu 译者:译者ID 校对:校对者ID

本文由 LCTT 原创翻译,Linux中国 荣誉推出