我有一個模板單元,必須創建它才能啟動/停止運行給定連接埠的某些服務。就像是[email protected]
,[email protected]
。
[Unit]
After=network.target
PartOf=services.target
[Service]
ExecStart=app run --port %i
ExecStopPost=sleep 5
[Install]
WantedBy=multi-user.target
我創建了一個目標來同時管理所有這些服務。
cat services.target
[Unit]
[email protected] [email protected]
效果很好。它們都提供相同的 API,因此為了中斷服務,我只想同時重新啟動一個程序。
。一種解決方案可能是After
在 中使用unit template
,但這不是很靈活,因為我可以運行或多或少的這些進程,如果我刪除一個,我可能會破壞依賴鏈......所以我找到的唯一解決方案是寫一個 bash 腳本,逐一停止/啟動實例,sleep
中間用 。這意味著可以使用 totarget
和stop
but start
not restart
... 這不方便。
我還有什麼其他選擇?可以使用嗎notify
?