From the course: Cert Prep: LPIC-1 Exam 101 (Version 5.0)

Get systemd service status - Linux Tutorial

From the course: Cert Prep: LPIC-1 Exam 101 (Version 5.0)

Start my 1-month free trial

Get systemd service status

- [Instructor] System D manages system services in CentOS 7. It also manages a lot of other objects like devices, system timers and targets, the System D equivalent to runlevels. System D Objects are called units and for each unit there's a unit file for configuration. For this course, we are only concerned with service units and service unit files. The command that System D uses to manage these units is systemctl. To look at our service unit files type into a terminal, "systemctl list-unit-files -at service" and hit enter. By default, list-unit-files -t service will show all enabled service unit files. Enabled meaning services that are configured to start up automatically. By adding -a, it will show both enabled and disabled service unit files. Notice that the systemctl sub-command is "list-unit-files". This means we're just looking at the unit files and their status. We're not yet looking at the running status of services. The output will be in two columns. The first column is the service name. The second column is the service state, which can be either enabled, disable or static. Enabled means that we'll start automatically at boot. Disabled means that we'll not start automatically. Static means the service is not enabled and has no provision to be enabled. Some services are not meant to start automatically. Press "Q" to quit. Let's get more information about enabled services. Type in "systemctl list-units -at service" and hit enter. By default, list-units -t service shows enabled running services. By the including the "-a" it will also show enabled non-running services. If you disable and stop a service it will not longer show up here. The output has five columns. The first column is the service name. The second column shows if the unit file was loaded. The third column, or active column, shows the general state of the service. The fourth column, or sub-column, shows us more detailed information about it's state including whether it's running or not. And the last column shows the description. Press "Q" to quit. We can filter by the state of the service. For instance, if we wanted to only list services that were active and currently running we can type in "systemctl list-unit -t service --state running" and hit enter. You'll notice the naming convention of the service files. In this case, rsyslog.service. All service files end with ".service". Press "Q" to quit. You can view any of these unit files to get an idea how they work, I'm going to choose the rsyslog.serivce. Type in "clear" and then type in "systemctl cat rsyslog" and hit enter. Notice the service log was rsyslog.service, but the command worked without the extension. What we see here is the unit file which determines the service dependencies, what command it executes and what the service should do if the command fails. We can also get the status of a single service as well, typing "clear" again and hit enter. Type in "systemctl status rsyslog" and hit enter. This gives us the status of the service when it started, what the process id number is and some log messages.

Contents