Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to start, stop, and restart services in Ubuntu and other Linux distributions

Shulou Source: shulou.com Published: 2022-06-01 05:42:04 10月05日 Update

This article mainly introduces how to start, stop and restart services in Ubuntu and other Linux distributions, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.

Method 1: use systemd to manage services in Linux

I started with systemd because it is widely accepted.

1. List all services

To manage services, you first need to know which services are available on the system. You can use the systemd command to list all the services on the Linux system:

Systemctl list-unit-files-- type service-all

Systemctl list-unit-files

This command outputs the status of all services. The service states are enabled enabled, disabled disabled, shielded masked (inactive until unshielded), static static, and generated generated.

Combined with the grep command, you can display only the services that are running:

Sudo systemctl | grep running

Display running services systemctl

Now that you know how to reference all the different services, you can start to actively manage them.

Note: the following commands should be replaced with the name of the service you want to manage. (for example: network-manager, ufw, etc.)

2. Start the service

To start the service in Linux, you just need to use its name:

Systemctl start 3. Stop the service

To stop the systemd service, you can use the stop option of the systemctl command:

Systemctl stop 4. Restart the service

To restart the systemd service, use:

Systemctl restart 5. Check service status

You can confirm that you have successfully performed a specific operation by printing the service status:

Systemctl status

This will be output in the following manner:

Systemctl status

This is the content of systemd. Now switch to init.

Method 2: use init to manage services in Linux

Init's command is as simple as systemd's.

1. List all services

To list all Linux services, use:

Service-status-all

Service-status-all

The preceding [-] means disabled and [+] means enabled.

2. Start the service

To start the service in Ubuntu and other distributions, use the command:

Service start3, stop servic

It is equally easy to stop the service.

Service stop4, restart the service

If you want to restart the service, the command is:

Service restart5, check service status

In addition, to check whether the expected results have been achieved, you can output the service status:

Service status

This will be output in the following manner:

Service status

Most importantly, this will tell you whether a service is active (running).

Thank you for reading this article carefully. I hope the article "how to start, stop and restart Services in Ubuntu and other Linux distributions" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Services commands status management articles output distribution management services inspections representatives methods methods processes systems operations differences importance initiative success value Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi NVidia Xiaomi Huawei Shulou Information