diff --git a/sources/tech/20191220 How to Start, Stop - Restart Services in Ubuntu and Other Linux Distributions.md b/sources/tech/20191220 How to Start, Stop - Restart Services in Ubuntu and Other Linux Distributions.md deleted file mode 100644 index ab88f9198d..0000000000 --- a/sources/tech/20191220 How to Start, Stop - Restart Services in Ubuntu and Other Linux Distributions.md +++ /dev/null @@ -1,183 +0,0 @@ -[#]: collector: (lujun9972) -[#]: translator: (geekpi) -[#]: reviewer: ( ) -[#]: publisher: ( ) -[#]: url: ( ) -[#]: subject: (How to Start, Stop & Restart Services in Ubuntu and Other Linux Distributions) -[#]: via: (https://itsfoss.com/start-stop-restart-services-linux/) -[#]: author: (Sergiu https://itsfoss.com/author/sergiu/) - -How to Start, Stop & Restart Services in Ubuntu and Other Linux Distributions -====== - -Services are essential background processes that are usually run while booting up and shut down with the OS. - -If you are a sysadmin, you’ll deal with the service regularly. - -If you are a normal desktop user, you may come across the need to restart a service like [setting up Barrier for sharing mouse and keyboard between computers][1]. or when you are [using ufw to setup firewall][2]. - -Today I will show you two different ways you can manage services. You’ll learn to start, stop and restart services in Ubuntu or any other Linux distribution. - -systemd vs init - -Ubuntu and many other distributions these days use systemd instead of the good old init. - -In systemd, you manage sevices with systemctl command. - -In init, you manage service with service command. - -You’ll notice that even though your Linux system uses systemd, it is still able to use the service command (intended to be used with init system). This is because service command is actually redirect to systemctl. It’s sort of backward compatibility introduced by systemd because sysadmins were habitual of using the service command. - -I’ll show both systemctl and service command in this tutorial. - -_I am Ubuntu 18.04 here, but the process (no pun intended) is the same for other versions._ - -### Method 1: Managing services in Linux with systemd - -I am starting with systemd because of the obvious reason of its widespread adoption. - -#### 1\. List all services - -In order to manage the services, you first need to know what services are available on your system. - -You can use the systemd command to list all the services on your Linux system: - -``` -systemctl list-unit-files --type service -all -``` - -![systemctl list-unit-files][3] - -This command will output the state of all services. The value of a service’s state can be enabled, disabled, masked (inactive until mask is unset), static and generated. - -Combine it with the [grep command][4] and you can **display just the running services**: - -``` -sudo systemctl | grep running -``` - -![Display running services systemctl][5] - -Now that you know how to reference all different services, you can start actively managing them. - -**Note:** ***<service-***_**name>**_ _in the commands should be replaced by the name of the service you wish to manage (e.g. network-manager, ufw etc.)._ - -#### **2\. Start a** service - -To start a service in Linux, you just need to use its name like this: - -``` -systemctl start -``` - -#### 3\. **Stop** a service - -To stop a systemd service, you can use the stop option of systemctl command: - -``` -systemctl stop -``` - -#### 4\. Re**start** a service - -To restart a service in Linux with systemd, you can use: - -``` -systemctl restart -``` - -#### 5\. Check the status of a service - -You can confirm that you have successfully executed a certain action by printing the service status: - -``` -systemctl status -``` - -This will output information in the following manner: - -![systemctl status][6] - -That was systemd. Let’s switch to init now. - -### Method 2: Managing services in Linux with init - -The commands in init are also as simple as system. - -#### 1\. List all services - -To list all the Linux services, use - -``` -service --status-all -``` - -![service –status-all][7] - -The services preceded by **[ – ]** are **disabled** and those with **[ + ]** are **enabled**. - -#### **2\. Start** a service - -To start a service in Ubuntu and other distributions, use this command: - -``` -service start -``` - -#### **3\. Stop** a service - -Stopping a service is equally easy. - -``` -service stop -``` - -#### 4\. Re**start** a service - -If you want to restart a service, the command is: - -``` -service restart -``` - -#### 5\. Check the status of a service - -Furthermore, to check if your intended result was achieved, you can output the service ****status**:** - -``` -service status -``` - -This will output information in the following manner: - -![service status][8] - -This will, most importantly, tell you if a certain service is active **(**running**)** or not. - -**Wrapping Up** - -Today I detailed two very simple methods of managing services on Ubuntu or any other Linux system. I hope this article was helpful to you. - -Which method do you prefer? Let us know in the comment section below! - --------------------------------------------------------------------------------- - -via: https://itsfoss.com/start-stop-restart-services-linux/ - -作者:[Sergiu][a] -选题:[lujun9972][b] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: https://itsfoss.com/author/sergiu/ -[b]: https://github.com/lujun9972 -[1]: https://itsfoss.com/keyboard-mouse-sharing-between-computers/ -[2]: https://itsfoss.com/set-up-firewall-gufw/ -[3]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/systemctl_list_services.png?ssl=1 -[4]: https://linuxhandbook.com/grep-command-examples/ -[5]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/systemctl_grep_running.jpg?ssl=1 -[6]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/12/systemctl_status.jpg?ssl=1 -[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/service_status_all.png?ssl=1 -[8]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/service_status.jpg?ssl=1 diff --git a/translated/tech/20191220 How to Start, Stop - Restart Services in Ubuntu and Other Linux Distributions.md b/translated/tech/20191220 How to Start, Stop - Restart Services in Ubuntu and Other Linux Distributions.md new file mode 100644 index 0000000000..ec3367d6ef --- /dev/null +++ b/translated/tech/20191220 How to Start, Stop - Restart Services in Ubuntu and Other Linux Distributions.md @@ -0,0 +1,183 @@ +[#]: collector: (lujun9972) +[#]: translator: (geekpi) +[#]: reviewer: ( ) +[#]: publisher: ( ) +[#]: url: ( ) +[#]: subject: (How to Start, Stop & Restart Services in Ubuntu and Other Linux Distributions) +[#]: via: (https://itsfoss.com/start-stop-restart-services-linux/) +[#]: author: (Sergiu https://itsfoss.com/author/sergiu/) + +如何在 Ubuntu 和其他 Linux 发行版中启动、停止和重启服务 +====== + +服务是必不可少的后台进程,它通常随系统启动,并在关机时关闭。 + +如果你是系统管理员,那么你会定期处理服务。 + +如果你是普通桌面用户,你可能会遇到需要重启服务的情况,例如[安装 Barrier 来用于在计算机之间共享鼠标和键盘][1]。或[在使用 ufw 设置防火墙][2]时。 + +今天,我将向你展示两种管理服务的方式。你将学习在 Ubuntu 或任何其他 Linux 发行版中启动、停止和重启服务。 + +systemd 与 init + +如今,Ubuntu 和许多其他发行版都使用 systemd 而不是旧的 init。 + +在 systemd 中,可以使用 systemctl 命令管理服务。 + +在 init 中,你可以使用 service 命令管理服务。 + +你会注意到,即使你的 Linux 系统使用 systemd,它仍然可以使用 service 命令(为了与 init 系统一起使用)。这是因为 service 命令实际上已重定向到 systemctl。systemd 引入了向后兼容性,因为系统管理员们习惯使用 service 命令。 + +在本教程中,我将同时展示 systemctl 和 service 命令。 + +_我的是 Ubuntu 18.04,但其他版本的过程也一样_。 + +### 方法 1:使用 systemd 在 Linux 中管理服务 + +我从 systemd 开始,因为它被广泛接受。 + +#### 1\. 列出所有服务 + +为了管理服务,你首先需要知道系统上有哪些服务可用。 + +你可以使用 systemd 命令列出 Linux 系统上的所有服务: + +``` +systemctl list-unit-files --type service -all +``` + +![systemctl list-unit-files][3] + +此命令将输出所有服务的状态。服务状态有启用、禁用、屏蔽(在取消掩码之前处于非活动状态)、静态和已生成。 + +与 [grep 命令][4] 结合,你可以**仅显示正在运行的服务**: + +``` +sudo systemctl | grep running +``` + +![Display running services systemctl][5] + +现在,你知道了如何引用所有不同的服务,你可以开始主动管理它们。 + +**注意:** 命令中的 **<service-name>** 应该用你想管理的服务名代替。(比如:network-manager、ufw 等) + +#### 2\. 启动服务 + +要在 Linux 中启动服务,你只需使用它的名字: + +``` +systemctl start +``` + +#### 3\. 停止服务 + +要停止 systemd 服务,可以使用 systemctl 命令的 stop 选项: + +``` +systemctl stop +``` + +#### 4\. 重启服务 + +要重启 systemd 服务,可以使用: + +``` +systemctl restart +``` + +#### 5\. 检查服务状态 + +你可以通过打印服务状态来确认你已经成功执行特定操作: + +``` +systemctl status +``` + +这将以以下方式输出: + +![systemctl status][6] + +这是 systemd 的内容。现在切换到 init。 + +### 方法 2:使用 init 在 Linux 中管理服务 + +init 的命令和 systemd 的一样简单。 + +#### 1\. 列出所有服务 + +要列出所有 Linux 服务,使用: + +``` +service --status-all +``` + +![service –status-all][7] + +前面的 **[ – ]** 代表**禁用**,**[ + ]** 代表**启用**。 + +#### 2\. 启动服务 + +要在 Ubuntu 和其他发行版中启动服务,使用命令: + +``` +service start +``` + +#### 3\. 停止服务 + +停止服务同样简单。 + +``` +service stop +``` + +#### 4\. 重启服务 + +如果你想重启服务,命令是: + +``` +service restart +``` + +#### 5\. 检查服务状态 + +此外,要检查是否达到了预期的结果,你可以输出服务**状态**: + +``` +service status +``` + +这将以以下方式输出: + +![service status][8] + +最重要的是,这将告诉你某项服务是否处于活跃状态(**正在运行**)。 + +**总结** + +今天,我详细介绍了两种在 Ubuntu 或任何其他 Linux 系统上管理服务的非常简单的方法。 希望本文对你有所帮助。 + +你更喜欢哪种方法? 让我在下面的评论中知道! + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/start-stop-restart-services-linux/ + +作者:[Sergiu][a] +选题:[lujun9972][b] +译者:[geekpi](https://github.com/geekpi) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/sergiu/ +[b]: https://github.com/lujun9972 +[1]: https://itsfoss.com/keyboard-mouse-sharing-between-computers/ +[2]: https://itsfoss.com/set-up-firewall-gufw/ +[3]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/systemctl_list_services.png?ssl=1 +[4]: https://linuxhandbook.com/grep-command-examples/ +[5]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/systemctl_grep_running.jpg?ssl=1 +[6]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/12/systemctl_status.jpg?ssl=1 +[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/service_status_all.png?ssl=1 +[8]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/service_status.jpg?ssl=1