How to check if a service is enabled with systemctl command
Tags: linux, devops
Published: 2023-09-14 10:47:44



In the context of systemd, when we say a service is "enabled," it means that the service is configured to start automatically during the system's boot process or when specific conditions are met.

In this article, we will check out how to check if a service is enabled.

{% embed https://www.howtouselinux.com/post/check-if-a-service-is-enabled-in-linux %}

Systemctl is a powerful command-line utility used to manage services, units, and other aspects of the systemd init system in Linux.

It provides a unified and consistent way to interact with system services, targets, sockets, timers, and more.

For example, to check the status of a specific service, use:

`systemctl status servicename`

For example:


```
$ systemctl status postgresql-14
* postgresql-14.service - PostgreSQL 14 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-14.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2023-08-10 06:11:02 GMT; 1 months 0 days ago
Docs: https://www.postgresql.org/docs/14/static/
Process: 9042 ExecStartPre=/usr/pgsql-14/bin/postgresql-14-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 9048 (postmaster)
Tasks: 13 (limit: 100420)
Memory: 1.3G
```


From the output, we can see that postgresl-14 is enabled on this system.

We can also use the systemctl command with the is-enabled option. Replace servicename with the name of the service you want to check:

```
systemctl is-enabled servicename

```
This command will return one of the following:

- enabled: The service is enabled and set to start at boot.
- disabled: The service is disabled and won't start at boot.
- static: The service is enabled but is not meant to start on its own.


For example:

```
$ systemctl is-enabled postgresql-14
enabled
```

If you are not exactly sure about the service name, you can use the following way to get this.

```
systemctl list-unit-files --state=enabled --type=service

```
When you run this command, you'll see a list of services with their names and statuses. The "enabled" state means that these services are configured to start at boot time.

Example output looks like this:

```
UNIT FILE STATE
auditd.service enabled
cronie.service enabled
dbus-org.freedesktop.network1.service enabled
```
...

This output displays the unit file names and their current states (in this case, "enabled"). It's a convenient way to check which services are set to start automatically on your system.

You can combine the above command with grep command to filter and search for specific services more effectively like this.

```
systemctl list-unit-files --state=enabled --type=service |grep postgresl

```
It filters the results to display only the lines that contain the word "postgresl."

You can adapt this approach to search for other specific services or keywords.

{% embed https://www.howtouselinux.com/post/6-underrated-linux-commands-that-deserve-more-attention %}


[Follow us on Google News to get the latest Linux skills.](https://news.google.com/publications/CAAqBwgKMOaltAsw88DLAw?hl=en-US&gl=US&ceid=US%3Aen)
{% embed https://news.google.com/publications/CAAqBwgKMOaltAsw88DLAw?hl=en-US&gl=US&ceid=US%3Aen %}