Class: Cuniculus::CLI
- Inherits:
-
Object
- Object
- Cuniculus::CLI
- Includes:
- Singleton
- Defined in:
- lib/cuniculus/cli.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #handle_signal(sig) ⇒ Object
- #launch(pipe_reader) ⇒ Object
- #parse(args = ARGV) ⇒ Object
- #run ⇒ Object
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/cuniculus/cli.rb', line 15 def @options end |
Instance Method Details
#handle_signal(sig) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/cuniculus/cli.rb', line 64 def handle_signal(sig) case sig when "INT", "TERM" raise Interrupt end end |
#launch(pipe_reader) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cuniculus/cli.rb', line 43 def launch(pipe_reader) config = Cuniculus.config supervisor = Cuniculus::Supervisor.new(config) begin Cuniculus.logger.info("Starting process") supervisor.start while (readable_io = IO.select([pipe_reader])) signal = readable_io.first[0].gets.strip handle_signal(signal) end rescue Interrupt Cuniculus.logger.info("Interrupt received; shutting down") supervisor.stop Cuniculus.logger.info("Shutdown complete") end exit(0) end |
#parse(args = ARGV) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/cuniculus/cli.rb', line 17 def parse(args = ARGV) @options = (args) return unless [:require] raise ArgumentError, "Invalid '--require' argument: #{[:require]}. File does not exist" unless File.exist?([:require]) raise ArgumentError, "Invalid '--require' argument: #{[:require]}. Cannot be a directory" if File.directory?([:require]) require File.join(Dir.pwd, [:require]) end |
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cuniculus/cli.rb', line 27 def run pipe_reader, pipe_writer = IO.pipe sigs = %w[INT TERM] sigs.each do |sig| trap sig do pipe_writer.puts(sig) end rescue ArgumentError puts "Signal #{sig} not supported" end launch(pipe_reader) end |