Class: Roundhouse::CLI
- Inherits:
-
Object
- Object
- Roundhouse::CLI
- Includes:
- Util, Singleton
- Defined in:
- lib/roundhouse/cli.rb
Constant Summary
Constants included from Util
Instance Attribute Summary collapse
-
#code ⇒ Object
Used for CLI testing.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#launcher ⇒ Object
Returns the value of attribute launcher.
Class Method Summary collapse
Instance Method Summary collapse
- #handle_signal(sig) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #parse(args = ARGV) ⇒ Object
-
#run ⇒ Object
Code within this method is not tested because it alters global process state irreversibly.
Methods included from Util
#fire_event, #hostname, #identity, #logger, #process_nonce, #redis, #want_a_hertz_donut?, #watchdog
Methods included from ExceptionHandler
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
31 32 33 |
# File 'lib/roundhouse/cli.rb', line 31 def initialize @code = nil end |
Instance Attribute Details
#code ⇒ Object
Used for CLI testing
27 28 29 |
# File 'lib/roundhouse/cli.rb', line 27 def code @code end |
#environment ⇒ Object
Returns the value of attribute environment.
29 30 31 |
# File 'lib/roundhouse/cli.rb', line 29 def environment @environment end |
#launcher ⇒ Object
Returns the value of attribute launcher.
28 29 30 |
# File 'lib/roundhouse/cli.rb', line 28 def launcher @launcher end |
Class Method Details
.banner ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/roundhouse/cli.rb', line 103 def self. %q{ ______ _ _ | ___ \ | | | | |_/ /___ _ _ _ __ __| | |__ ___ _ _ ___ ___ | // _ \| | | | '_ \ / _` | '_ \ / _ \| | | / __|/ _ \ | |\ \ (_) | |_| | | | | (_| | | | | (_) | |_| \__ \ __/ \_| \_\___/ \__,_|_| |_|\__,_|_| |_|\___/ \__,_|___/\___| } end |
Instance Method Details
#handle_signal(sig) ⇒ Object
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 |
# File 'lib/roundhouse/cli.rb', line 116 def handle_signal(sig) Roundhouse.logger.debug "Got #{sig} signal" case sig when 'INT' # Handle Ctrl-C in JRuby like MRI # http://jira.codehaus.org/browse/JRUBY-4637 raise Interrupt when 'TERM' # Heroku sends TERM and then waits 10 seconds for process to exit. raise Interrupt when 'USR1' Roundhouse.logger.info "Received USR1, no longer accepting new work" launcher.manager.async.stop fire_event(:quiet, true) when 'USR2' if Roundhouse.[:logfile] Roundhouse.logger.info "Received USR2, reopening log file" Roundhouse::Logging.reopen_logs end when 'TTIN' Thread.list.each do |thread| Roundhouse.logger.warn "Thread TID-#{thread.object_id.to_s(36)} #{thread['label']}" if thread.backtrace Roundhouse.logger.warn thread.backtrace.join("\n") else Roundhouse.logger.warn "<no backtrace available>" end end end end |
#parse(args = ARGV) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/roundhouse/cli.rb', line 35 def parse(args=ARGV) @code = nil (args) initialize_logger validate! daemonize write_pid load_celluloid end |
#run ⇒ Object
Code within this method is not tested because it alters global process state irreversibly. PRs which improve the test coverage of Roundhouse::CLI are welcomed.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/roundhouse/cli.rb', line 49 def run boot_system self_read, self_write = IO.pipe %w(INT TERM USR1 USR2 TTIN).each do |sig| begin trap sig do self_write.puts(sig) end rescue ArgumentError puts "Signal #{sig} not supported" end end logger.info "Running in #{RUBY_DESCRIPTION}" logger.info Roundhouse::LICENSE fire_event(:startup) logger.debug { "Middleware: #{Roundhouse.server_middleware.map(&:klass).join(', ')}" } Roundhouse.redis do |conn| # touch the connection pool so it is created before we # launch the actors. end if ![:daemon] logger.info 'Starting processing, hit Ctrl-C to stop' end require 'roundhouse/launcher' @launcher = Roundhouse::Launcher.new() begin launcher.run while readable_io = IO.select([self_read]) signal = readable_io.first[0].gets.strip handle_signal(signal) end rescue Interrupt logger.info 'Shutting down' launcher.stop fire_event(:shutdown, true) # Explicitly exit so busy Processor threads can't block # process shutdown. exit(0) end end |