How to Manage Ubuntu Boot Services: List, Start, and Stop Systemd Services at Startup

Services, also known as daemons, are background programs and scripts that provide essential functionalities, such as database services like MySQL, or web server capabilities (e.g., Tomcat).

As the number of services installed and running increases overtime, it can become challenging to keep track of all active applications. Understanding which services are configured to start automatically when your system boots can be invaluable, especially if you’ve experienced a slowdown in system performance. Unnecessary services running in the background can consume valuable system resources like RAM, swap space, and CPU cycles, reducing the resources available for essential applications. Disabling or preventing these non-essential services from launching at startup can significantly enhance system responsiveness by freeing up these resources.

This concise tutorial will guide you through the methods to display all Ubuntu services configured to start at boot, as well as how to manage them by starting and stopping services as needed.

Read: How to Access Recovery Mode in Ubuntu Linux 22.04

Listing Startup Services at Boot Time

Several options are available for viewing the list of services configured to start at boot. Below, we will detail the most commonly employed tools for this purpose.

1 – `systemctl`

`systemctl` is the primary command-line management tool for `systemd`, the system and service manager in modern Linux distributions. It provides comprehensive control over system services and allows you to inspect the current system state.

To list all services along with their current statuses using `systemctl`, open your terminal and execute the command:

systemctl -at service

systemctl list services output

systemctl list services

Read: How to Troubleshoot and Optimize Ubuntu Startup: Manage Systemd Services for Faster Boot Time

To specifically display only services that are currently active, use the following command:

systemctl -t service --state=active

systemctl list active services output

Linux list services – active only

Read: How to fix high memory usage in Ubuntu

To view services that are enabled to start at boot, execute the command below:

systemctl list-unit-files --state=enabled

systemctl list enabled services output

Alternatively, you can achieve the same result using the `grep` command to filter the output:

systemctl list-unit-files | grep enabled

To display a list of all currently loaded service units, use the following command:

systemctl list-units --type service

systemctl list loaded service units output

This command provides detailed information for each service unit, including its full name (UNIT), its loading status (LOAD), its high-level activation state (ACTIVE), its low-level activation state (SUB), and a brief description (DESCRIPTION).

Read: Repeat Linux Commands Every X Seconds for Real-Time Monitoring, Automation & Precise Scheduling

By default, `systemctl list-units` only shows active units. To display all loaded units, regardless of their state, use the `–all` or `-a` options:

systemctl list-units --type service --all

Services Ordered Before a Specific Service

To identify services that are configured to start before a particular service, for example, `ssh.service`, use the following command:

systemctl list-dependencies --after ssh.service

systemctl list dependencies after ssh.service output

Services starting before ssh service

The output displays services that are ordered to start before the ‘ssh’ service, as shown in the image above.

Services Ordered After a Specific Service

To find services that are ordered to start after a specific service (again, using ‘ssh’ as an example), run the following command:

systemctl list-dependencies --before ssh.service

systemctl list dependencies before ssh.service output

2 – `service` Command

The `service` command is another utility that allows you to manage daemons and other services in Linux, including starting, restarting, and stopping them. To get a list of all services using the `service` command, execute:

service --status-all

service --status-all command output

Ubuntu list services using service command

3 – Checking Specific Service Enablement Status

To verify if a particular service is enabled to start at boot, you can use the following syntax:

systemctl is-enabled {service_name}
systemctl is-enabled service_name.service

systemctl is-enabled ssh.service output

In the example above, ‘ssh’ is the service name being checked.

4 – Checking Specific Service Status

To view the detailed status of a service, including its enabled state, you can use these commands:

systemctl status {service_name}

systemctl status ssh output

systemctl status service_name.service

systemctl status ssh.service output

Alternatively, you can utilize the following command to list unit files by service type and check their status:

systemctl list-unit-files --type service

systemctl list-unit-files --type service output

The following table explains the information columns for service units:

systemctl service unit file columns description table

Courtesy: Redhat

Read: Network Configuration in Ubuntu 

Enabling a Specific Service at Boot-Time

To enable a service to automatically start during system boot, use one of these commands:

sudo systemctl enable {service_name}
sudo systemctl enable service_name.service

Disabling a Specific Service at Boot Time

Similar to enabling, `systemctl` can also disable a service from starting at boot using these commands:

sudo systemctl disable {service_name}
sudo systemctl disable service_name.service

Disabling a service prevents its service unit from automatically starting when the system boots.

This action reads the `[Install]` section of the service unit file and removes the symbolic links from `/etc/systemd/system/` and its subdirectories that point to `/usr/lib/systemd/system/name.service`. Furthermore, you can completely prevent a service unit from being started, either by other services or manually, by masking it. To mask a service, execute the following command as root:

systemctl mask name.service

Stopping a Specific Service

To stop an actively running service, use one of the following commands:

sudo systemctl stop {service_name}
sudo systemctl stop service_name.service

Starting and Restarting a Specific Service

To start a service that is currently inactive, use one of these commands:

sudo systemctl start {service_name}
sudo systemctl start service_name.service

To restart a service that is already running:

sudo systemctl restart {service_name}
sudo systemctl restart service_name.service

Displaying Service Error Messages/Logs

To examine error messages and logs associated with a specific service, execute one of these commands:

journalctl -u {service_name}

journalctl -u service_name output

Alternatively:

journalctl -u service_name.service

Starting a Conflicting Service

In `systemd`, service dependencies can be both positive and negative. A service might require other services to be running before it can start (positive dependency), or it might require certain services to be stopped (negative dependency). When you attempt to start a service, `systemd` automatically manages these dependencies without explicit user notification. If you try to start a service that has a negative dependency on a service that’s already running, `systemd` will automatically stop the first service. For instance, if ‘postfix’ is running and you try to start ‘sendmail’, `systemd` will first stop ‘postfix’ because these two services cannot operate simultaneously on the same port.

Comparison of `systemctl` with the `service` tool

systemctl vs service command comparison table

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.

 

Leave a Reply