Sha256: 76abbe033bf2698e3256100f052742eba9165a257c7f39dfd0c8dec158a12099
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 KB
Contents
require "log4r" module VagrantPlugins module HYPERKIT module Action # This stops the running instance. class StopInstance def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant_hyperkit::action::stop_instance") end 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 def is_process_alive?(pid) return false if pid == 0 begin Process.getpgid(pid) true rescue Errno::ESRCH false end end def kill_xhyve_process(env) Process.kill(15, pid(env)) end 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 def pid(env) @pid ||= env[:xhyve_status][:pid].to_i end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
vagrant-hyperkit-0.4.3 | lib/vagrant-hyperkit/action/stop_instance.rb |