Linux get service list

How to list all enabled services from systemctl?

How can I list all enabled services from systemctl ? I know running systemctl command by itself lists all services, but I would like to only get the enabled ones.

Fascinating. The lowest rated answer is the most «correct» answer, even though it is clearly not the best answer. This excellent question (and its answers) is an interesting example of how systemd violates the long-standing (and brilliant) design principles of Unix & Co. @FelipeAlvarez complains that the most-accepted answer assumes systemd follows the unix design philosopy, but systemd/systemctl can do exactly what he wants (most experienced users will just consider that complete bloat). I begin to see more clearly why Linus Torvalds is so vehemently critical of systemd.

If you want to list «templated» services (blabla@instance.service), do not forget to add «—all» — thanks to @rafdouglas below.

9 Answers 9

systemctl list-unit-files | grep enabled will list all enabled ones.

If you want which ones are currently running, you need systemctl | grep running .

Use the one you’re looking for. Enabled, doesn’t mean it’s running. And running doesn’t mean it’s enabled. They are two different things.

Enabled means the system will run the service on the next boot. So if you enable a service, you still need to manually start it, or reboot and it will start.

Running means it’s actually running right now, but if it’s not enabled, it won’t restart when you reboot.

annoying to have to use an external tool (grep) to show this vital information. But thank you for showing us the way 🙂

@FelipeAlvarez Correct. But that’s how Linux works. Many small binaries that work well with each other. systemctl does what is asked, it lists services. There is no filtering command built-in to systemctl because grep already exists and can do that well with any program’s output. It’s how it’s always been 🙂

I agree and so it should be. But, systemd already tries to do SO much that I wonder why it can’t list enabled services?

Читайте также:  Screen utility in linux

systemctl | grep running do not list anything to me! Even if something is running is only listed as for his status like: enabled, disabled, masked, static

—state=

The argument should be a comma-separated list of unit LOAD , SUB , or ACTIVE states. When listing units, show only those in the specified states. Use —state=failed to show only failed units.

LOAD : Reflects whether the unit definition was properly loaded.
ACTIVE : The high-level unit activation state, i.e. generalization of SUB .
SUB : The low-level unit activation state, values depend on unit type.

Though you can also use this to only show enabled units with:

systemctl list-unit-files --state=enabled 

If a unit is enabled that means that the system will start it on startup. Though setting something to enabled doesn’t actually also start it so you will need to do that manually, or reboot the system after setting it to enabled .

Источник

How to List Services in Ubuntu Server / Desktop

In this tutorial we are going to learn how to list services in Ubuntu using the command line interface. We will see how we can list running services and services that are not running.

List Ubuntu Services with Service command

The service —status-all command will list all services on your Ubuntu Server (Both running services and Not running Services).

This will show all available services on your Ubuntu System. The status is [ + ] for running services, [ — ] for stopped services.

List Ubuntu Services with Service command

Using the grep command, we can filter the output to show only the running services.

To list ubuntu services that are not running, Type,

The service command can be used to list services in all Ubuntu releases, including (Ubuntu 17, 16.04, and 14.04).

List Services with systemctl command

Since Ubuntu 15, the services are managed by the systemd. With systemd we can use systemctl command to get information about running services in our Ubuntu system.

To list all running services on Ubuntu, Type:

The output of the command will look something like this:

UNIT LOAD ACTIVE SUB DESCRIPTION apache2.service loaded active running LSB: Apache2 web server apparmor.service loaded active exited LSB: AppArmor initialization cron.service loaded active running Regular networking.service loaded active exited Raise network interfaces nmbd.service loaded active running LSB: start Samba NetBIOS nameserver (nmbd) smbd.service loaded active running LSB: start Samba SMB/CIFS daemon (smbd) ssh.service loaded active running OpenBSD LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type. 

To list all services, including inactive units, Type:

Читайте также:  Linux как изменить файл командная строка

To List inactive unit, Type:

systemctl list-units -a --state=inactive

The systemctl command does not work for Ubuntu 14.04 and earlier releases, instead use the service —status-all command mentioned above.

Источник

How to List All Running Services Under Systemd in Linux

Linux systems provide a variety of system services (such as process management, login, syslog, cron, etc.) and network services (such as remote login, e-mail, printers, web hosting, data storage, file transfer, domain name resolution (using DNS), dynamic IP address assignment (using DHCP), and much more).

Technically, a service is a process or group of processes (commonly known as daemons) running continuously in the background, waiting for requests to come in (especially from clients).

Linux supports different ways to manage (start, stop, restart, enable auto-start at system boot, etc.) services, typically through a process or service manager. Most if not all modern Linux distributions now use the same process manager: systemd.

Systemd is a system and service manager for Linux; a drop-in replacement for the init process, which is compatible with SysV and LSB init scripts, and the systemctl command is the primary tool to manage systemd.

In this guide, we will demonstrate how to list all running services under systemd in Linux.

Listing Running Services Under SystemD in Linux

When you run the systemctl command without any arguments, it will display a list of all loaded systemd units (read the systemd documentation for more information about systemd units) including services, showing their status (whether active or not).

List Systemctl Units in Linux

To list all loaded services on your system (whether active; running, exited, or failed, use the list-units subcommand and —type switch with a value of service.

# systemctl list-units --type=service OR # systemctl --type=service

List All Services Under Systemd

And to list all loaded but active services, both running and those that have exited, you can add the —state option with a value of active, as follows.

# systemctl list-units --type=service --state=active OR # systemctl --type=service --state=active

List All Active Running Services in Systemd

But to get a quick glance at all running services (i.e. all loaded and actively running services), run the following command.

# systemctl list-units --type=service --state=running OR # systemctl --type=service --state=running

List Running Services in Systemd

If you frequently use the previous command, you can create an alias command in your ~/.bashrc file as shown, to easily invoke it.

Читайте также:  Linux mint установка nvidia driver

Then add the following line under the list of aliases as shown in the screenshot.

alias running_services='systemctl list-units --type=service --state=running'

Create a Alias for Long Command

Save the changes in the file and close it. And from now onwards, use the “running_services” command to view a list of all loaded, actively running services on your server.

# running_services #use the Tab completion

View All Running Services

Besides, an important aspect of services is the port they use. To determine the port a daemon process is listening on, you can use the netstat or ss command as shown.

Where the flag -l means print all listening sockets, -t displays all TCP connections, -u shows all UDP connections, -n means print numeric port numbers (instead of application names) and -p means show the application name.

# netstat -ltup | grep zabbix_agentd OR # ss -ltup | grep zabbix_agentd

The fifth column shows the socket: Local Address:Port. In this case, the process zabbix_agentd is listening on port 10050.

Determine Process Port

Also, if your server has a firewall service running, which controls how to block or allow traffic to or from selected services or ports, you can list services or ports that have been opened in the firewall, using the firewall-cmd or ufw command (depending on the Linux distributions you are using) as shown.

# firewall-cmd --list-services [FirewallD] # firewall-cmd --list-ports $ sudo ufw status [UFW Firewall]

List Open Services and Ports on Firewall

That’s all for now! In this guide, we demonstrated how to view running services under systemd in Linux. We also covered how to check the port service is listening on and how to view services or ports opened in the system firewall.

Do you have any additions to make or questions? If yes, reach us using the comment form below.

Источник

Оцените статью
Adblock
detector