class SnowmanIO::CLI
The command line interface for SnowmanIO
.
Attributes
options[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/snowman-io/cli.rb, line 13 def initialize(options = {}) @options = options end
run()
click to toggle source
# File lib/snowman-io/cli.rb, line 8 def self.run options = Options.new.parse!(ARGV) new(options).run end
Public Instance Methods
run()
click to toggle source
# File lib/snowman-io/cli.rb, line 17 def run setup_logger # Self-pipe for deferred signal-handling (http://cr.yp.to/docs/selfpipe.html) 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 launcher = Launcher.new(options) begin launcher.start while readable_io = IO.select([self_read]) signal = readable_io.first[0].gets.strip handle_signal(signal) end rescue Interrupt SnowmanIO.logger.info 'Shutting down' launcher.stop exit(0) end end
Private Instance Methods
handle_signal(sig)
click to toggle source
# File lib/snowman-io/cli.rb, line 50 def handle_signal(sig) SnowmanIO.logger.debug "Received #{sig} signal" case sig when 'TERM' raise Interrupt when 'INT' raise Interrupt end end
setup_logger()
click to toggle source
# File lib/snowman-io/cli.rb, line 60 def setup_logger Celluloid.logger = (options[:verbose] ? SnowmanIO.logger : nil) if options[:verbose] SnowmanIO.logger.level = ::Logger::DEBUG else SnowmanIO.logger.level = ::Logger::INFO end end