How to Manage a Linux Server with systemdTo control services with systemd, the systemctl command is used. Let’s go over how to start, stop, restart, enable and disable, and check the status of a service. We’ll use the Apache Service, known as httpd on RedHat Based Linux distributions as an example.
Unless there is a failure running some of these commands, they will not output any results, this is expected. Commands expected to have output will be noted.
This will only start a service one time, if you want the service to be started on boot, see the “Enable on Boot” command below.
systemctl start httpd
This will only stop a service one time, if you want the service to not be restarted on boot, see the “Disable on Boot” command below.
systemctl stop httpd
Fully stops and starts a service:
systemctl restart httpd
Reloads a service’s configuration without causing the service to restart. Not all services accept that reload command.
systemctl reload httpd
- Enable on Boot:
This will set the specified service to start up every time a system is booted up.
systemctl enable httpdExample output:
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /etc/systemd/system/httpd.service.
- Disable on Boot:
This will set the specified service to not start up every time a system is booted up.
systemctl disable httpdExample output:
Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.
- Check Status:
systemctl status httpdExample output:
● httpd.service - Apache web server managed by cPanel EasyApache Loaded: loaded (/etc/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2018-01-26 13:32:15 EST; 20h ago Main PID: 2988 (httpd) CGroup: /system.slice/httpd.service ├─ 2988 /usr/sbin/httpd -k start ├─30142 /usr/sbin/httpd -k start ├─30143 /usr/local/cpanel/3rdparty/bin/perl /usr/local/cpanel/bin/leech... ├─30144 /usr/sbin/httpd -k start ├─30145 /usr/sbin/httpd -k start ├─30219 /usr/sbin/httpd -k start ├─30220 /usr/sbin/httpd -k start └─30221 /usr/sbin/httpd -k start Jan 26 13:32:15 test.example.com systemd: Starting Apache web server managed .... Jan 26 13:32:15 test.example.com systemd: PID file /run/apache2/httpd.pid not.... Jan 26 13:32:15 test.example.com systemd: Started Apache web server managed b.... Hint: Some lines were ellipsized, use -l to show in full.
More Information:More information on using systemctl, and other portions of systemd can be found in several Linux manual pages, primarily systemctl(1). Here’s a short example of the command to view the manual page, and the first few lines of that page:
man 1 systemctl
SYSTEMCTL(1) systemctl SYSTEMCTL(1) NAME systemctl - Control the systemd system and service manager SYNOPSIS systemctl [OPTIONS...] COMMAND [NAME...] DESCRIPTION systemctl may be used to introspect and control the state of the "systemd" system and service manager. Please refer to systemd(1) for an introduction into the basic concepts and functionality this tool manages.