Stop, start and restart services on Debian

29/12/2020
Chưa phân loại

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:

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

How to Use the ps Command to Find Running Processes on Linux

The full form of ps is process status. It is a command used to find information about currently running processes on Linux....
29/12/2020

Installing Dropbox on Debian 10

Dropbox is a very popular cloud file hosting service. Dropbox can be used from a web browser. Dropbox also offers clients...
29/12/2020

How to install SteamOS on Ubuntu 17.04

This tutorial on how to install SteamOS on Ubuntu is for game enthusiast, and someone that loves playing games on Steam....
28/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Cách gắn set proxy cho điện thoại android, oppo, giả lập android, Ldplayer Bằng Proxydroid
20/09/2023

Mua Proxy Socks5 VN Chơi Game Gia Lập Tăng Cường Trải Nghiệm Chơi Game
22/06/2023

Mua Proxy Mỹ, Us Nuôi Tài Khoản Etsy, eBay Tìm Hiểu Về Mua Proxy Mỹ tại Onet.com.vn
22/06/2023

Mua Proxy Game – Giải pháp tuyệt vời cho việc chơi game trên mạng mà không bị giới hạn về vị trí địa lý
03/06/2023

Sử dụng Proxy để Quản Lý Tài Khoản Quảng Cáo Ads Một Cách An Toàn
27/05/2023