DEV Community

Cover image for How to check if a service is enabled with systemctl command
howtouselinux
howtouselinux

Posted on • Updated on

How to check if a service is enabled with systemctl command

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.

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
Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

...

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

Enter fullscreen mode Exit fullscreen mode

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.

Follow us on Google News to get the latest Linux skills.

Google News - howtouselinux - howtouselinux

Read full articles from howtouselinux and explore endless topics and more on your phone or tablet with Google News.

favicon news.google.com

Top comments (0)