Class: VagrantPlugins::ManagedServers::Action::RebootServer
- Inherits:
-
Object
- Object
- VagrantPlugins::ManagedServers::Action::RebootServer
- Defined in:
- lib/vagrant-managed-servers/action/reboot_server.rb
Overview
reboot the managed server
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ RebootServer
constructor
A new instance of RebootServer.
- #send_reboot(machine) ⇒ Object
Constructor Details
#initialize(app, env) ⇒ RebootServer
Returns a new instance of RebootServer.
10 11 12 13 |
# File 'lib/vagrant-managed-servers/action/reboot_server.rb', line 10 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant_managed_servers::action::reboot_server") end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/vagrant-managed-servers/action/reboot_server.rb', line 15 def call(env) server = env[:machine].id boot_timeout = env[:machine].config.vm.boot_timeout ## This is user configurable, defaults to 300 seconds # "Reboot" env[:ui].info(I18n.t("vagrant_managed_servers.rebooting_server", :host => server)) env[:ui].info(" -- Server: #{server}") send_reboot(env[:machine]) # We don't want to spin endlessly waiting for the machine to come back. # Wait for the config.vm.boot_timeout amount of time. begin Timeout::timeout(boot_timeout) { # keep track of if the server has gone unreachable machine_up = true while machine_up begin # communicate.ready? takes a long time to return false (the indication that the machine has gone down for reboot) # and this was causing the loop to never register that the machine had gone down. So if it has taken a long time to # return, we assume that the machine has indeed gone down. status = Timeout::timeout(5) { machine_up = env[:machine].communicate.ready? } rescue Exception => err # The Timeout::Error is getting swallowed somewhere. If err is execution expired, then the timeout was hit. # Otherwise re-raise err raise err unless err. == "execution expired" # Machine is down. Wait for it to come back up! env[:ui].info(I18n.t("vagrant_managed_servers.waiting_for_server", :host => server)) until env[:machine].communicate.ready? sleep 1 end machine_up = false end sleep 1 env[:ui].info(I18n.t("vagrant_managed_servers.waiting_for_server", :host => server)) end env[:ui].info(" #{server} rebooted and ready.") @app.call(env) } rescue Exception => err raise err unless err. == "execution expired" env[:ui].error("Timed out waiting for machine to reboot!") end end |
#send_reboot(machine) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/vagrant-managed-servers/action/reboot_server.rb', line 59 def send_reboot(machine) if (machine.config.vm.communicator == :winrm) machine.communicate.sudo("shutdown -f -r -t 0") else machine.communicate.sudo("reboot") end end |