taccle Posted August 6, 2022 Share Posted August 6, 2022 Hello Unraid community! I would like to know if there is any way to run a "user script" when a VM is shutdown. I have to use the GPU reset script of Spaceinvader One (https://www.youtube.com/watch?v=0uZODoPQH9c) every time I want to start a new VM. As it's mostly my parents using the VM, I would like the script to run automatically. Till now, I configured Windows to send a ssh command to Unraid when it's shutting down. But I don't think it's the best way to do it. Thanks in advance for your help! Quote Link to comment
Solution SimonF Posted August 6, 2022 Solution Share Posted August 6, 2022 (edited) 17 minutes ago, taccle said: Hello Unraid community! I would like to know if there is any way to run a "user script" when a VM is shutdown. I have to use the GPU reset script of Spaceinvader One (https://www.youtube.com/watch?v=0uZODoPQH9c) every time I want to start a new VM. As it's mostly my parents using the VM, I would like the script to run automatically. Till now, I configured Windows to send a ssh command to Unraid when it's shutting down. But I don't think it's the best way to do it. Thanks in advance for your help! Yes you can via a hooks file. Dependant on version of OS you have to change either /etc/libvirt/hooks/qemu or create dir and add script in to qemu.d in hooks. here is script i use for usb manager to install. qemu.d you need 6.10 https://github.com/SimonFair/USB_Manager/blob/main/source/scripts/install.sh Edited August 6, 2022 by SimonF Quote Link to comment
taccle Posted August 6, 2022 Author Share Posted August 6, 2022 Hi Simon! Thanks! That's exactly the solution I needed! To sum up if someone needs to do the same: - I created the directory qemu.d in /etc/libvirt/hooks/ - Inside this directory I wrote the script below. It will run Reset_GPU located in user_scripts when any VM is stopping. I don't run it immediately because I want to be sure the VM is properly off. Spoiler #!/bin/bash if [[ $2 == "stopped" ]] then at now + 2 minute -f /boot/config/plugins/user.scripts/scripts/Reset_GPU/script fi - I made it executable : chmod +x GPU_Reset Thanks again Simon, I didn't know about qemu and I've been struggling on this since a pretty long time! Quote Link to comment
SimonF Posted August 6, 2022 Share Posted August 6, 2022 1 hour ago, taccle said: Hi Simon! Thanks! That's exactly the solution I needed! To sum up if someone needs to do the same: - I created the directory qemu.d in /etc/libvirt/hooks/ - Inside this directory I wrote the script below. It will run Reset_GPU located in user_scripts when any VM is stopping. I don't run it immediately because I want to be sure the VM is properly off. Reveal hidden contents #!/bin/bash if [[ $2 == "stopped" ]] then at now + 2 minute -f /boot/config/plugins/user.scripts/scripts/Reset_GPU/script fi - I made it executable : chmod +x GPU_Reset Thanks again Simon, I didn't know about qemu and I've been struggling on this since a pretty long time! Here are the status. you can use stopped or relaased without waiting. https://www.libvirt.org/hooks.html#etc-libvirt-hooks-qemu Quote Link to comment
taccle Posted August 11, 2022 Author Share Posted August 11, 2022 Thanks! Yes when using "stopped" and without waiting, the reset wasn't done properly. I changed it to "release" and now it's working fine! Spoiler #!/bin/bash if [[ $2 == "release" ]] then bash /boot/config/plugins/user.scripts/scripts/Reset_GPU/script fi Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.