Graceful shutdown on pc turnoff

89 views
Skip to first unread message

in...@videlin.eu

unread,
May 29, 2018, 11:46:55 PM5/29/18
to Vagrant
Hello,
I am searching for a way to gracefully shutdown my vagrant box when I turn of my pc.

I am constantly forgetting to halt the box before the system shut down and next time the box is corrupted (my databases are lost and I should provision the box again)

I have tried to write a simple bat file that would execute the `vagrant halt` command and then add it to the shutdown scripts of windows (as described here: https://stackoverflow.com/questions/12434863/executing-a-batch-script-on-windows-shutdown?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa)
but then it seems that Virtualbox is suspending the box before the bat file is executed.

Any suggestions?

My system spec:
OS: Windows 10 x64
Vagrant provider: Virtualbox 5.2


Alvaro Miranda Aguilera

unread,
May 30, 2018, 3:04:06 AM5/30/18
to vagra...@googlegroups.com
Hello

Seems per this post:

you can override per box what to do on host shutdown.. default is suspend, you can do poweroff like

setextradata "VM NAME" GUI/DefaultCloseAction Shutdown


This can be implemented like this:

Vagrant.configure("2") do |config|

  config.vm.box = "hashicorp/precise64"


  config.vm.provider "virtualbox" do |v|

    v.customize ["setextradata", :id, "GUI/DefaultCloseAction", "Shutdown"]

  end


end



you can add that per VM, or place a Vagrantfile in ~/.vagrant.d that will be a global one.



Vagrant.configure("2") do |config|


  config.vm.provider "virtualbox" do |v|

    v.customize ["setextradata", :id, "GUI/DefaultCloseAction", "Shutdown"]

  end


end




--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/d3658359-fb8e-4995-b425-4ace114af886%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

in...@videlin.eu

unread,
May 30, 2018, 12:01:41 PM5/30/18
to Vagrant
Amazing!!!

Thank you so much for the great reply!
I just tested it with restart and shutdown of the OS and in both cases, the box is not corrupted.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.



--
Alvaro

Reply all
Reply to author
Forward
0 new messages