Debian System Administration

Stop, start and restart services on Debian

Services on Linux Debian 10 Buster

A service is a program running on the background to be used when needed. Apache, ssh, Nginx or Mysql are some of the most known services. On Debian, including Debian 10 Buster, services are stored in the directory /etc/init.d/, they can be managed with the init system or the systemd, both of which will be explained below with examples of 3 different ways to stop, start, restart or check a service status.

The service command

The command service in Linux allows to check the status, stop, start or restart services and daemons, init files stored under the /etc/init.d directory.

The syntax to stop, run, restart services or print their status at demand is:

service <Service-Name> <Order>

The following example shows how to check the ssh service status using the service command:

service ssh status

Systemd

The Systemd is a suite to manage Linux services and daemons (the last “d” is because of Unix daemons). The systemctl command allows to start,stop,restart and check services status. Its aim is to unify the configuration and behaviour for all Linux distributions replacing Unix SystemV and BSD init systems.It also manages the init program described below.

The syntax to check the status of a service is the following:

systemctl status ssh

The /etc/init.d directory

When the system boots init is the first program to be executed and remains running as process with PID 1 until the system turns off.“ It is the direct or indirect ancestor of all other processes and automatically adopts all orphaned processes. Init is started by the kernel during the booting process; a kernel panic will occur if the kernel is unable to start it. Init is typically assigned process identifier 1” (Source: Wikipedia)

All services and daemons starting at boot are found in the /etc/init.d directory. All files stored in the /etc/init.d directory support stopping, starting, restarting and checking services status.
The syntax to check the status of  the ssh service is:

/etc/init.d/ssh status

Checking a service status on Linux Debian 10 Buster

Below you’ll find 3 different ways showing how to check for a service status on Debian 10 Buster (or any modern Debian release).

Checking a service status with the command service:

The command service allows to show a service status, to start, stop or restart it, to show a service the syntax is:

service <Service-Name> status

The following example shows the ssh service status:

service sshd status

In my case in which the ssh service is running the output is:

Checking status of services within init.d:

Additionally to the command service you can also interact with services stored at the /etc/init.d directory, to check a service status the syntax is:

/etc/init.d/<Services-Name> status

To check the status of the ssh service run:

/etc/init.d/ssh status

And you can also check a service status using the Systemd control command systemctl, the syntax is:

systemctl status <Service-Name>

To check the ssh status using the systemctl command run:

systemctl status ssh

Starting services on Linux Debian 10 Buster

To start services on Linux using the command service  the syntax is:

service <Service-Name> start

The following example shows how to start the ssh service using the service command:

service ssh start

Like with the status you can also start services from the init.d directory getting an informative output,  the syntax is:

/etc/init.d/ssh start

You can also start services using the systemctl command with the following syntax:

systemctl start <Service-Name>

The following example shows how to start the ssh service using the systemctl command:

systemctl start ssh

Stopping services on Linux Debian 10 Buster

To stop services on Debian using the service command the syntax is:

service <Service-Name> stop

The following example shows how to stop the ssh service:

service ssh stop

To stop services using the init.d directory the syntax is:

./etc/init.d/<Service-Name> stop

The example below shows how to stop the ssh service using the /etc/init.d directory:

./etc/init.d/ssh stop

To stop a service using the systemctl command the syntax is:

systemctl stop <Service-Name>

The example below shows how to stop the ssh service using the systemctl command:

systemctl stop ssh

Restarting services on Linux Debian 10 Buster

Restarting services requires the same syntax, to restart the ssh service using the command service run:

service ssh restart

To restart the ssh service using the init.d directory run:

/etc/init.d/ssh restart

And finally to restart the ssh service using the Systemd run:

systemctl restart ssh

That’s all on managing services under Linux. Check the Related Articles section to learn more about services.

I hope you found this brief tutorial useful. Keep following LinuxHint for additional updates and tips on Linux and Networking.

Related articles:

About the author

Ivan Vanney

Ivan Vanney

Ivan Vanney has over a decade working as sysadmin. He is s contributor on LinuxHint.com, and the founder of linuxer.info