How to list, start and stop services at boot time in Linux Ubuntu/Debian

Updated on 7/1/2023 -Services, also known as daemons, are scripts and programs that run in the background and provide various functionalities, such as MySQL, or web server services (like Tomcat). As the number of services increases over

time, it can be easy to overlook which applications are currently running. Knowing which services start at boot time can be useful if you have noticed that your system is running slow. Some unnecessary background services can consume additional RAM, SWAP memory, and CPU power, leaving less room for important programs. Stopping or preventing these services from starting at boot can improve system performance by freeing up resources.

In this short tutorial, you will learn how to display all Ubuntu startup services at boot time in and how to start and stop them.

Read: How to Access Recovery Mode in Ubuntu Linux 22.04

List startup services at boot time

There are many options that allow us to see the list of services at boot time. We will outline below the most commonly used tools .

1 – systemctl

systemctl is the central management utility that controls the systemd system, manages the services and examine the system state.
In order to list out all services along with their corresponding statuses using systemct , open up your terminal and type in the command below :

systemctl -at service

systemctl list services

Now to single out only those services that are active, go ahead and run the command below :

systemctl -t service – -state=active

Linux list services

For the services that are enabled however, you would need to invoke the command below :

systemctl list-unit-files – -state=enabled

As an alternative to the command above, it is also possible to use grep command as follows :

systemctl list-unit-files | grep enabled

In order to display the list of all currently loaded service units, type in the command below :

systemctl list-units – -type service

This command displays, for each service unit file, its full name (UNIT) , its loaded status (LOAD), its high-level (ACTIVE) unit file activation state followed by low-level (SUB) unit file activation state and finally a short description (DESCRIPTION).

The command ‘systemctl list-units’ displays, by default, only active units. In order to display a list of all loaded units (all states), you could execute this command with the –all or -a command line switches as follows:

systemctl list-units – -type service – -all

Services that started before a given service

In order to find out the services which ordered to start before a specified service, type in the following command in the terminal:

systemctl list-dependencies –after ssh.service

Linux start service

Where you are able to see the services ordered to start before the service named ssh in the snapshot above.

Services that started after a given service

To determine the services which ordered to after after a specified service (ssh here), run the following command:

systemctl list-dependencies before ssh.service

2 service command

The ‘service’ command utility allows to start, restart and stop and daemons as well as other services in Linux. In order to display the list of all services , run the command below :

service – -status-all

Ubuntu list services

3 – Checking a specific service enability status

In order to check whether a specific service was enabled at boot time, you could run the following syntax:

systemctl is-enabled {service_name}

systemctl is-enabled service_name.service

here the service name is ssh.

4 – Checking a specific service status

In order to see the status of a given service (enability flag is also provided as highlighted below), the following commands could be executed :

systemctl status {service_name}

systemctl status service_name.service

As an alternative to the command above, you could also use the command below :

systemctl list-unit-files –type service

The following table shows the service units information :

Courtesy: Redhat

You may be interested to read: Network configuration in Ubuntu 

Enabling a specific service at boot time

It is possible to enable a single service by using the one of the commands below :

sudo systemctl enable {service_name}

sudo systemctl enable service_name.service

Disabling a specific service at boot time

Much like enabling a service, systemctl is also able to disable a service by using one of the commands below :

sudo systemctl disable {service_name}

sudo systemctl disable service_name.service

Disabling a service prevents it (its service unit) from being automatically started at boot time.

This will read the [Install] section of the specific service unit and deletes the appropriate symbolic links to the file /usr/lib/systemd/system/name.service from the directory /etc/systemd/system/ and its subdirectories. Furthermore, you would be able to mask any service unit in order to prevent it from being started by another service or manually. To carry this out, execute the following command as root:

systemctl mask name.service

Stopping a specific service

Stopping a specific active service can be achieved via one the commands below (linux stop service) :

sudo systemctl stop {service_name}

sudo systemctl stop service_name.service

Starting and Restarting a specific service

Starting a specific inactive service can be done via one the commands below :

sudo systemctl start {service_name}

sudo systemctl start service_name.service

For the restart :

sudo systemctl restart {service_name}

sudo systemctl restart service_name.service

Displaying services error messages/logs

To check error messages or logs related to the services, execute one of the commands below :

journalctl -u {service_name}

or as an alternative :

journalctl -u service_name.service

Starting a Conflicting Service

In systemd, there are both positive and negative dependencies between services. A specific service may depend on one or more other services to start (positive dependency), or it may depend on stopping one or more services (negative dependency). When you try to start a new service, systemd automatically resolves all dependencies. The user is not explicitly notified in this process. If a service is already running and you try to start another service that has a negative dependency on it, the first service will be automatically stopped. As an example, if the postfix service is already running and you attempt to start the sendmail service, systemd will first stop the postfix service since these two services cannot be run on the same port.

Comparison of systemctl with the service tool

Credit : Redhat


If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.

 

ziad nahdy

Ziad Nahdy, fan of open source and programming languages. He is a technical writer, blogger and Linux enthusiast. He loves to read and help others with their problems. He is addicted to open source software but he also loves other technology related subjects.

This Post Has 3 Comments

  1. vcenter

    so useful and informative post
    thank you

    1. barbari-arya

      very goood
      thanks a lot

  2. Siz Hollman

    Well done! Is there a way to “delay” a service or manually create a service dependency?

Leave a Reply