Class: Vagrant::DnsdockHostUpdater::Plugin
- Inherits:
-
Object
- Object
- Vagrant::DnsdockHostUpdater::Plugin
- Defined in:
- lib/vagrant-dnsdock-hostupdater/plugin.rb
Class Method Summary collapse
- .close_manager ⇒ Object
- .init_plugin ⇒ Object
- .log(msg) ⇒ Object
- .pid ⇒ Object
-
.pid_path ⇒ Object
Add command for ‘$ vagrant dnsdock-host-updater` command ’dnsdock-host-updater’ do require_relative ‘command’ Command end.
Class Method Details
.close_manager ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vagrant-dnsdock-hostupdater/plugin.rb', line 49 def self.close_manager if pid log "Already running with PID: #{pid}" begin log "Attempting to stop server with PID: #{pid}" Process.kill('KILL', pid.to_i) rescue log "Unable to kill process with ID: #{pid}. This may be because the process has already been terminated." end log "Cleaning up PID file: #{pid_path}" File.delete(pid_path) end end |
.init_plugin ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/vagrant-dnsdock-hostupdater/plugin.rb', line 64 def self.init_plugin server_path = File.('../../server.rb', __FILE__) if @started return end close_manager pid = Process.spawn("ruby #{server_path}") log "Started server with PID: #{pid}" if pid pid_file = File.open(pid_path, 'w') pid_file << pid pid_file.close log "Wrote server PID (#{pid}) to #{pid_path}" Process.detach(pid) @started = true end end |
.log(msg) ⇒ Object
41 42 43 |
# File 'lib/vagrant-dnsdock-hostupdater/plugin.rb', line 41 def self.log(msg) puts "[vagrant-dnsdock-hostupdater] #{msg}" end |
.pid ⇒ Object
45 46 47 |
# File 'lib/vagrant-dnsdock-hostupdater/plugin.rb', line 45 def self.pid File.exist?(pid_path) ? File.read(pid_path) : nil end |
.pid_path ⇒ Object
Add command for ‘$ vagrant dnsdock-host-updater` command ’dnsdock-host-updater’ do
require_relative 'command'
Command
end
37 38 39 |
# File 'lib/vagrant-dnsdock-hostupdater/plugin.rb', line 37 def self.pid_path File.('~/.docker-host-manager.pid') end |