Class: RightScale::AgentDeployer

Inherits:
Object
  • Object
show all
Includes:
CommonParser
Defined in:
lib/right_agent/scripts/agent_deployer.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CommonParser

#agent_type, #parse_common, #resolve_identity

Class Method Details

.runObject

Create and run deployer

Return

true

Always return true



73
74
75
76
# File 'lib/right_agent/scripts/agent_deployer.rb', line 73

def self.run
  d = AgentDeployer.new
  d.deploy(d.parse_args)
end

Instance Method Details

#deploy(options) ⇒ Object

Generate configuration from specified options and the agent’s base options and write them to a file

Parameters

options(Hash)

Command line options

Return

true

Always return true



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/right_agent/scripts/agent_deployer.rb', line 86

def deploy(options)
  # Initialize directory settings
  AgentConfig.root_dir = options[:root_dir]
  AgentConfig.cfg_dir = options[:cfg_dir]
  AgentConfig.pid_dir = options[:pid_dir]

  # Configure agent
  cfg = load_init_cfg
  check_agent(options, cfg)
  cfg = configure(options, cfg)

  # Persist configuration
  persist(options, cfg)

  # Setup agent monitoring
  monitor(options) if options[:monit]
  true
end

#parse_argsObject

Create options hash from command line arguments

Return

options(Hash)

Parsed options



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/right_agent/scripts/agent_deployer.rb', line 109

def parse_args
  options = {}
  options[:agent_name] = ARGV[0]
  options[:options] = { :secure => true }
  options[:quiet] = false
  fail('No agent specified on the command line', print_usage = true) if options[:agent_name].nil?

  opts = OptionParser.new do |opts|
    parse_common(opts, options)
    parse_other_args(opts, options)

    opts.on('-r', '--root-dir DIR') do |d|
      # Allow for more than one
      if options[:root_dir]
        options[:root_dir] = [options[:root_dir]] unless options[:root_dir].is_a?(Array)
        options[:root_dir] << d
      else
        options[:root_dir] = d
      end
    end

    opts.on('-c', '--cfg-dir DIR') do |d|
      options[:cfg_dir] = d
    end

    opts.on('-z', '--pid-dir DIR') do |d|
      options[:pid_dir] = d
    end

    opts.on('-w', '--monit') do
      options[:monit] = true
    end

    opts.on('-S', '--secure-identity') do
      options[:secure_identity] = true
    end

    opts.on('--http-proxy PROXY') do |proxy|
      options[:http_proxy] = proxy
    end

    opts.on('--http-no-proxy NOPROXY') do |no_proxy|
      options[:http_no_proxy] = no_proxy
    end

    opts.on('--time-to-live SEC') do |sec|
      options[:time_to_live] = sec.to_i
    end

    opts.on('--retry-timeout SEC') do |sec|
      options[:retry_timeout] = sec.to_i
    end

    opts.on('--retry-interval SEC') do |sec|
      options[:retry_interval] = sec.to_i
    end

    opts.on('--check-interval SEC') do |sec|
      options[:check_interval] = sec.to_i
    end

    opts.on('--ping-interval SEC') do |sec|
      options[:ping_interval] = sec.to_i
    end

    opts.on('--reconnect-interval SEC') do |sec|
      options[:reconnect_interval] = sec.to_i
    end

    opts.on('--grace-timeout SEC') do |sec|
      options[:grace_timeout] = sec.to_i
    end

    opts.on('--[no-]dup-check') do |b|
      options[:dup_check] = b
    end

    opts.on('--prefetch COUNT') do |count|
      options[:prefetch] = count.to_i
    end

    opts.on('-b', '--heartbeat SEC') do |sec|
      options[:heartbeat] = sec.to_i
    end

    opts.on('-o', '--options OPT') do |e|
      fail("Invalid option definition #{e}' (use '=' to separate name and value)") unless e.include?('=')
      key, val = e.split(/=/)
      options[:options][key.gsub('-', '_').to_sym] = val
    end

    opts.on('-Q', '--quiet') do
      options[:quiet] = true
    end

    opts.on_tail('--help') do
      puts Usage.scan(__FILE__)
      exit
    end
  end
  begin
    opts.parse!(ARGV)
  rescue Exception => e
    exit 0 if e.is_a?(SystemExit)
    fail(e.message, print_usage = true)
  end
  resolve_identity(options)
  options
end