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

 

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

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

Both negative and positive dependencies between services exist in systemd . Starting a specific service may be dependent on one or more other services (.i.e. positive dependency). Negative dependency is similar but the dependency is related to stopping one or more services.

When you try to start a new service, all dependencies are resolved automatically by systemd . The user does not get notified (explicitly) in this case . In case a service is already running, and at the same time you try to start yet another service which has a negative dependency, the first service in this case, will be automatically stopped.

For instance, if the postfix service is already running and you attempt to start the sendmail service, systemd will first automatically stop the first service, i.e. postfix, since these two services are conflicting as they cannot be executed on the same port.

Comparison of systemctl with the service tool

Post a Comment

Previous Post Next Post