Class: DeployAgent::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/deploy_agent/cli.rb

Instance Method Summary collapse

Instance Method Details

#accesslistObject



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/deploy_agent/cli.rb', line 78

def accesslist
  puts "Access list:"
  DeployAgent.allowed_destinations.each do |destination|
    begin
      IPAddr.new(destination)
      puts " - " + destination
    rescue IPAddr::InvalidAddressError
      puts " - " + destination + " (INVALID)"
    end
  end
  puts
  puts "To edit the list of allowed servers, please modify " + ACCESS_PATH
end

#dispatch(arguments) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/deploy_agent/cli.rb', line 7

def dispatch(arguments)
  methods = self.public_methods(false).delete_if { |n| n == :dispatch }.sort

  @options = {}

  OptionParser.new do |opts|
    opts.on('-v', '--verbose', 'Log extra debug information') do
      @options[:verbose] = true
    end
  end.parse!

  if arguments[0] && methods.include?(arguments[0].to_sym)
    public_send(arguments[0])
  else
    puts "Usage: deploy-agent [#{methods.join('|')}]"
  end
end

#restartObject



29
30
31
32
33
34
35
# File 'lib/deploy_agent/cli.rb', line 29

def restart
  stop
  while(is_running?)
    sleep 0.5
  end
  start
end

#runObject



73
74
75
76
# File 'lib/deploy_agent/cli.rb', line 73

def run
  ensure_configured
  Agent.new(@options).run
end

#setupObject



25
26
27
# File 'lib/deploy_agent/cli.rb', line 25

def setup
  ConfigurationGenerator.new.configure
end

#startObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/deploy_agent/cli.rb', line 37

def start
  if is_running?
    puts "Deploy agent already running. Process ID #{pid_from_file}"
    Process.exit(1)
  else
    ensure_configured
    pid = fork do
      $background = true
      write_pid
      run
    end
    puts "Deploy agent started. Process ID #{pid}"
    Process.detach(pid)
  end
end

#statusObject



64
65
66
67
68
69
70
71
# File 'lib/deploy_agent/cli.rb', line 64

def status
  if is_running?
    puts "Deploy agent is running. PID #{pid_from_file}"
  else
    puts "Deploy agent is not running."
    Process.exit(1)
  end
end

#stopObject



53
54
55
56
57
58
59
60
61
62
# File 'lib/deploy_agent/cli.rb', line 53

def stop
  if is_running?
    pid = pid_from_file
    Process.kill('TERM', pid)
    puts "Deploy agent stopped. Process ID #{pid}"
  else
    puts "Deploy agent is not running"
    Process.exit(1)
  end
end

#versionObject



92
93
94
# File 'lib/deploy_agent/cli.rb', line 92

def version
  puts DeployAgent::VERSION
end