systemd 沒有偵測到死亡的守護程式

systemd 沒有偵測到死亡的守護程式

我有一個aaa.service文件(控制 JBoss),除了其他常規內容之外,還包含

[Service]
Type=forking
ExecStart=/my/script start
ExecReload=/my/script restart
ExecStop=/my/script stop
PIDFile=...

/my/script start建立 PID 檔案並service aaa status顯示它發出一個奇怪的警告:

Supervising process xxx which is not our child. We'll most likely not notice when it exits.

完整輸出:

   Loaded: loaded (/etc/systemd/system/aaa.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-01-22 20:55:16 CET; 34min ago
  Process: 32435 ExecStart=/my/script start (code=exited, status=0/SUCCESS)
 Main PID: 32542
    Tasks: 0 (limit: 512)
   CGroup: /system.slice/aaa.service

Jan 22 20:54:56 I011-830 su[32447]: (to aaa) root on none
Jan 22 20:54:56 I011-830 su[32447]: pam_unix(su-l:session): session opened for user aaa by (uid=0)
Jan 22 20:55:16 I011-830 aaa[32435]: Starting JBoss application server: Starting JBoss application server:
Jan 22 20:55:16 I011-830 systemd[1]: aaa.service: Supervising process 32542 which is not our child. We'll most likely not notice when it exits.

現在我的實際問題是,如果進程被殺死,然後透過發出service aaa stop,systemd 不會檢測到它。它甚至聲稱它正在運行並且不想再次啟動它:

# cat <pid-file>
No such file or directory
# service aaa status
   Loaded: loaded (/etc/systemd/system/aaa.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-01-22 20:55:16 CET; 40min ago
  Process: 32435 ExecStart=/konsens/app/aaa/init/aaastart (code=exited, status=0/SUCCESS)
 Main PID: 32542
    Tasks: 0 (limit: 512)
   CGroup: /system.slice/aaa.service
 ...
# service aaa start
# <--- Instant return, no process started

我怎樣才能實現以下目標?

  • systemd 應該能夠啟動並停止我的服務
  • service aaa status應該顯示進程的狀態,無論它是由 systemd 啟動還是手動發出/my/service start
  • systemd 應該能夠在手動終止服務後啟動服務
  • systemd 應該能夠停止我手動啟動的服務

答案1

我怎樣才能實現以下目標? 1 systemd 應該能夠啟動並停止我的服務

大多數發行版都具有向後相容性,因此如果您不想建立本機服務,可以將服務儲存在 /etc/init.d/ 中。

2 service aaa status 應顯示進程的狀態,無論它是由 systemd 啟動還是手動發出 /my/service start

執行此操作的一種方法是在腳本中新增一個檢查,以呼叫systemctl start aaa.service是否一開始就沒有以這種方式呼叫。陷阱可用於退出。

3 systemd 手動殺死後應該能夠啟動服務

由#2解決

4 systemd 應該能夠停止我手動啟動的服務

由#2解決

相關內容