Class: VagrantPlugins::HYPERKIT::Action::StopInstance
- Inherits:
-
Object
- Object
- VagrantPlugins::HYPERKIT::Action::StopInstance
- Defined in:
- lib/vagrant-hyperkit/action/stop_instance.rb
Overview
This stops the running instance.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #destroy_xhyve_status_file(env) ⇒ Object
-
#initialize(app, env) ⇒ StopInstance
constructor
A new instance of StopInstance.
- #is_process_alive?(pid) ⇒ Boolean
- #kill_xhyve_process(env) ⇒ Object
- #pid(env) ⇒ Object
Constructor Details
#initialize(app, env) ⇒ StopInstance
Returns a new instance of StopInstance.
8 9 10 11 |
# File 'lib/vagrant-hyperkit/action/stop_instance.rb', line 8 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant_hyperkit::action::stop_instance") end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vagrant-hyperkit/action/stop_instance.rb', line 13 def call(env) if is_process_alive? pid(env) env[:ui].info(I18n.t("vagrant_hyperkit.stopping")) kill_xhyve_process(env) else env[:ui].info(I18n.t("vagrant_hyperkit.already_status", status: env[:machine].state.id)) end destroy_xhyve_status_file(env) @app.call(env) end |
#destroy_xhyve_status_file(env) ⇒ Object
38 39 40 41 |
# File 'lib/vagrant-hyperkit/action/stop_instance.rb', line 38 def destroy_xhyve_status_file(env) xhyve_status_file_path = File.join(env[:machine].data_dir, "xhyve.json") FileUtils.remove_file(xhyve_status_file_path, force: true) end |
#is_process_alive?(pid) ⇒ Boolean
24 25 26 27 28 29 30 31 32 |
# File 'lib/vagrant-hyperkit/action/stop_instance.rb', line 24 def is_process_alive?(pid) return false if pid == 0 begin Process.getpgid(pid) true rescue Errno::ESRCH false end end |
#kill_xhyve_process(env) ⇒ Object
34 35 36 |
# File 'lib/vagrant-hyperkit/action/stop_instance.rb', line 34 def kill_xhyve_process(env) Process.kill(15, pid(env)) end |
#pid(env) ⇒ Object
43 44 45 |
# File 'lib/vagrant-hyperkit/action/stop_instance.rb', line 43 def pid(env) @pid ||= env[:xhyve_status][:pid].to_i end |