systemdサービス:開始前にタイムアウト時に再起動

systemdサービス:開始前にタイムアウト時に再起動

ExecStartPreサービスが開始される前にDNS検証が正しく機能していることを確認するのに特に長い時間がかかるシステムサービスがあります。このコマンドがタイムアウトするたびに(デフォルトではDNSが機能するまで)、サービスを再起動したいと思います。ここからこの作品を手に入れました。ここ

はい、設定によってTimeoutStartSec開始タイムアウトが増え、ExecStartPreコマンドの実行が完了する可能性があることがわかります。これは技術的に可能ですが、他のものを探しています。つまり、ExecStartPre90秒がかかりなくなるまでサービスを再起動する方法です。

これまで、私はタイムアウトをキャプチャできるようにしたいと思い、1つの設定とRestart=on-abnormal1つを試しました。Restart=on-failure彼らはしません。どんな助けでも大変感謝します。

サービスファイル:

[Unit]
Description=thing
After=network-online.target

[Service]
Type=simple
ExecStartPre=/bin/sh -c 'until host google.com; do sleep 1; done'
ExecStart=python ...script.py
Restart=on-failure
RestartSec=60
...

[Install]
WantedBy=multi-user.target

再起動してログインしてください。

-- Boot 16978e49888146259f843055bfa26399 --
Oct 03 02:26:05 thing systemd[1]: Starting thing...
Oct 03 02:26:15 thing sh[609]: ;; connection timed out; no servers could be reached
Oct 03 02:26:26 thing sh[934]: ;; connection timed out; no servers could be reached
Oct 03 02:26:37 thing sh[973]: ;; connection timed out; no servers could be reached
Oct 03 02:26:48 thing sh[1003]: ;; connection timed out; no servers could be reached
Oct 03 02:27:00 thing sh[1038]: ;; connection timed out; no servers could be reached
Oct 03 02:27:11 thing sh[1066]: ;; connection timed out; no servers could be reached
Oct 03 02:27:22 thing sh[1101]: ;; connection timed out; no servers could be reached
Oct 03 02:27:33 thing sh[1131]: ;; connection timed out; no servers could be reached
Oct 03 02:27:35 thing systemd[1]: thing.service: start-pre operation timed out. Terminating.
Oct 03 02:27:35 thing systemd[1]: thing.service: Control process exited, code=killed, status=15/TERM
Oct 03 02:27:35 thing systemd[1]: thing.service: Failed with result 'timeout'.
Oct 03 02:27:35 thing systemd[1]: Failed to start thing.

ベストアンサー1

おすすめ記事