If you serve as an admin over Linux systems, one tool that you’ll fall back on daily is systemctl. Jack Wallen shows you how easy it is to list services with this command.
Linux is an incredibly powerful system with GUI and command-line tools to meet nearly any need. Once upon a time, managing running systems was a bit more challenging on the open-source operating systems because the previous init system required administrators to use a hodgepodge of methods and tools to start, stop, run, and monitor services. With the advent of systemd, that all changed such that admins had a much easier means of controlling the multitude of services their applications and services depend on.
SEE: 40+ open source and Linux terms you need to know (TechRepublic Premium)
Consider this: With a growing list of services running on your servers, how do you know which of those services are running successfully and which have failed? You could go through the tedious process of running
systecmtl status SERVICE (where SERVICE is the name of the service in question) for every service installed on your system. That, of course, is simply not an option for anyone who has a regular day of crazy ahead of them.
So, what do you do? Is there a way to easily check in on those services? There is, and I’m going to show you.
What you’ll need
The only things you’ll need to follow along are a running instance of any Linux distribution that uses systemd as its init system and a user with sudo privileges. That’s it. Let’s check in on those services.
How to list all active services
The first thing we’ll do is list all active services. Log into your Linux server and issue the command:
sudo systemctl list-units --type service
What we’re listing above are services. You can list other types of units, such as sockets (–type socket), mount points (–type mount), and devices (–type device).
The output of the command will list out five columns of information, which are:
- UNIT–The name of the unit.
- LOAD–If the unit has been loaded into memory.
- ACTIVE–The activation state (active, reloading, inactive, failed, activating, deactivating).
- SUB–The low-level activation state (such as dead, exited, failed, inactive or running).
- DESCRIPTION–A short description of the unit.
As you can see (in Figure A), you’ll get plenty of information from the command, including all of the active services and their current states.
If you want a listing of every unit on the system (including those that are loaded and active and those that aren’t loaded), the command would be:
sudo systemctl list-unit-files
The nice thing about the above command is that it clearly marks any system in red that’s currently disabled (Figure B).
If you find something isn’t working on your server, but can’t remember the exact name of that service, this is a great way to quickly find out what it is. Once you’ve discovered a service that has a questionable status, you can get more information by viewing only that service with systemctl, like so:
sudo systemctl status SERVICE
Where SERVICE is the name of the service in question.
For example, when I run the first command, I can see that the lynis service has failed. To find out more I can issue the command:
sudo systemctl status lynis
I should be presented with enough information (Figure C) to help me start troubleshooting the problem.
Every failed service will give you a different clue as to why it failed. The important thing here is that you have the ability to troubleshoot more easily.
And that’s all there is to using systemctl to list all services on a Linux server or desktop for easier troubleshooting. The systemctl command should become an invaluable component of your admin toolkit for all Linux machines.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.