How To Start, Stop and Get Status of Linux Service With Systemd?
Services are all over the Linux world. Enterprise Linux world turn over services. There are different tools to manage Linux services like Sys-V, upstart, systemd etc. Systemd is gaining popularity in recent times. Fedora, CentOs, RedHat uses systemd for a long time. Ubuntu started to use systemd too. Here we will look into basics of the service management with systemd.
List Installed Services
We want to see installed services so we will start the services with its exact name.
[root@cen1 conf]# systemctl list-units
UNIT LOAD ACTIVE SUB DESCRIPTION
proc-sys-fs-binfmt_misc.automount loaded active waiting Arbitrary Executable File Formats File System Automou
sys-devices-pci0000:00-0000:00:03.0-virtio0-net-eth0.device loaded active plugged Virtio network device
sys-devices-pci0000:00-0000:00:04.0-sound-card0.device loaded active plugged 82801FB/FBM/FR/FW/FRW (ICH6 Family) High Definition
sys-devices-pci0000:00-0000:00:05.0-virtio1-virtio\x2dports-vport1p1.device loaded active plugged /sys/devices/pci0000:00/0000:00
sys-devices-pci0000:00-0000:00:05.0-virtio1-virtio\x2dports-vport1p2.device loaded active plugged /sys/devices/pci0000:00/0000:00
sys-devices-pci0000:00-0000:00:07.0-virtio2-block-vda-vda1.device loaded active plugged /sys/devices/pci0000:00/0000:00:07.0/virt
sys-devices-pci0000:00-0000:00:07.0-virtio2-block-vda.device loaded active plugged /sys/devices/pci0000:00/0000:00:07.0/virtio2/b
sys-devices-platform-serial8250-tty-ttyS1.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS1
sys-devices-platform-serial8250-tty-ttyS2.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS2
sys-devices-platform-serial8250-tty-ttyS3.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS3
sys-devices-pnp0-00:04-tty-ttyS0.device loaded active plugged /sys/devices/pnp0/00:04/tty/ttyS0
- In systemd services are named unit so we use systemctl list-units command.
- As we see there information about service status like active
Get Status of a Service
Now we can know exact names of the services. We want to get detailed information about httpd service.
[root@cen1 conf]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Çrş 2016-11-02 10:39:21 UTC; 1h 20min ago
Main PID: 11753 (httpd)
Status: "Total requests: 394; Current requests/sec: 0; Current traffic: 0 B/sec"
├─11753 /usr/sbin/httpd -DFOREGROUND
├─11755 /usr/sbin/httpd -DFOREGROUND
├─11756 /usr/sbin/httpd -DFOREGROUND
├─11757 /usr/sbin/httpd -DFOREGROUND
├─11758 /usr/sbin/httpd -DFOREGROUND
├─11759 /usr/sbin/httpd -DFOREGROUND
├─11775 /usr/sbin/httpd -DFOREGROUND
├─11777 /usr/sbin/httpd -DFOREGROUND
├─11778 /usr/sbin/httpd -DFOREGROUND
├─11779 /usr/sbin/httpd -DFOREGROUND
└─11780 /usr/sbin/httpd -DFOREGROUND
Kas 02 10:39:21 cen1 systemd: Starting The Apache HTTP Server...
Kas 02 10:39:21 cen1 httpd: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, u...message
Kas 02 10:39:21 cen1 systemd: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
- systemctl status is the command to get status information
- httpd is the service we want to see status information.
- Active:active means it is running currently
- At the bottom we can see latest logs generated by httpd service
We can start httpd service easily like below
[root@cen1 conf]# systemctl start httpd
The easiest part of managing services is stopping them. We can stop them like start
[root@cen1 conf]# systemctl stop httpd
After making configuration changes about services we need to stop and start service. The practical way is just restarting service like below.
[root@cen1 conf]# systemctl restart httpd