Авторские статьи

Reboot in command-line of virtual machine Proxmox VE.

If you haven’t heard about Proxmox VE, you should better memorize it. It will be useful when you need comfortable and free solution for implementation of virtualization. Proxmox VE is Debian Linux + web interface, because of which you will access to powerful functional of hypervisor KVM, Qemu, container LXC and Ceph. Proxmox VE has advanced API allowing realizing an alternate way to access your virtual machines. In this article we will tell about command-line utility pvesh which uses API and helps admin with automation of his daily tasks. We face the task to reboot the virtual machine not with the own commands from the schedulers of operating system (from the inside of virtual machine), but from outside by means of Proxmox VE. Namely, to send a signal as if the power button that orders virtual server to wrap it up is pressed.

We would like to create a solution that will not be anchored to a current location of virtual machines on physical servers in virtualization cluster. My colleagues and I actively use Live Migration and nowadays VM1 works on node2, and tomorrow it will be sent online to node3.

This request immediately put paid to the use of low-level command qm, which demands ordering from that cluster node, where the exact virtual machine is working. I have already displayed the power of PveSh in examples since it uses API Proxmox VE and allows putting plans into action.

Before rebooting the servers we should remember that there was given valuable advice about preparing them for work in virtualization environment for MS Windows Server. While attempting to turn them off with the help of web interface or in the console, you will receive a request. We must change such behavior.

Windows 2008 guest best practices
Windows 2012 guest best practices

Unfortunately, when you press virtual power button you turn off the virtual server instead of rebooting it. That is, you will have "restart" in the meaning "shutdown + start". For script’s work only jq is required. The default repositories Debian and Ubuntu have it and it facilitates the work with JSON answers. Script’s work is not very difficult. At first, according to the given VMID we get node-name for our cluster on which the virtual machine is working at the moment. Make shutdown. Then we interrogate the status at infinite loop and when it becomes stopped we can interrupt the loop while and start the virtual machine.

# vasilisc.com

if ! [ -x "$(command -v jq)" ]; then
        echo 'Error: jq is not installed.' >&2
        echo "apt-get install jq"
        exit 1

if [ -z $1 ]; then
        echo "Use "$0" VMID"
        exit 1

NODE=`pvesh get /cluster/resources --type vm | jq --raw-output ".[] | select(.vmid == ${VMID}) | .node"`

# shutdown VM
pvesh create /nodes/${NODE}/qemu/${VMID}/status/shutdown

# get status
while true 
        STATUS=`pvesh get /nodes/${NODE}/qemu/${VMID}/status/current | jq --raw-output ".status"`
        echo "NODE="${NODE}" VMID="${VMID}" is "${STATUS}
        sleep 5

        if [ "${STATUS}" == "stopped" ]; then

# start
sleep 5
pvesh create /nodes/${NODE}/qemu/${VMID}/status/start

exit 0

Proxmox VE API. Access.
Proxmox VE API. Cluster.
Proxmox VE API. Storage.
Proxmox VE API. Pools.
Proxmox VE API. Versions.
Proxmox VE API. Nodes.

Дата последней правки: 2023-12-27 11:33:12

RSS vasilisc.com   


Ворох бумаг
Видео Linux
Игры в Linux
Статьи об Astra Linux
Статьи о FreeBSD
Статьи об Ubuntu
Статьи о Snappy
Статьи об Ubuntu Phone
Статьи о Kubuntu
Статьи о Xubuntu
Статьи о Lubuntu
Статьи об Open Source
Карта сайта