systemctl
是一個用于管理系統服務和守護進程的命令行工具,它是 Systemd 系統和服務管理器的一部分
systemctl list-dependencies
命令。例如,要查看 httpd.service
的依賴關系,可以運行:systemctl list-dependencies httpd.service
這將顯示 httpd.service
所依賴的服務以及依賴于它的服務。
.service
文件。通常,這些文件位于 /etc/systemd/system/
或 /lib/systemd/system/
目錄中。在 [Unit]
部分,可以使用以下兩個指令來定義依賴關系:Wants=
:表示即使此服務失敗,也不會影響到其他服務的啟動。Requires=
:表示如果此服務失敗,那么依賴于它的服務也會失敗。例如,要讓 my-service.service
依賴于 httpd.service
,可以在 my-service.service
的 [Unit]
部分添加以下內容:
[Unit]
Wants=httpd.service
systemctl daemon-reload
systemctl start
命令。例如,要啟動 httpd.service
及其依賴項,可以運行:systemctl start httpd.service
systemctl stop
命令。例如,要停止 httpd.service
及其依賴項,可以運行:systemctl stop httpd.service
systemctl restart
命令。例如,要重啟 httpd.service
及其依賴項,可以運行:systemctl restart httpd.service
通過這些方法,您可以使用 systemctl
命令管理服務依賴關系。