Shell script to automatically start, stop, restart virtual machines; and perform healthchecks. The script is designed to be executed on a schedule using cron. The script reads the description of every virtual machine on the host looking for function keywords in the description and performing any required actions.
Add any or all of the function keywords with a parameter into the "Notes" section of a virtual machines.
Requires sudo permission
- Login to the Proxmox host
git clone https://github.com/mbaezner/pve-agent.git /tmp/pve-agent
sudo cp /tmp/pve-agent/usr/bin/pve-agent /usr/bin/pve-agent
sudo chmod +x /usr/bin/pve-agent
sudo cp /tmp/pve-agent/usr/lib/systemd/system/pve-agent.service /usr/lib/systemd/system/pve-agent.service
sudo cp /tmp/pve-agent/usr/lib/systemd/system/pve-agent.timer /usr/lib/systemd/system/pve-agent.timer
systemctl daemon-reload
systemctl enable pve-agent.timer
- See ansible role
Requires sudo permission
- Login to the Proxmox host
sudo crontab -l | grep --invert-match 'pve-agent.sh' | sudo crontab -
rm /var/lib/vz/snippets/pve-agent.sh
Requires sudo permission
- Login to the Proxmox host
- Follow the remove instructions above
- Follow the install instructions above
- See ansible role
Policy | Description |
---|---|
no |
Do not automatically restart the virtual machine (default) |
always |
Always restart the virtual machine when it is not running |
qm_restart always
- qm_restart <policy>
Automatically start the virtual machine at the specified time
qm_autostart 6:00
Automatically stop the virtual machine at the specified time
qm_autostop 18:00
Command is run inside the virtual machine via the QEMU Guest Agent, so the QEMU Guest agent must be installed and enabled for the Virtual Machine
Appends "-healthy" to the virtual machine name when the commands returns 0, or "-unhealthy" when the command returns non-zero; if the original virtual machine name is "ubuntu", when the command returns zero the name will be changed to "ubuntu-healthy" and when the command returns non-zero the name will be changed to "ubuntu-unhealthy"
qm_healthcheck curl --fail --silent --output /dev/null http://localhost:80
- Migrate from cron to systemd service and timer
- First release