How to use the command "qm wait" (with examples)
The “qm wait” command is used to wait until a virtual machine is stopped in the Proxmox Virtual Environment (PVE). It can also include a timeout duration to limit the waiting time. This command is useful in scenarios where you want to wait for a virtual machine to shut down completely before performing any further actions.
Use case 1: Wait until the virtual machine is stopped
Code:
qm wait vm_id
Motivation: By using this command, you can ensure that the virtual machine has completely stopped before proceeding with any maintenance or management tasks. This prevents potential issues that may arise if actions are performed on a running or partially stopped virtual machine.
Explanation:
- “qm wait” is the command to wait until the virtual machine is stopped.
- “vm_id” is the identifier of the virtual machine you want to wait for.
Example output:
Waiting for virtual machine vm_id to stop...
Use case 2: Wait until the virtual machine is stopped with a 10 second timeout
Code:
qm wait --timeout 10 vm_id
Motivation: In some cases, you may want to set a specific timeout duration for waiting until the virtual machine is stopped. This is useful when you have a limited amount of time or when you want to prevent waiting indefinitely.
Explanation:
- “qm wait” is the command to wait until the virtual machine is stopped.
- “–timeout 10” sets the timeout duration to 10 seconds.
- “vm_id” is the identifier of the virtual machine you want to wait for.
Example output:
Waiting for virtual machine vm_id to stop... (timeout: 10 seconds)
Use case 3: Send a shutdown request, then wait until the virtual machine is stopped with a 10 second timeout
Code:
qm shutdown vm_id && qm wait --timeout 10 vm_id
Motivation: If you want to gracefully shut down a virtual machine and then wait until it is completely stopped, you can use this command. It ensures that the virtual machine goes through a proper shutdown sequence before waiting for its complete stoppage.
Explanation:
- “qm shutdown” is the command to send a shutdown request to the virtual machine.
- “vm_id” is the identifier of the virtual machine you want to shut down and wait for.
- “&&” is the shell operator to execute the following command only if the previous command executes successfully.
- “qm wait” is the command to wait until the virtual machine is stopped.
- “–timeout 10” sets the timeout duration to 10 seconds.
- “vm_id” is the identifier of the virtual machine you want to wait for.
Example output:
Shutting down virtual machine vm_id...
Waiting for virtual machine vm_id to stop... (timeout: 10 seconds)
Conclusion:
The “qm wait” command in Proxmox Virtual Environment is a useful tool for ensuring that virtual machines are fully stopped before performing any further actions. Whether you simply want to wait until a VM is stopped or set a timeout duration, this command gives you the flexibility to manage your virtual machines effectively.