怎么用Systemd管理Ubuntu服务和进程

Systemd是一个系统和服务管理器,可以用来启动、停止和管理各种系统服务和进程。在Ubuntu上,可以使用systemctl命令来管理Systemd服务和进程。

以下是一些常用的Systemd命令:

启动一个服务:sudo systemctl start <service_name>
例如:sudo systemctl start apache2

停止一个服务:sudo systemctl stop <service_name>
例如:sudo systemctl stop apache2

重启一个服务:sudo systemctl restart <service_name>
例如:sudo systemctl restart apache2

查看一个服务的状态:sudo systemctl status <service_name>
例如:sudo systemctl status apache2

设置一个服务开机启动:sudo systemctl enable <service_name>
例如:sudo systemctl enable apache2

禁止一个服务开机启动:sudo systemctl disable <service_name>
例如:sudo systemctl disable apache2

查看所有正在运行的服务:sudo systemctl list-units --type=service
例如:sudo systemctl list-units --type=service

通过使用以上命令,你可以方便地管理Ubuntu上的各种服务和进程。Systemd还提供了更多高级功能,比如自定义服务配置文件等,可以根据需要进一步了解和使用。

阅读剩余
THE END