Class: Procodile::CLI
- Inherits:
-
Object
- Object
- Procodile::CLI
- Defined in:
- lib/procodile/cli.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
- .command(name) ⇒ Object
- .commands ⇒ Object
- .desc(description) ⇒ Object
- .options(&block) ⇒ Object
- .start_supervisor(config, options = {}, &after_start) ⇒ Object
Instance Method Summary collapse
- #dispatch(command) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
33 34 35 |
# File 'lib/procodile/cli.rb', line 33 def initialize = {} end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
31 32 33 |
# File 'lib/procodile/cli.rb', line 31 def config @config end |
#options ⇒ Object
Returns the value of attribute options.
30 31 32 |
# File 'lib/procodile/cli.rb', line 30 def end |
Class Method Details
.command(name) ⇒ Object
24 25 26 27 28 |
# File 'lib/procodile/cli.rb', line 24 def self.command(name) commands[name] = {:name => name, :description => @description, :options => } @description = nil = nil end |
.commands ⇒ Object
12 13 14 |
# File 'lib/procodile/cli.rb', line 12 def self.commands @commands ||= {} end |
.desc(description) ⇒ Object
16 17 18 |
# File 'lib/procodile/cli.rb', line 16 def self.desc(description) @description = description end |
.options(&block) ⇒ Object
20 21 22 |
# File 'lib/procodile/cli.rb', line 20 def self.(&block) = block end |
.start_supervisor(config, options = {}, &after_start) ⇒ Object
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/procodile/cli.rb', line 470 def self.start_supervisor(config, = {}, &after_start) = {} [:respawn] = [:respawn] [:stop_when_none] = [:stop_when_none] [:proxy] = [:proxy] [:force_single_log] = [:foreground] [:port_allocations] = [:port_allocations] if [:clean] FileUtils.rm_rf(Dir[File.join(config.pid_root, '*')]) puts "Emptied PID directory" end if !Dir[File.join(config.pid_root, "*")].empty? raise Error, "The PID directory (#{config.pid_root}) is not empty. Cannot start unless things are clean." end $0="[procodile] #{config.app_name} (#{config.root})" if [:foreground] File.open(config.supervisor_pid_path, 'w') { |f| f.write(::Process.pid) } Supervisor.new(config, ).start(&after_start) else FileUtils.rm_f(File.join(config.pid_root, "*.pid")) pid = fork do STDOUT.reopen(config.log_path, 'a') STDOUT.sync = true STDERR.reopen(config.log_path, 'a') STDERR.sync = true Supervisor.new(config, ).start(&after_start) end ::Process.detach(pid) File.open(config.supervisor_pid_path, 'w') { |f| f.write(pid) } puts "Started Procodile supervisor with PID #{pid}" end end |
Instance Method Details
#dispatch(command) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/procodile/cli.rb', line 37 def dispatch(command) if self.class.commands.keys.include?(command.to_sym) public_send(command) else raise Error, "Invalid command '#{command}'" end end |