Class: Emmy::Runner
Constant Summary collapse
- RUBY =
Gem.ruby
- BIN_EMMY =
"bin/emmy"
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#argv ⇒ Object
Returns the value of attribute argv.
-
#config ⇒ Object
Returns the value of attribute config.
-
#env ⇒ Object
Returns the value of attribute env.
-
#option_parser ⇒ Object
Returns the value of attribute option_parser.
Instance Method Summary collapse
- #bootstrap! ⇒ Object
- #configure(&b) ⇒ Object
- #daemonize_server ⇒ Object
- #defaults! ⇒ Object
- #display_help ⇒ Object
- #display_version ⇒ Object
- #each(&b) ⇒ Object
- #error(message) ⇒ Object
- #execute_bin_emmy ⇒ Object
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #instance! ⇒ Object
- #instance_defaults!(id) ⇒ Object
- #parse_environment! ⇒ Object
- #run_action ⇒ Object
- #show_configuration ⇒ Object
- #start_console ⇒ Object
- #start_server ⇒ Object
- #stop_server ⇒ Object
- #update_rack_environment! ⇒ Object
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/emmy/runner.rb', line 18 def initialize @argv = ARGV @env = ENV @config = EmmyHttp::Configuration.new @action = :start_server on :bootstrap do parse_environment! end on :bootstrap do defaults! end on :instance do |id| instance_defaults!(id) end on :parse_options do option_parser.parse!(argv) end on :parse_options do update_rack_environment! end end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
15 16 17 |
# File 'lib/emmy/runner.rb', line 15 def action @action end |
#argv ⇒ Object
Returns the value of attribute argv.
12 13 14 |
# File 'lib/emmy/runner.rb', line 12 def argv @argv end |
#config ⇒ Object
Returns the value of attribute config.
14 15 16 |
# File 'lib/emmy/runner.rb', line 14 def config @config end |
#env ⇒ Object
Returns the value of attribute env.
13 14 15 |
# File 'lib/emmy/runner.rb', line 13 def env @env end |
#option_parser ⇒ Object
Returns the value of attribute option_parser.
16 17 18 |
# File 'lib/emmy/runner.rb', line 16 def option_parser @option_parser end |
Instance Method Details
#bootstrap! ⇒ Object
204 205 206 |
# File 'lib/emmy/runner.rb', line 204 def bootstrap! bootstrap.instance_fire(self) end |
#configure(&b) ⇒ Object
196 197 198 |
# File 'lib/emmy/runner.rb', line 196 def configure(&b) on :bootstrap, &b end |
#daemonize_server ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/emmy/runner.rb', line 122 def daemonize_server each_server do Process.fork do Process.setsid exit if fork Fibre.reset # Boot instance instance! scope_pid(Process.pid) do |pid| puts pid File.umask(0000) bind_standard_streams start_server end end end sleep(1) end |
#defaults! ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/emmy/runner.rb', line 93 def defaults! if config.environment == "development" config.stdout = "#{config.backend}.stdout" config.stderr = config.stdout end config.pid = "#{config.backend}.pid" config.log = "#{config.backend}.log" config.adapter ||= EmmyExtends::Thin::Controller rescue nil end |
#display_help ⇒ Object
183 184 185 |
# File 'lib/emmy/runner.rb', line 183 def display_help puts option_parser end |
#display_version ⇒ Object
187 188 189 |
# File 'lib/emmy/runner.rb', line 187 def display_version puts Emmy::VERSION end |
#each(&b) ⇒ Object
200 201 202 |
# File 'lib/emmy/runner.rb', line 200 def each(&b) on :instance, &b end |
#error(message) ⇒ Object
191 192 193 194 |
# File 'lib/emmy/runner.rb', line 191 def error() puts exit end |
#execute_bin_emmy ⇒ Object
43 44 45 46 47 |
# File 'lib/emmy/runner.rb', line 43 def execute_bin_emmy return false unless File.file?(BIN_EMMY) exec RUBY, BIN_EMMY, *argv true end |
#instance! ⇒ Object
208 209 210 |
# File 'lib/emmy/runner.rb', line 208 def instance! instance.instance_fire(self, config.id) end |
#instance_defaults!(id) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/emmy/runner.rb', line 105 def instance_defaults!(id) if config.id config.url.port += id if config.servers config.pid = "#{config.backend}#{id}.pid" config.log = "#{config.backend}#{id}.log" end end |
#parse_environment! ⇒ Object
49 50 51 |
# File 'lib/emmy/runner.rb', line 49 def parse_environment! config.environment = env['EMMY_ENV'] || env['RACK_ENV'] || 'development' end |
#run_action ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/emmy/runner.rb', line 113 def run_action # Bootstrap bootstrap! if @action != :display_help # start action send(action) self end |
#show_configuration ⇒ Object
175 176 177 178 179 180 181 |
# File 'lib/emmy/runner.rb', line 175 def show_configuration puts "Server configuration:" config.attributes.each do |name, value| value = "off" if value.nil? puts " #{name}: #{value}" end end |
#start_console ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/emmy/runner.rb', line 162 def start_console EmmyMachine.run_once do if defined?(binding.pry) TOPLEVEL_BINDING.pry else require 'irb' require 'irb/completion' IRB.start end end end |
#start_server ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/emmy/runner.rb', line 143 def start_server Emmy.run do trap("INT") { Emmy.stop } trap("TERM") { Emmy.stop } Emmy.fiber_block do file = backend_file Backend.module_eval(File.read(file), file) end end end |
#stop_server ⇒ Object
155 156 157 158 159 160 |
# File 'lib/emmy/runner.rb', line 155 def stop_server each_server do instance! stop_pid(config.pid) end end |
#update_rack_environment! ⇒ Object
53 54 55 |
# File 'lib/emmy/runner.rb', line 53 def update_rack_environment! ENV['RACK_ENV'] = config.environment end |