我有一个包含以下内容的脚本:
sudo machinectl start "$machinename"
sudo systemd-run -PM root@"$machinename" "$command"
Failed to connect to bus: No such file or directory
Failed to start transient service unit: Transport endpoint is not connected
这失败了,因为第一行只开始启动容器;第二行在容器完成启动之前运行。目前,我有一个解决方案,可以不断轮询容器的状态并阻塞,直到它准备好:
while [ "$(sudo systemctl show "systemd-nspawn@$machinename" -P StatusText)" != "Container running: Ready." ]
do
true
done
如何等待容器完成启动,而不是不断轮询容器的状态?