Qvm-shutdown: Best Way To Solve Race Conditions In Scripts?

I’m have race condition issues caused by scripts that are running qvm-shutdown, then qvm-startup. Qube is trying to startup before its fully shutdown.

Script has to shutdown qube, clear the memory, then restart qube.

I could use a pause param, but that’s not vary elegant. Qubes will shutdown at different speeds.

Is there a way to get the script to wait until the qube is shutdown before trying the startup?

try qvm-shutdown --wait <vm>; qvm-start <vm>

1 Like

Can you post the script (or a trimmed down version)?

qvm-shutdown does have a --wait parameter.
You can also check if $? is zero or non-zero after qvm-shutdown --wait to see if shutdown exited with unexpected results.

I’d probably also add a sleep 1 or sleep 2 statement between shutdown and start, just to be sure storage has also been properly cleaned up before qvm-start.

B

PS - in @airelemental 's snippet above, a) I’d prefer && instead of ; and b) then also check $? to see if the combined command line failed.

2 Likes

After a bunch more testing, I determined I can get the outcome I want without shutting down and restarting the qube. This made the script faster, and made the race condition moot.