📜  show services linux - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:34:58.488000             🧑  作者: Mango

Show Services on Linux - Shell-Bash

If you are a developer working on Linux machines, you might have come across the need to check what are the running services or daemons on a particular machine. This is where the "systemctl" command comes into play. By using this command, we can check the status of any service, restart it, or even disable it from running at startup. In this article, we will dive into the usage of "systemctl" command and explore different ways to check the services running on a Linux machine.

Checking the status of a service

The "systemctl status" command can be used to check the status of any service on a Linux machine. Let's say we want to check the status of the "httpd" service, we can use the following command:

systemctl status httpd

The output should look something like this:

● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2021-08-08 14:17:04 PDT; 1h 23min ago
     Docs: man:httpd.service(8)
 Main PID: 818 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
    Tasks: 213 (limit: 4915)
   Memory: 24.6M
   CGroup: /system.slice/httpd.service
           ├─818 /usr/sbin/httpd -DFOREGROUND
           ├─819 /usr/sbin/httpd -DFOREGROUND
           ├─820 /usr/sbin/httpd -DFOREGROUND
           ├─821 /usr/sbin/httpd -DFOREGROUND
           └─822 /usr/sbin/httpd -DFOREGROUND

Aug 08 14:17:04 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Aug 08 14:17:04 localhost.localdomain httpd[818]: Server configured, listening on: port 80
Aug 08 14:17:04 localhost.localdomain systemd[1]: Started The Apache HTTP Server.

We can see that the "httpd" service is running and its status is "active (running)".

Listing all services

We can list all the running services on a Linux machine by using the "systemctl" command with the "list-units" option. This will list all the units (services, targets, devices, etc.) loaded into system:

systemctl list-units --type=service

The output will be a list of all active and inactive services:

UNIT                                LOAD   ACTIVE SUB     DESCRIPTION
abrt-ccpp.service                   loaded active exited  Install ABRT coredump hook
abrt-oops.service                   loaded active running ABRT kernel oops Watcher
abrt-vmcore.service                 loaded active exited  Harvest vmcores for ABRT
...
Listing all enabled services

We can also list all the enabled services running at startup by using the following command:

systemctl list-unit-files --type=service | grep enabled

The output will look something like this:

httpd.service    enabled
mariadb.service  enabled
sshd.service     enabled
...

In this example, we can see that "httpd", "mariadb", and "sshd" services are enabled to run at startup.

Conclusion

In this article, we explored how to use the "systemctl" command to check the status of running services, list all services, and list all enabled services on a Linux machine. This is an essential skill for any developer working on Linux machines, and can help troubleshoot issues related to running services. We hope you found this article useful and informative!