
我需要重新啟動一個有問題的 openvpn 服務,該服務因掛起/恢復而搞砸了。我的想法是創建一個專用的重啟服務,如許多地方所記錄的(例如這裡),但我希望僅當服務在暫停時實際上處於活動狀態時才會重新啟動,因為我並不總是使用 VPN,並且我不希望恢復過程默默地啟動它。我沒有找到有關此用例的任何明確指示,因此感謝您的幫助。
答案1
我找到了我自己問題的答案:systemct try-restart
。從man systemctl
:
try-restart PATTERN...
Stop and then start one or more units specified on the command line if the units are running. This does nothing if units are not running.