Execute script before/after a vm starts/stops

Hannobal

New Member
Sep 21, 2014
12
0
1
Hi community,

is there any way to execute a script before/after a vm starts/stops? Maybe something which I can configure for each vm.

thanks in advance!
 
Last edited:
Hi :)

As far as I know, when you start/stop a VM (KVM or OpenVZ) prox is just starting the KVM/OpenVZ process.

E.g. /usr/bin/kvm -id 403 -chardev socket,id=qmp,path=/var/run/qemu-server/403.qmp,server,nowait -mon chardev=qmp,mode=control -vnc unix:/var/run/qemu-server/403.vnc,x509,password -pidfile /var/run/qemu-server/403.pid -daemonize -name han-internetfeeds -smp sockets=2,cores=8 -nodefaults -boot menu=on -vga cirrus -cpu kvm64,+lahf_lm,+x2apic,+sep -k en-gb -m 32768 -device piix3-usb-uhci,id=uhci,bus=pci.0,addr=0x1.0x2 -device usb-tablet,id=tablet,bus=uhci.0,port=1 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 -iscsi initiator-name=iqn.1993-08.org.debian:01:3d5a96bbe899 -drive file=/dev/ProxSANImages/vm-403-disk-2,if=none,id=drive-virtio0,cache=writethrough,aio=native -device virtio-blk-pci,drive=drive-virtio0,id=virtio0,bus=pci.0,addr=0xa,bootindex=200 -netdev type=tap,id=net0,ifname=tap403i0,script=/var/lib/qemu-server/pve-bridge,downscript=/var/lib/qemu-server/pve-bridgedown -device e1000,romfile=,mac=1E:BD:21:3D:84:C2,netdev=net0,bus=pci.0,addr=0x12,id=net0 -machine type=pc-i440fx-2.1 -incoming tcp:localhost:60001 -S

I can't see any logical way that you would be able to attach a script to this, unless you really start to hack away at Proxmox (which is WAY above my head).

Why would you need to initiate a script on start/stop anyway? Can you not set it up as a cronjob to run your desired script?
 
Hi, thanks for your answer!

I will describe you my situation:

I want to passthrough some devices, which is working very good, but I can do this only one time and then I have to restart the host system to get the devices available again. So after a restart of the host system I can bind the devices to any vm again, but if I shutdown this vm, the devices are unavailable for binding to any other vm or to the same vm.

I researched about this problem and I think, that proxmox does not unbind the devices clearly. If there would only be one vm I could bypass this problem with a little workaround using netcat, which connects to the pid file and if it is no more existent then the script will unbind the devices manually, but with more than one vm it is a little bit complicated because how should the script know which vm uses the devices...
 
Last edited: