pve-agent
Description
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.
Usage
Add any or all of the function keywords with a parameter into the "Notes" section of a virtual machines.
Install
Manually
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
Ansible
- See ansible role
Remove
Manually
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
Upgrade 1.0 to 1.1
Manually
Requires sudo permission
- Login to the Proxmox host
- Follow the remove instructions above
- Follow the install instructions above
Ansible
- See ansible role
Functions
qm_reboot <policy>
Policy | Description |
---|---|
no |
Do not automatically restart the virtual machine (default) |
always |
Always restart the virtual machine when it is not running |
Examples
qm_restart always
Alias
- qm_restart <policy>
qm_autostart <time>
Automatically start the virtual machine at the specified time
Examples
qm_autostart 6:00
qm_autostop <time>
Automatically stop the virtual machine at the specified time
Examples
qm_autostop 18:00
qm_healthcheck <command>
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"
Examples
qm_healthcheck curl --fail --silent --output /dev/null http://localhost:80
Release Notes
1.1
- Migrate from cron to systemd service and timer
1.0
- First release