Class: RightScale::AgentController
- Includes:
- CommonParser
- Defined in:
- lib/right_agent/scripts/agent_controller.rb
Constant Summary collapse
- FORCED_OPTIONS =
{ :threadpool_size => 1 }
- DEFAULT_OPTIONS =
{ :single_threaded => true, :log_dir => Platform.filesystem.log_dir, :daemonize => true }
- @@agent =
nil
Class Method Summary collapse
-
.run ⇒ Object
Create and run controller.
Instance Method Summary collapse
-
#control(options) ⇒ Object
Parse arguments and execute request.
-
#parse_args ⇒ Object
Create options hash from command line arguments.
Methods included from CommonParser
#agent_type, #parse_common, #resolve_identity
Class Method Details
.run ⇒ Object
Create and run controller
Return
- true
-
Always return true
104 105 106 107 |
# File 'lib/right_agent/scripts/agent_controller.rb', line 104 def self.run c = AgentController.new c.control(c.parse_args) end |
Instance Method Details
#control(options) ⇒ Object
Parse arguments and execute request
Parameters
- options(Hash)
-
Command line options
Return
- true
-
Always return true
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 |
# File 'lib/right_agent/scripts/agent_controller.rb', line 116 def control() # Initialize directory settings AgentConfig.cfg_dir = [:cfg_dir] AgentConfig.pid_dir = [:pid_dir] # List agents if requested list_configured_agents if [:list] # Validate arguments action = .delete(:action) fail("No action specified on the command line.", print_usage = true) unless action if action == 'kill' && ([:pid_file].nil? || !File.file?([:pid_file])) fail("Missing or invalid pid file #{[:pid_file]}", print_usage = true) end if [:agent_name] if action == 'start' cfg = configure_agent(action, ) else cfg = AgentConfig.load_cfg([:agent_name]) fail("Deployment is missing configuration file #{AgentConfig.cfg_file([:agent_name]).inspect}.") unless cfg end .delete(:identity) = cfg.merge() AgentConfig.root_dir = [:root_dir] AgentConfig.pid_dir = [:pid_dir] Log.program_name = syslog_program_name() Log.log_to_file_only([:log_to_file_only]) configure_proxy([:http_proxy], [:http_no_proxy]) if [:http_proxy] elsif [:identity] [:agent_name] = AgentConfig.agent_name([:identity]) end @options = DEFAULT_OPTIONS.clone.merge(.merge(FORCED_OPTIONS)) FileUtils.mkdir_p(@options[:pid_dir]) unless @options[:pid_dir].nil? || File.directory?(@options[:pid_dir]) # Execute request success = case action when /show|killall/ action = 'stop' if action == 'killall' s = true AgentConfig.cfg_agents.each { |agent_name| s &&= dispatch(action, agent_name) } s when 'kill' kill_process else dispatch(action, @options[:agent_name]) end exit(1) unless success end |
#parse_args ⇒ Object
Create options hash from command line arguments
Return
- options(Hash)
-
Parsed options
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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/right_agent/scripts/agent_controller.rb', line 171 def parse_args = {:thin_command_client => false} opts = OptionParser.new do |opts| parse_common(opts, ) parse_other_args(opts, ) opts.on("-s", "--start AGENT") do |a| [:action] = 'start' [:agent_name] = a end opts.on("-p", "--stop AGENT") do |a| [:action] = 'stop' [:agent_name] = a end opts.on("--stop-agent ID") do |id| [:action] = 'stop' [:identity] = id end opts.on("-k", "--kill PIDFILE") do |file| [:pid_file] = file [:action] = 'kill' end opts.on("-K", "--killall") do [:action] = 'killall' end opts.on("-U", "--status") do [:action] = 'show' end opts.on("-l", "--list") do [:list] = true end opts.on("--log-level LVL") do |lvl| [:log_level] = lvl end opts.on("-c", "--cfg-dir DIR") do |d| [:cfg_dir] = d end opts.on("-z", "--pid-dir DIR") do |dir| [:pid_dir] = dir end opts.on("--log-dir DIR") do |dir| [:log_dir] = dir # Ensure log directory exists (for windows, etc.) FileUtils.mkdir_p(dir) unless File.directory?(dir) end opts.on("-f", "--foreground") do [:daemonize] = false #Squelch Ruby VM warnings about various things $VERBOSE = nil end opts.on("-I", "--interactive") do [:console] = 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., print_usage = true) end # allow specific arguments to use a thin command client for faster # execution (on Windows, etc.) unless [:thin_command_client] # require full right_agent for any commands which do not specify thin # command client. require File.normalize_path(File.join(File.dirname(__FILE__), '..', '..', 'right_agent')) end resolve_identity() end |