条件失败时重试 systemd

N.F*_*.F. 5 linux systemd

我有一个 systemd 服务,它检查启动时是否安装了外部媒体。

\n
[Unit]\nDescription=My App\nConditionPathIsMountPoint=/mnt/sdcard\n\n[Service]\nWorkingDirectory=/opt/myapp\nExecStartPre=+/opt/myapp/bin/pre.sh\nExecStart=/opt/myapp/bin/myapp\nExecStop=/bin/kill -INT ${MAINPID}\nExecReload=/bin/kill -INT ${MAINPID} && /opt/myapp/bin/myapp\nRestart=always\nRestartSec=5\nUser=user\nGroup=user\n\n[Install]\nWantedBy=multi-user.target mnt-sdcard.mount\n
Run Code Online (Sandbox Code Playgroud)\n

我想等待myapp启动,直到/mnt/sdcard安装完毕。\n但此服务运行不佳。当安装介质被延迟时,systemd 会抛出异常start condition failed并且不会重试。

\n
# systemctl status myapp\n\xe2\x97\x8f myapp.service - My App\n   Loaded: loaded (/etc/systemd/system/myapp.service; enabled; vendor preset: enabled)\n   Active: inactive (dead)\nCondition: start condition failed at Wed 2021-01-27 14:22:31 JST; 2h 35min ago\n            ConditionPathIsMountPoint=/mnt/sdcard was not met\n
Run Code Online (Sandbox Code Playgroud)\n

当启动条件失败时如何重试启动?

\n

小智 0

在您的预启动脚本中检查外部媒体是否延迟安装在循环中