
我這個很簡單systemd
。
[Unit]
Description="Something"
[Service]
Type=simple
ExecStart=/bin/systemctl restart nginx
當我嘗試使用 運行它,systemctl start my-script.service
並使用 查詢它時systemctl status my-script.service
,它顯示 status Loaded
,並將永遠這樣做。
我有這樣的感覺,問題是我想systemctl
從內部使用systemd
。
答案1
systemctl status
將為您的服務報告“已載入”,因為此時它確實已載入到 systemd 中。我不確定你還期待什麼。我嘗試自己啟動您的服務,它按預期工作,重新啟動 Nginx 服務:
$ journalctl | tail -10
Apr 27 12:39:28 myhost.com systemd[1]: Started "Something".
Apr 27 12:39:28 myhost.com systemd[1]: Stopping A high performance web server and a reverse proxy server...
Apr 27 12:39:28 myhost.com systemd[1]: Stopped A high performance web server and a reverse proxy server.
Apr 27 12:39:28 myhost.com systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 27 12:39:28 myhost.com systemd[1]: Started A high performance web server and a reverse proxy server.
如果您的 systemd 服務文件未如預期運作,請更具體地說明您的問題。