right_agent 2.0.7-x86-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.rdoc +82 -0
- data/Rakefile +113 -0
- data/lib/right_agent.rb +59 -0
- data/lib/right_agent/actor.rb +182 -0
- data/lib/right_agent/actor_registry.rb +76 -0
- data/lib/right_agent/actors/agent_manager.rb +232 -0
- data/lib/right_agent/agent.rb +1149 -0
- data/lib/right_agent/agent_config.rb +480 -0
- data/lib/right_agent/agent_identity.rb +210 -0
- data/lib/right_agent/agent_tag_manager.rb +237 -0
- data/lib/right_agent/audit_formatter.rb +107 -0
- data/lib/right_agent/clients.rb +31 -0
- data/lib/right_agent/clients/api_client.rb +383 -0
- data/lib/right_agent/clients/auth_client.rb +247 -0
- data/lib/right_agent/clients/balanced_http_client.rb +369 -0
- data/lib/right_agent/clients/base_retry_client.rb +495 -0
- data/lib/right_agent/clients/right_http_client.rb +279 -0
- data/lib/right_agent/clients/router_client.rb +493 -0
- data/lib/right_agent/command.rb +30 -0
- data/lib/right_agent/command/agent_manager_commands.rb +150 -0
- data/lib/right_agent/command/command_client.rb +136 -0
- data/lib/right_agent/command/command_constants.rb +33 -0
- data/lib/right_agent/command/command_io.rb +126 -0
- data/lib/right_agent/command/command_parser.rb +87 -0
- data/lib/right_agent/command/command_runner.rb +118 -0
- data/lib/right_agent/command/command_serializer.rb +63 -0
- data/lib/right_agent/connectivity_checker.rb +179 -0
- data/lib/right_agent/console.rb +65 -0
- data/lib/right_agent/core_payload_types.rb +44 -0
- data/lib/right_agent/core_payload_types/cookbook.rb +61 -0
- data/lib/right_agent/core_payload_types/cookbook_position.rb +46 -0
- data/lib/right_agent/core_payload_types/cookbook_repository.rb +116 -0
- data/lib/right_agent/core_payload_types/cookbook_sequence.rb +70 -0
- data/lib/right_agent/core_payload_types/dev_repositories.rb +100 -0
- data/lib/right_agent/core_payload_types/dev_repository.rb +76 -0
- data/lib/right_agent/core_payload_types/event_categories.rb +38 -0
- data/lib/right_agent/core_payload_types/executable_bundle.rb +130 -0
- data/lib/right_agent/core_payload_types/login_policy.rb +72 -0
- data/lib/right_agent/core_payload_types/login_user.rb +79 -0
- data/lib/right_agent/core_payload_types/planned_volume.rb +94 -0
- data/lib/right_agent/core_payload_types/recipe_instantiation.rb +73 -0
- data/lib/right_agent/core_payload_types/repositories_bundle.rb +50 -0
- data/lib/right_agent/core_payload_types/right_script_attachment.rb +95 -0
- data/lib/right_agent/core_payload_types/right_script_instantiation.rb +94 -0
- data/lib/right_agent/core_payload_types/runlist_policy.rb +44 -0
- data/lib/right_agent/core_payload_types/secure_document.rb +66 -0
- data/lib/right_agent/core_payload_types/secure_document_location.rb +63 -0
- data/lib/right_agent/core_payload_types/software_repository_instantiation.rb +61 -0
- data/lib/right_agent/daemonize.rb +35 -0
- data/lib/right_agent/dispatched_cache.rb +109 -0
- data/lib/right_agent/dispatcher.rb +272 -0
- data/lib/right_agent/enrollment_result.rb +221 -0
- data/lib/right_agent/exceptions.rb +87 -0
- data/lib/right_agent/history.rb +145 -0
- data/lib/right_agent/log.rb +460 -0
- data/lib/right_agent/minimal.rb +46 -0
- data/lib/right_agent/monkey_patches.rb +30 -0
- data/lib/right_agent/monkey_patches/ruby_patch.rb +55 -0
- data/lib/right_agent/monkey_patches/ruby_patch/array_patch.rb +29 -0
- data/lib/right_agent/monkey_patches/ruby_patch/darwin_patch.rb +24 -0
- data/lib/right_agent/monkey_patches/ruby_patch/linux_patch.rb +24 -0
- data/lib/right_agent/monkey_patches/ruby_patch/linux_patch/file_patch.rb +30 -0
- data/lib/right_agent/monkey_patches/ruby_patch/object_patch.rb +49 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch.rb +32 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/file_patch.rb +60 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/process_patch.rb +63 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/stdio_patch.rb +27 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/time_patch.rb +55 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/win32ole_patch.rb +34 -0
- data/lib/right_agent/multiplexer.rb +102 -0
- data/lib/right_agent/offline_handler.rb +270 -0
- data/lib/right_agent/operation_result.rb +300 -0
- data/lib/right_agent/packets.rb +673 -0
- data/lib/right_agent/payload_formatter.rb +104 -0
- data/lib/right_agent/pending_requests.rb +128 -0
- data/lib/right_agent/pid_file.rb +159 -0
- data/lib/right_agent/platform.rb +770 -0
- data/lib/right_agent/platform/unix/darwin/platform.rb +102 -0
- data/lib/right_agent/platform/unix/linux/platform.rb +305 -0
- data/lib/right_agent/platform/unix/platform.rb +226 -0
- data/lib/right_agent/platform/windows/mingw/platform.rb +447 -0
- data/lib/right_agent/platform/windows/mswin/platform.rb +236 -0
- data/lib/right_agent/platform/windows/platform.rb +1808 -0
- data/lib/right_agent/protocol_version_mixin.rb +69 -0
- data/lib/right_agent/retryable_request.rb +195 -0
- data/lib/right_agent/scripts/agent_controller.rb +543 -0
- data/lib/right_agent/scripts/agent_deployer.rb +400 -0
- data/lib/right_agent/scripts/common_parser.rb +160 -0
- data/lib/right_agent/scripts/log_level_manager.rb +192 -0
- data/lib/right_agent/scripts/stats_manager.rb +268 -0
- data/lib/right_agent/scripts/usage.rb +58 -0
- data/lib/right_agent/secure_identity.rb +92 -0
- data/lib/right_agent/security.rb +32 -0
- data/lib/right_agent/security/cached_certificate_store_proxy.rb +77 -0
- data/lib/right_agent/security/certificate.rb +102 -0
- data/lib/right_agent/security/certificate_cache.rb +89 -0
- data/lib/right_agent/security/distinguished_name.rb +56 -0
- data/lib/right_agent/security/encrypted_document.rb +83 -0
- data/lib/right_agent/security/rsa_key_pair.rb +76 -0
- data/lib/right_agent/security/signature.rb +86 -0
- data/lib/right_agent/security/static_certificate_store.rb +85 -0
- data/lib/right_agent/sender.rb +792 -0
- data/lib/right_agent/serialize.rb +29 -0
- data/lib/right_agent/serialize/message_pack.rb +107 -0
- data/lib/right_agent/serialize/secure_serializer.rb +151 -0
- data/lib/right_agent/serialize/secure_serializer_initializer.rb +47 -0
- data/lib/right_agent/serialize/serializable.rb +151 -0
- data/lib/right_agent/serialize/serializer.rb +159 -0
- data/lib/right_agent/subprocess.rb +38 -0
- data/lib/right_agent/tracer.rb +124 -0
- data/right_agent.gemspec +101 -0
- data/spec/actor_registry_spec.rb +80 -0
- data/spec/actor_spec.rb +162 -0
- data/spec/agent_config_spec.rb +235 -0
- data/spec/agent_identity_spec.rb +78 -0
- data/spec/agent_spec.rb +734 -0
- data/spec/agent_tag_manager_spec.rb +319 -0
- data/spec/clients/api_client_spec.rb +423 -0
- data/spec/clients/auth_client_spec.rb +272 -0
- data/spec/clients/balanced_http_client_spec.rb +576 -0
- data/spec/clients/base_retry_client_spec.rb +635 -0
- data/spec/clients/router_client_spec.rb +594 -0
- data/spec/clients/spec_helper.rb +111 -0
- data/spec/command/agent_manager_commands_spec.rb +51 -0
- data/spec/command/command_io_spec.rb +93 -0
- data/spec/command/command_parser_spec.rb +79 -0
- data/spec/command/command_runner_spec.rb +107 -0
- data/spec/command/command_serializer_spec.rb +51 -0
- data/spec/connectivity_checker_spec.rb +83 -0
- data/spec/core_payload_types/dev_repositories_spec.rb +64 -0
- data/spec/core_payload_types/dev_repository_spec.rb +33 -0
- data/spec/core_payload_types/executable_bundle_spec.rb +67 -0
- data/spec/core_payload_types/login_user_spec.rb +102 -0
- data/spec/core_payload_types/recipe_instantiation_spec.rb +81 -0
- data/spec/core_payload_types/right_script_attachment_spec.rb +65 -0
- data/spec/core_payload_types/right_script_instantiation_spec.rb +79 -0
- data/spec/core_payload_types/spec_helper.rb +23 -0
- data/spec/dispatched_cache_spec.rb +136 -0
- data/spec/dispatcher_spec.rb +324 -0
- data/spec/enrollment_result_spec.rb +53 -0
- data/spec/history_spec.rb +246 -0
- data/spec/log_spec.rb +192 -0
- data/spec/monkey_patches/eventmachine_spec.rb +62 -0
- data/spec/multiplexer_spec.rb +48 -0
- data/spec/offline_handler_spec.rb +340 -0
- data/spec/operation_result_spec.rb +208 -0
- data/spec/packets_spec.rb +461 -0
- data/spec/pending_requests_spec.rb +136 -0
- data/spec/platform/spec_helper.rb +216 -0
- data/spec/platform/unix/darwin/platform_spec.rb +181 -0
- data/spec/platform/unix/linux/platform_spec.rb +540 -0
- data/spec/platform/unix/spec_helper.rb +149 -0
- data/spec/platform/windows/mingw/platform_spec.rb +222 -0
- data/spec/platform/windows/mswin/platform_spec.rb +259 -0
- data/spec/platform/windows/spec_helper.rb +720 -0
- data/spec/retryable_request_spec.rb +306 -0
- data/spec/secure_identity_spec.rb +50 -0
- data/spec/security/cached_certificate_store_proxy_spec.rb +62 -0
- data/spec/security/certificate_cache_spec.rb +71 -0
- data/spec/security/certificate_spec.rb +49 -0
- data/spec/security/distinguished_name_spec.rb +46 -0
- data/spec/security/encrypted_document_spec.rb +55 -0
- data/spec/security/rsa_key_pair_spec.rb +55 -0
- data/spec/security/signature_spec.rb +66 -0
- data/spec/security/static_certificate_store_spec.rb +58 -0
- data/spec/sender_spec.rb +1045 -0
- data/spec/serialize/message_pack_spec.rb +131 -0
- data/spec/serialize/secure_serializer_spec.rb +132 -0
- data/spec/serialize/serializable_spec.rb +90 -0
- data/spec/serialize/serializer_spec.rb +197 -0
- data/spec/spec.opts +2 -0
- data/spec/spec.win32.opts +1 -0
- data/spec/spec_helper.rb +130 -0
- data/spec/tracer_spec.rb +114 -0
- metadata +447 -0
@@ -0,0 +1,400 @@
|
|
1
|
+
# === Synopsis:
|
2
|
+
# RightScale RightAgent Deployer (rad) - (c) 2009-2011 RightScale Inc
|
3
|
+
#
|
4
|
+
# rad is a command line tool for building the configuration file for a RightAgent
|
5
|
+
#
|
6
|
+
# The configuration file is generated in:
|
7
|
+
# <agent name>/config.yml
|
8
|
+
# in platform-specific RightAgent configuration directory
|
9
|
+
#
|
10
|
+
# === Usage:
|
11
|
+
# rad AGENT [options]
|
12
|
+
#
|
13
|
+
# options:
|
14
|
+
# --root-dir, -r DIR Set agent root directory (containing init, actors, and certs subdirectories)
|
15
|
+
# --cfg-dir, -c DIR Set directory where generated configuration files for all agents are stored
|
16
|
+
# --pid-dir, -z DIR Set directory containing process id file
|
17
|
+
# --identity, -i ID Use this as base ID to build agent's identity
|
18
|
+
# --token, -t TOKEN Use this token to build agent's identity with it plugging
|
19
|
+
# directly in unless --secure-identity is specified
|
20
|
+
# --secure-identity, -S Derive token used in agent identity from given TOKEN and ID
|
21
|
+
# --prefix, -x PREFIX Use this prefix to build agent's identity
|
22
|
+
# --type TYPE Use this agent type to build agent's' identity;
|
23
|
+
# defaults to AGENT with any trailing '_[0-9]+' removed
|
24
|
+
# --api-url, -a URL Set URL for HTTP access to RightApi
|
25
|
+
# --account, -A ID Set identifier for account owning this agent
|
26
|
+
# --shard, -s ID Set identifier for database shard in which this agent is operating
|
27
|
+
# --mode, -m MODE Set communication mode this agent is to use: :http or :amqp
|
28
|
+
# --url URL Set agent AMQP connection URL (host, port, user, pass, vhost)
|
29
|
+
# --user, -u USER Set agent AMQP username
|
30
|
+
# --password, -p PASS Set agent AMQP password
|
31
|
+
# --vhost, -v VHOST Set agent AMQP virtual host
|
32
|
+
# --host, -h HOST Set AMQP broker host
|
33
|
+
# --port, -P PORT Set AMQP broker port
|
34
|
+
# --heartbeat, -b SEC Set number of seconds between AMQP broker connection heartbeats, 0 means disable
|
35
|
+
# --prefetch COUNT Set maximum requests AMQP broker is to prefetch before current is ack'd
|
36
|
+
# --http-proxy PROXY Use a proxy for all agent-originated HTTP traffic
|
37
|
+
# --http-no-proxy NOPROXY Comma-separated list of proxy exceptions (e.g. metadata server)
|
38
|
+
# --time-to-live SEC Set maximum age in seconds before a request times out and is rejected
|
39
|
+
# --retry-timeout SEC Set maximum number of seconds to retry request before give up
|
40
|
+
# --retry-interval SEC Set number of seconds before initial request retry, increases exponentially
|
41
|
+
# --check-interval SEC Set number of seconds between failed connection checks, increases exponentially
|
42
|
+
# --ping-interval SEC Set minimum number of seconds since last message receipt for the agent
|
43
|
+
# to ping the RightNet router to check connectivity, 0 means disable ping
|
44
|
+
# --reconnect-interval SEC Set number of seconds between HTTP or AMQP reconnect attempts
|
45
|
+
# --grace-timeout SEC Set number of seconds before graceful termination times out
|
46
|
+
# --[no-]dup-check Set whether to check for and reject duplicate requests, .e.g., due to retries
|
47
|
+
# --options, -o KEY=VAL Set options that act as final override for any persisted configuration settings
|
48
|
+
# --monit Generate monit configuration file
|
49
|
+
# --test Build test deployment using default test settings
|
50
|
+
# --quiet, -Q Do not produce output
|
51
|
+
# --help Display help
|
52
|
+
|
53
|
+
require 'rubygems'
|
54
|
+
require 'optparse'
|
55
|
+
require 'fileutils'
|
56
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'usage'))
|
57
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'right_agent'))
|
58
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'common_parser'))
|
59
|
+
|
60
|
+
module RightScale
|
61
|
+
|
62
|
+
class AgentDeployer
|
63
|
+
|
64
|
+
include CommonParser
|
65
|
+
|
66
|
+
# Create and run deployer
|
67
|
+
#
|
68
|
+
# === Return
|
69
|
+
# true:: Always return true
|
70
|
+
def self.run
|
71
|
+
d = AgentDeployer.new
|
72
|
+
d.deploy(d.parse_args)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Generate configuration from specified options and the agent's base options
|
76
|
+
# and write them to a file
|
77
|
+
#
|
78
|
+
# === Parameters
|
79
|
+
# options(Hash):: Command line options
|
80
|
+
#
|
81
|
+
# === Return
|
82
|
+
# true:: Always return true
|
83
|
+
def deploy(options)
|
84
|
+
# Initialize directory settings
|
85
|
+
AgentConfig.root_dir = options[:root_dir]
|
86
|
+
AgentConfig.cfg_dir = options[:cfg_dir]
|
87
|
+
AgentConfig.pid_dir = options[:pid_dir]
|
88
|
+
|
89
|
+
# Configure agent
|
90
|
+
cfg = load_init_cfg
|
91
|
+
check_agent(options, cfg)
|
92
|
+
cfg = configure(options, cfg)
|
93
|
+
|
94
|
+
# Persist configuration
|
95
|
+
persist(options, cfg)
|
96
|
+
|
97
|
+
# Setup agent monitoring
|
98
|
+
monitor(options) if options[:monit]
|
99
|
+
true
|
100
|
+
end
|
101
|
+
|
102
|
+
# Create options hash from command line arguments
|
103
|
+
#
|
104
|
+
# === Return
|
105
|
+
# options(Hash):: Parsed options
|
106
|
+
def parse_args
|
107
|
+
options = {}
|
108
|
+
options[:agent_name] = ARGV[0]
|
109
|
+
options[:options] = { :secure => true }
|
110
|
+
options[:quiet] = false
|
111
|
+
fail('No agent specified on the command line', print_usage = true) if options[:agent_name].nil?
|
112
|
+
|
113
|
+
opts = OptionParser.new do |opts|
|
114
|
+
parse_common(opts, options)
|
115
|
+
parse_other_args(opts, options)
|
116
|
+
|
117
|
+
opts.on('-r', '--root-dir DIR') do |d|
|
118
|
+
# Allow for more than one
|
119
|
+
if options[:root_dir]
|
120
|
+
options[:root_dir] = [options[:root_dir]] unless options[:root_dir].is_a?(Array)
|
121
|
+
options[:root_dir] << d
|
122
|
+
else
|
123
|
+
options[:root_dir] = d
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
opts.on('-c', '--cfg-dir DIR') do |d|
|
128
|
+
options[:cfg_dir] = d
|
129
|
+
end
|
130
|
+
|
131
|
+
opts.on('-z', '--pid-dir DIR') do |d|
|
132
|
+
options[:pid_dir] = d
|
133
|
+
end
|
134
|
+
|
135
|
+
opts.on('--monit') do
|
136
|
+
options[:monit] = true
|
137
|
+
end
|
138
|
+
|
139
|
+
opts.on('--http-proxy PROXY') do |proxy|
|
140
|
+
options[:http_proxy] = proxy
|
141
|
+
end
|
142
|
+
|
143
|
+
opts.on('--http-no-proxy NOPROXY') do |no_proxy|
|
144
|
+
options[:http_no_proxy] = no_proxy
|
145
|
+
end
|
146
|
+
|
147
|
+
opts.on('--time-to-live SEC') do |sec|
|
148
|
+
options[:time_to_live] = sec.to_i
|
149
|
+
end
|
150
|
+
|
151
|
+
opts.on('--retry-timeout SEC') do |sec|
|
152
|
+
options[:retry_timeout] = sec.to_i
|
153
|
+
end
|
154
|
+
|
155
|
+
opts.on('--retry-interval SEC') do |sec|
|
156
|
+
options[:retry_interval] = sec.to_i
|
157
|
+
end
|
158
|
+
|
159
|
+
opts.on('--check-interval SEC') do |sec|
|
160
|
+
options[:check_interval] = sec.to_i
|
161
|
+
end
|
162
|
+
|
163
|
+
opts.on('--ping-interval SEC') do |sec|
|
164
|
+
options[:ping_interval] = sec.to_i
|
165
|
+
end
|
166
|
+
|
167
|
+
opts.on('--reconnect-interval SEC') do |sec|
|
168
|
+
options[:reconnect_interval] = sec.to_i
|
169
|
+
end
|
170
|
+
|
171
|
+
opts.on('--grace-timeout SEC') do |sec|
|
172
|
+
options[:grace_timeout] = sec.to_i
|
173
|
+
end
|
174
|
+
|
175
|
+
opts.on('--[no-]dup-check') do |b|
|
176
|
+
options[:dup_check] = b
|
177
|
+
end
|
178
|
+
|
179
|
+
opts.on('--prefetch COUNT') do |count|
|
180
|
+
options[:prefetch] = count.to_i
|
181
|
+
end
|
182
|
+
|
183
|
+
opts.on("-a", "--api-url URL") do |url|
|
184
|
+
options[:api_url] = url
|
185
|
+
end
|
186
|
+
|
187
|
+
opts.on('-A', '--account ID') do |id|
|
188
|
+
options[:account_id] = id.to_i
|
189
|
+
end
|
190
|
+
|
191
|
+
opts.on('-s', '--shard ID') do |id|
|
192
|
+
options[:shard_id] = id.to_i
|
193
|
+
end
|
194
|
+
|
195
|
+
opts.on('-m', '--mode MODE') do |mode|
|
196
|
+
options[:mode] = mode
|
197
|
+
end
|
198
|
+
|
199
|
+
opts.on('-b', '--heartbeat SEC') do |sec|
|
200
|
+
options[:heartbeat] = sec.to_i
|
201
|
+
end
|
202
|
+
|
203
|
+
opts.on('-o', '--options OPT') do |e|
|
204
|
+
fail("Invalid option definition #{e}' (use '=' to separate name and value)") unless e.include?('=')
|
205
|
+
key, val = e.split(/=/)
|
206
|
+
options[:options][key.gsub('-', '_').to_sym] = val
|
207
|
+
end
|
208
|
+
|
209
|
+
opts.on('-Q', '--quiet') do
|
210
|
+
options[:quiet] = true
|
211
|
+
end
|
212
|
+
|
213
|
+
opts.on_tail('--help') do
|
214
|
+
puts Usage.scan(__FILE__)
|
215
|
+
exit
|
216
|
+
end
|
217
|
+
end
|
218
|
+
begin
|
219
|
+
opts.parse!(ARGV)
|
220
|
+
rescue Exception => e
|
221
|
+
exit 0 if e.is_a?(SystemExit)
|
222
|
+
fail(e.message, print_usage = true)
|
223
|
+
end
|
224
|
+
resolve_identity(options)
|
225
|
+
options
|
226
|
+
end
|
227
|
+
|
228
|
+
protected
|
229
|
+
|
230
|
+
# Parse any other arguments used by agent
|
231
|
+
#
|
232
|
+
# === Parameters
|
233
|
+
# opts(OptionParser):: Options parser with options to be parsed
|
234
|
+
# options(Hash):: Storage for options that are parsed
|
235
|
+
#
|
236
|
+
# === Return
|
237
|
+
# true:: Always return true
|
238
|
+
def parse_other_args(opts, options)
|
239
|
+
true
|
240
|
+
end
|
241
|
+
|
242
|
+
# Load initial configuration for agent, if any
|
243
|
+
#
|
244
|
+
# === Return
|
245
|
+
# cfg(Hash):: Initial agent configuration options
|
246
|
+
def load_init_cfg
|
247
|
+
cfg = {}
|
248
|
+
if (cfg_file = AgentConfig.init_cfg_file) && (cfg_data = YAML.load(IO.read(cfg_file)))
|
249
|
+
cfg = SerializationHelper.symbolize_keys(cfg_data) rescue nil
|
250
|
+
fail("Cannot read configuration for agent #{cfg_file.inspect}") unless cfg
|
251
|
+
end
|
252
|
+
cfg
|
253
|
+
end
|
254
|
+
|
255
|
+
# Check agent type consistency and existence of initialization file and actors directory
|
256
|
+
#
|
257
|
+
# === Parameters
|
258
|
+
# options(Hash):: Command line options
|
259
|
+
# cfg(Hash):: Initial configuration settings
|
260
|
+
#
|
261
|
+
# === Return
|
262
|
+
# true:: Always return true
|
263
|
+
def check_agent(options, cfg)
|
264
|
+
identity = options[:identity]
|
265
|
+
agent_type = options[:agent_type]
|
266
|
+
type = AgentIdentity.parse(identity).agent_type if identity
|
267
|
+
fail("Agent type #{agent_type.inspect} and identity #{identity.inspect} are inconsistent") if agent_type != type
|
268
|
+
fail("Cannot find agent init.rb file in init directory of #{AgentConfig.root_dir.inspect}") unless AgentConfig.init_file
|
269
|
+
|
270
|
+
actors = cfg[:actors]
|
271
|
+
fail('Agent configuration is missing actors') unless actors && actors.respond_to?(:each)
|
272
|
+
actors_dirs = AgentConfig.actors_dirs
|
273
|
+
actors.each do |a|
|
274
|
+
found = false
|
275
|
+
actors_dirs.each { |d| break if found = File.exist?(File.normalize_path(File.join(d, "#{a}.rb"))) }
|
276
|
+
fail("Cannot find source for actor #{a.inspect} in #{actors_dirs.inspect}") unless found
|
277
|
+
end
|
278
|
+
true
|
279
|
+
end
|
280
|
+
|
281
|
+
# Determine configuration settings to be persisted
|
282
|
+
#
|
283
|
+
# === Parameters
|
284
|
+
# options(Hash):: Command line options
|
285
|
+
# cfg(Hash):: Initial configuration settings
|
286
|
+
#
|
287
|
+
# === Return
|
288
|
+
# cfg(Hash):: Configuration settings
|
289
|
+
def configure(options, cfg)
|
290
|
+
cfg[:root_dir] = AgentConfig.root_dir
|
291
|
+
cfg[:pid_dir] = AgentConfig.pid_dir
|
292
|
+
cfg[:identity] = options[:identity] if options[:identity]
|
293
|
+
cfg[:token] = options[:token] if options[:token]
|
294
|
+
cfg[:api_url] = options[:api_url] if options[:api_url]
|
295
|
+
cfg[:account_id] = options[:account_id] if options[:account_id]
|
296
|
+
cfg[:shard_id] = options[:shard_id] if options[:shard_id]
|
297
|
+
cfg[:mode] = options[:mode] if options[:mode]
|
298
|
+
cfg[:user] = options[:user] if options[:user]
|
299
|
+
cfg[:pass] = options[:pass] if options[:pass]
|
300
|
+
cfg[:vhost] = options[:vhost] if options[:vhost]
|
301
|
+
cfg[:port] = options[:port] if options[:port]
|
302
|
+
cfg[:host] = options[:host] if options[:host]
|
303
|
+
cfg[:prefetch] = options[:prefetch] || 1
|
304
|
+
cfg[:heartbeat] = options[:heartbeat] if options[:heartbeat]
|
305
|
+
cfg[:time_to_live] = options[:time_to_live] || 60
|
306
|
+
cfg[:retry_timeout] = options[:retry_timeout] || 60
|
307
|
+
cfg[:retry_interval] = options[:retry_interval] || 5
|
308
|
+
cfg[:ping_interval] = options[:ping_interval] ||= 4 * 60 * 60
|
309
|
+
cfg[:check_interval] = options[:check_interval] if options[:check_interval]
|
310
|
+
cfg[:reconnect_interval] = options[:reconnect_interval] if options[:reconnect_interval]
|
311
|
+
cfg[:grace_timeout] = options[:grace_timeout] if options[:grace_timeout]
|
312
|
+
cfg[:dup_check] = options[:dup_check].nil? ? true : options[:dup_check]
|
313
|
+
cfg[:http_proxy] = options[:http_proxy] if options[:http_proxy]
|
314
|
+
cfg[:http_no_proxy] = options[:http_no_proxy] if options[:http_no_proxy]
|
315
|
+
cfg
|
316
|
+
end
|
317
|
+
|
318
|
+
# Write configuration options to file after applying any overrides
|
319
|
+
#
|
320
|
+
# === Parameters
|
321
|
+
# options(Hash):: Command line options
|
322
|
+
# cfg(Hash):: Configurations options with which specified options are to be merged
|
323
|
+
#
|
324
|
+
# === Return
|
325
|
+
# true:: Always return true
|
326
|
+
def persist(options, cfg)
|
327
|
+
overrides = options[:options]
|
328
|
+
overrides.each { |k, v| cfg[k] = v } if overrides
|
329
|
+
cfg_file = AgentConfig.store_cfg(options[:agent_name], cfg)
|
330
|
+
unless options[:quiet]
|
331
|
+
puts "Generated configuration file for #{options[:agent_name]} agent: #{cfg_file}" unless options[:quiet]
|
332
|
+
end
|
333
|
+
true
|
334
|
+
end
|
335
|
+
|
336
|
+
# Setup agent monitoring
|
337
|
+
#
|
338
|
+
# === Parameters
|
339
|
+
# options(Hash):: Command line options
|
340
|
+
#
|
341
|
+
# === Return
|
342
|
+
# true:: Always return true
|
343
|
+
def monitor(options)
|
344
|
+
agent_name = options[:agent_name]
|
345
|
+
identity = options[:identity]
|
346
|
+
pid_file = PidFile.new(identity)
|
347
|
+
cfg = <<-EOF
|
348
|
+
check process #{agent_name}
|
349
|
+
with pidfile \"#{pid_file}\"
|
350
|
+
start program \"/opt/rightscale/bin/rnac --start #{agent_name}\"
|
351
|
+
stop program \"/opt/rightscale/bin/rnac --stop #{agent_name}\"
|
352
|
+
mode manual
|
353
|
+
EOF
|
354
|
+
cfg_file = File.join(AgentConfig.cfg_dir, agent_name, "#{identity}.conf")
|
355
|
+
File.open(cfg_file, 'w') { |f| f.puts(cfg) }
|
356
|
+
File.chmod(0600, cfg_file) # monit requires strict perms on this file
|
357
|
+
puts " - agent monit config: #{cfg_file}" unless options[:quiet]
|
358
|
+
true
|
359
|
+
end
|
360
|
+
|
361
|
+
|
362
|
+
# Print error on console and exit abnormally
|
363
|
+
#
|
364
|
+
# === Parameters
|
365
|
+
# message(String):: Error message to be displayed
|
366
|
+
# print_usage(Boolean):: Whether to display usage information
|
367
|
+
#
|
368
|
+
# === Return
|
369
|
+
# never return
|
370
|
+
def fail(message = nil, print_usage = false)
|
371
|
+
puts "** #{message}" if message
|
372
|
+
puts Usage.scan(__FILE__) if print_usage
|
373
|
+
exit(1)
|
374
|
+
end
|
375
|
+
|
376
|
+
end
|
377
|
+
|
378
|
+
end
|
379
|
+
|
380
|
+
#
|
381
|
+
# Copyright (c) 2009-2011 RightScale Inc
|
382
|
+
#
|
383
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
384
|
+
# a copy of this software and associated documentation files (the
|
385
|
+
# "Software"), to deal in the Software without restriction, including
|
386
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
387
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
388
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
389
|
+
# the following conditions:
|
390
|
+
#
|
391
|
+
# The above copyright notice and this permission notice shall be
|
392
|
+
# included in all copies or substantial portions of the Software.
|
393
|
+
#
|
394
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
395
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
396
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
397
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
398
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
399
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
400
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,160 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2009-2011 RightScale Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
require 'uri'
|
24
|
+
require 'tmpdir'
|
25
|
+
|
26
|
+
require File.normalize_path(File.join(File.dirname(__FILE__), '..', 'agent_identity'))
|
27
|
+
|
28
|
+
# Common options parser
|
29
|
+
module RightScale
|
30
|
+
|
31
|
+
module CommonParser
|
32
|
+
|
33
|
+
# Parse common options between rad and rnac
|
34
|
+
#
|
35
|
+
# === Parameters
|
36
|
+
# opts(OptionParser):: Options parser with options to be parsed
|
37
|
+
# options(Hash):: Storage for options that are parsed
|
38
|
+
#
|
39
|
+
# === Return
|
40
|
+
# true:: Always return true
|
41
|
+
def parse_common(opts, options)
|
42
|
+
|
43
|
+
opts.on("--test") do
|
44
|
+
options[:user] = 'test'
|
45
|
+
options[:pass] = 'testing'
|
46
|
+
options[:vhost] = '/right_net'
|
47
|
+
options[:test] = true
|
48
|
+
options[:pid_dir] = Dir.tmpdir
|
49
|
+
options[:base_id] = "#{rand(1000000)}"
|
50
|
+
options[:options][:log_dir] = Dir.tmpdir
|
51
|
+
end
|
52
|
+
|
53
|
+
opts.on("-i", "--identity ID") do |id|
|
54
|
+
options[:base_id] = id
|
55
|
+
end
|
56
|
+
|
57
|
+
opts.on("-t", "--token TOKEN") do |t|
|
58
|
+
options[:token] = t
|
59
|
+
end
|
60
|
+
|
61
|
+
opts.on("-S", "--secure-identity") do
|
62
|
+
options[:secure_identity] = true
|
63
|
+
end
|
64
|
+
|
65
|
+
opts.on("-x", "--prefix PREFIX") do |p|
|
66
|
+
options[:prefix] = p
|
67
|
+
end
|
68
|
+
|
69
|
+
opts.on("--url URL") do |url|
|
70
|
+
uri = URI.parse(url)
|
71
|
+
options[:user] = uri.user if uri.user
|
72
|
+
options[:pass] = uri.password if uri.password
|
73
|
+
options[:host] = uri.host
|
74
|
+
options[:port] = uri.port if uri.port
|
75
|
+
options[:vhost] = uri.path if (uri.path && !uri.path.empty?)
|
76
|
+
end
|
77
|
+
|
78
|
+
opts.on("-u", "--user USER") do |user|
|
79
|
+
options[:user] = user
|
80
|
+
end
|
81
|
+
|
82
|
+
opts.on("-p", "--pass PASSWORD") do |pass|
|
83
|
+
options[:pass] = pass
|
84
|
+
end
|
85
|
+
|
86
|
+
opts.on("-v", "--vhost VHOST") do |vhost|
|
87
|
+
options[:vhost] = vhost
|
88
|
+
end
|
89
|
+
|
90
|
+
opts.on("-P", "--port PORT") do |port|
|
91
|
+
options[:port] = port
|
92
|
+
end
|
93
|
+
|
94
|
+
opts.on("-h", "--host HOST") do |host|
|
95
|
+
options[:host] = host
|
96
|
+
end
|
97
|
+
|
98
|
+
opts.on('--type TYPE') do |t|
|
99
|
+
options[:agent_type] = t
|
100
|
+
end
|
101
|
+
|
102
|
+
opts.on_tail("--help") do
|
103
|
+
puts Usage.scan(__FILE__)
|
104
|
+
exit
|
105
|
+
end
|
106
|
+
|
107
|
+
opts.on_tail("--version") do
|
108
|
+
puts version
|
109
|
+
exit
|
110
|
+
end
|
111
|
+
true
|
112
|
+
end
|
113
|
+
|
114
|
+
# Generate agent identity from options
|
115
|
+
# Build identity from base_id, token, prefix and agent name
|
116
|
+
#
|
117
|
+
# === Parameters
|
118
|
+
# options(Hash):: Hash containing identity components
|
119
|
+
#
|
120
|
+
# === Return
|
121
|
+
# options(Hash)::
|
122
|
+
def resolve_identity(options)
|
123
|
+
options[:agent_type] = agent_type(options[:agent_type], options[:agent_name])
|
124
|
+
if options[:base_id]
|
125
|
+
base_id = options[:base_id].to_i
|
126
|
+
if base_id.abs.to_s != options[:base_id]
|
127
|
+
puts "** Identity needs to be a positive integer"
|
128
|
+
exit(1)
|
129
|
+
end
|
130
|
+
token = if options[:secure_identity]
|
131
|
+
RightScale::SecureIdentity.derive(base_id, options[:token])
|
132
|
+
else
|
133
|
+
options[:token]
|
134
|
+
end
|
135
|
+
options[:identity] = AgentIdentity.new(options[:prefix] || 'rs', options[:agent_type], base_id, token).to_s
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# Determine agent type
|
140
|
+
#
|
141
|
+
# === Parameters
|
142
|
+
# type(String):: Agent type
|
143
|
+
# name(String):: Agent name
|
144
|
+
#
|
145
|
+
# === Return
|
146
|
+
# (String):: Agent type
|
147
|
+
def agent_type(type, name)
|
148
|
+
unless type
|
149
|
+
if name =~ /^(.*)_[0-9]+$/
|
150
|
+
type = Regexp.last_match(1)
|
151
|
+
else
|
152
|
+
type = name || "instance"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
type
|
156
|
+
end
|
157
|
+
|
158
|
+
end # CommonParser
|
159
|
+
|
160
|
+
end # RightScale
|