Class: Bannister::Recurse
- Inherits:
-
Object
- Object
- Bannister::Recurse
- Defined in:
- lib/bannister/recurse.rb
Overview
Use the Recurse class to launch other apps with a runner script.
Instance Method Summary collapse
-
#initialize(dir) ⇒ Recurse
constructor
A new instance of Recurse.
-
#start(foreground = false) ⇒ Object
Run the application’s runner.
-
#stop ⇒ Object
Run “runner stop” and exit.
Constructor Details
#initialize(dir) ⇒ Recurse
Returns a new instance of Recurse.
7 8 9 10 11 |
# File 'lib/bannister/recurse.rb', line 7 def initialize(dir) raise ArgumentError.new("dir cannot be nil!") if dir.nil? @dir=dir end |
Instance Method Details
#start(foreground = false) ⇒ Object
Run the application’s runner. If foreground is true, exec “runner run” in @dir. Otherwise set up traps for the right signals to a backgrounded “runner start” process.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bannister/recurse.rb', line 27 def start(foreground=false) Dir.chdir(@dir) do if foreground # We're replacing the current process with the child, so we want # std* to go to the console exec "./runner run" else trap("TERM"){stop()} trap("HUP"){stop()} # This ignores stdout and stderr. Since the child process expects to # running in the background anyway, we expect it to make its own # arrangements. # # Yes, this is lazy, but there's not a lot more we can do at this # point without a higher-level error-handling facility. system "./runner start &" sleep() end end end |
#stop ⇒ Object
Run “runner stop” and exit.
15 16 17 18 |
# File 'lib/bannister/recurse.rb', line 15 def stop system "./runner stop" exit(0) end |