Class: Pigeon::Launcher
- Inherits:
-
Object
- Object
- Pigeon::Launcher
- Defined in:
- lib/pigeon/launcher.rb
Class Method Summary collapse
-
.launch(engine = Pigeon::Engine, *arguments) ⇒ Object
Class Methods ========================================================.
Instance Method Summary collapse
- #handle_args(*args) ⇒ Object
-
#initialize(with_engine = Pigeon::Engine) {|_self| ... } ⇒ Launcher
constructor
Instance Methods =====================================================.
- #restart(pid, old_pid) ⇒ Object
- #run(pid) ⇒ Object
- #shutdown(pid) ⇒ Object
- #start(pid) ⇒ Object
- #status(pid) ⇒ Object
- #stop(pid) ⇒ Object
- #usage ⇒ Object
Constructor Details
Class Method Details
.launch(engine = Pigeon::Engine, *arguments) ⇒ Object
Class Methods ========================================================
6 7 8 9 10 |
# File 'lib/pigeon/launcher.rb', line 6 def self.launch(engine = Pigeon::Engine, *arguments) arguments = %w[ start ] if (arguments.empty?) new(engine).handle_args(*arguments) end |
Instance Method Details
#handle_args(*args) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pigeon/launcher.rb', line 20 def handle_args(*args) op = OptionParser.new command = op.parse(*args.flatten).first begin case (command) when 'start' @engine.start(&method(:start)) when 'stop' @engine.stop(&method(:stop)) when 'restart' @engine.restart(&method(:restart)) when 'status' @engine.status(&method(:status)) when 'run' @engine.logger = Pigeon::Logger.new(STDOUT) @engine.run(&method(:run)) else usage end rescue Interrupt shutdown(pid) exit(0) end end |
#restart(pid, old_pid) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/pigeon/launcher.rb', line 73 def restart(pid, old_pid) if (old_pid) puts "#{@engine.name} terminated. [%d]" % old_pid end puts "#{@engine.name} now running. [%d]" % pid end |
#run(pid) ⇒ Object
48 49 50 51 |
# File 'lib/pigeon/launcher.rb', line 48 def run(pid) puts "#{@engine.name} now running. [%d]" % pid puts "Use ^C to terminate." end |
#shutdown(pid) ⇒ Object
81 82 83 |
# File 'lib/pigeon/launcher.rb', line 81 def shutdown(pid) puts "Shutting down." end |
#start(pid) ⇒ Object
53 54 55 |
# File 'lib/pigeon/launcher.rb', line 53 def start(pid) puts "#{@engine.name} now running. [%d]" % pid end |
#status(pid) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/pigeon/launcher.rb', line 65 def status(pid) if (pid) puts "#{@engine.name} running. [%d]" % pid else puts "#{@engine.name} is not running." end end |
#stop(pid) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/pigeon/launcher.rb', line 57 def stop(pid) if (pid) puts "#{@engine.name} shut down. [%d]" % pid else puts "#{@engine.name} was not running." end end |
#usage ⇒ Object
85 86 87 |
# File 'lib/pigeon/launcher.rb', line 85 def usage puts "Usage: #{File.basename($0)} [start|stop|restart|status|run]" end |