我有一个系统服务,它的时间特别长ExecStartPre
命令,确保 DNS 解析在服务启动之前正常工作。我希望每次此命令超时时都重新启动服务(基本上直到 DNS 工作为止)。我从这里得到了这个片段这里。
是的,我意识到设置TimeoutStartSec
可以增加启动超时,从而允许 ExecStartPre 命令完成运行。这在技术上是可行的,但我正在寻找不同的东西:一种不断重新启动服务直到ExecStartPre
不需要> 90秒的方法。
到目前为止,我已经尝试了一种配置Restart=on-abnormal
和 一种配置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.