service — 管理系統服務(舊版,改用 systemctl)
管理系統服務(SysV 相容層,現代系統請改用 systemctl)。
語法
service 服務名稱 {start|stop|restart|status|...}
使用範例
範例 1:管理 nginx 服務(service vs systemctl)
兩種指令的對應關係(在 systemd 系統中 service 會呼叫 systemctl)。
$ # service 指令 → systemctl 等效指令
service nginx start → sudo systemctl start nginx
service nginx stop → sudo systemctl stop nginx
service nginx restart → sudo systemctl restart nginx
service nginx status → sudo systemctl status nginx
範例 2:查看所有可用服務
列出系統上所有可以用 service 管理的服務。
$ sudo service --status-all
[ + ] cron
[ + ] nginx
[ - ] apache2
[ + ] ssh