diff --git a/README.md b/README.md index a0fbadd..6e77f74 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,12 @@ This plugin adds an entry to your /etc/hosts file on the host system. -On **up** and **reload** commands, it tries to add the information, if its not already existant in your hosts file. If it needs to be added, you will be asked for an administrator password, since it uses sudo to edit the file. +On **up**, **resume** and **reload** commands, it tries to add the information, if its not already existant in your hosts file. If it needs to be added, you will be asked for an administrator password, since it uses sudo to edit the file. -On **halt**, **suspend** and **destroy**, those entries will be removed again. +On **halt** and **destroy**, those entries will be removed again. +By setting the remove\_on\_suspend option, you can have them removed on **suspend**, too: + + config.hostsupdater.remove_on_suspend = true ## Versions ### 0.0.4 @@ -24,9 +27,9 @@ Uninstall it with: At the moment, the only things you need, are the hostname and a :private_network network with a fixed ip. - $ config.vm.network :private_network, ip: "192.168.3.10" - $ config.vm.hostname = "www.testing.de" - $ config.hostsupdater.aliases = ["alias.testing.de", "alias2.somedomain.com"] + config.vm.network :private_network, ip: "192.168.3.10" + config.vm.hostname = "www.testing.de" + config.hostsupdater.aliases = ["alias.testing.de", "alias2.somedomain.com"] This ip and the hostname will be used for the entry in the /etc/hosts file. diff --git a/lib/vagrant-hostsupdater/Action/RemoveHosts.rb b/lib/vagrant-hostsupdater/Action/RemoveHosts.rb index 50d80af..b7c7115 100644 --- a/lib/vagrant-hostsupdater/Action/RemoveHosts.rb +++ b/lib/vagrant-hostsupdater/Action/RemoveHosts.rb @@ -11,8 +11,13 @@ def initialize(app, env) end def call(env) - @ui.info "Removing hosts" - removeHostEntries + machine_action = env[:machine_action] + if machine_action != :suspend || @machine.config.hostsupdater.remove_on_suspend + @ui.info "Removing hosts" + removeHostEntries + else + @ui.info "Removing on suspend disabled" + end @app.call(env) end diff --git a/lib/vagrant-hostsupdater/config.rb b/lib/vagrant-hostsupdater/config.rb index 0ae899e..8fdddfa 100644 --- a/lib/vagrant-hostsupdater/config.rb +++ b/lib/vagrant-hostsupdater/config.rb @@ -4,6 +4,7 @@ module VagrantPlugins module HostsUpdater class Config < Vagrant.plugin("2", :config) attr_accessor :aliases + attr_accessor :remove_on_suspend end end -end \ No newline at end of file +end diff --git a/lib/vagrant-hostsupdater/plugin.rb b/lib/vagrant-hostsupdater/plugin.rb index b419d9c..441cb7c 100644 --- a/lib/vagrant-hostsupdater/plugin.rb +++ b/lib/vagrant-hostsupdater/plugin.rb @@ -35,10 +35,14 @@ class Plugin < Vagrant.plugin('2') hook.append(Action::UpdateHosts) end + action_hook(:hostsupdater, :machine_action_resume) do |hook| + hook.append(Action::UpdateHosts) + end + command(:hostsupdater) do require_relative 'command' Command end end end -end \ No newline at end of file +end