Jump to content
bland328

Running custom script before VM is shut down?

3 posts in this topic Last Reply

Recommended Posts

Posted (edited)

I'm not quite sure where to ask this question! It could end up being appropriate here, or perhaps it's a plugin question, or perhaps it's something else.

 

What I'm trying to do:

I'm looking for a way to run a custom script on my Unraid server (on the host, not the guest) before one of my VMs is shut down by the host.

 

Also, while I do want to catch the case that my VM is shut down from the Unraid GUI, I could live with only catching the case that the array is being stopped.

 

What won't work:

  • Building a manually-executed script that does my additional work and then shuts the VM down won't do the trick, since I need to do this additional work automatically even in the cases that the VM is being shut down from the GUI or is being shut down automatically as a result of the array being stopped.

 

What doesn't work:

  • To catch the case that the array is being stopped, I've tried the User Scripts plugin, with a script that runs "At stopping of array," but that's too late--my VM has already been shut down by the time my script is called.

  • To catch that same case, I've also tried a bare-bones custom plugin (/usr/local/emhttp/plugins/my_custom_plugin/event/stopping_svcs), but that's also called too late.

  • I've even looked into modifying the libvirt /etc/libvirt/hooks/qemu script, but it too is called after a VM has been stopped.


Any thoughts on how to catch an attempt at shutting a VM down, or at least being called early in the array-stopping procedure?

 

Thanks for any ideas!

 

Edited by bland328

Share this post


Link to post

AFAIK, the host only knows the current state of the VM, not the intended trajectory. If you need an event to fire before an attempted shutdown, it's going to have to come from inside the guest. If you can get a trigger from inside the guest, it's pretty easy to have it fire off a script in the host.

 

I do have one suggestion, don't know if it will help. Monitor ping returns from your guest. When the ping dies, you know the guest is pretty much already shut down.

 

Your scenario is light on timing details and intended actions, so it's hard to come up with suggestions.

Share this post


Link to post

Thanks for the response, @jonathanm.

 

I've revised my original post just a bit to clarify that I'm not shooting for the host discerning the trajectory of the guest--I'm looking to get a chance to do some work before (or even as) the host makes an effort to shut down the guest.

 

That is, I'm only trying to catch the case that Unraid/libvirt is making an attempt to shut my VM down from outside the guest.

 

It's easy to learn that my VM was shut down, but I'm hoping to be called before it happens.

Share this post


Link to post

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.