ry / ebb fork watch download tarball
public this repo is viewable by everyone
Description: web server
Homepage: http://ebb.rubyforge.org
Clone URL: git://github.com/ry/ebb.git
Clean up ebb_rails and Runner
Ryan Dahl (author)
about 1 month ago
commit  7dcfc536c96e944907396069075db87ee422b206
tree    eb97b2560590a6cf80ca0143074eb32ac2efb548
parent  eb55b568610bf4d33ebc59ef7ff79838544617aa
...
10
11
12
13
14
 
 
15
16
 
17
18
19
 
20
21
22
23
24
 
25
26
 
 
 
 
27
28
29
30
31
32
33
34
 
 
 
...
10
11
12
 
 
13
14
15
 
16
17
18
 
19
20
21
22
23
 
24
25
 
26
27
28
29
30
31
32
33
34
35
 
36
37
38
39
0
@@ -10,24 +10,29 @@ module Rack
0
   end
0
 end
0
 
0
-Ebb::Runner.new('ebb_rails') do
0
- def add_extra_options(parser, options)
0
+class EbbRails < Ebb::Runner
0
+ def extra_options
0
     # defaults for ebb_rails
0
- options.update(
0
+ @options.update(
0
       :environment => 'development',
0
       :port => 3000,
0
- # rails has a massive mutex lock around each request - threaded processing
0
+ # rails has a mutex lock around each request - threaded processing
0
       # will only slow things down
0
       :threaded_processing => false
0
     )
0
     
0
- parser.on("-e", "--env ENV",
0
+ @parser.on("-e", "--env ENV",
0
             "Rails environment (default: development)") do |env|
0
- options[:environment] = env
0
+ @options[:environment] = env
0
+ end
0
+ @parser.on("-c", "--chdir DIR", "RAILS_ROOT directory") do |c|
0
+ @options[:root] = c
0
     end
0
   end
0
   
0
   def app(options)
0
     Rack::Adapter::Rails.new(options)
0
   end
0
-end
0
\ No newline at end of file
0
+end
0
+
0
+EbbRails.new(ARGV).run
...
70
71
72
73
 
74
75
76
...
70
71
72
 
73
74
75
76
0
@@ -70,7 +70,7 @@ module Ebb
0
       client.begin_transmission()
0
     else
0
       client.begin_transmission()
0
- client.body.each { |p| write(p) }
0
+ body.each { |p| client.write(p) }
0
       client.body_written()
0
     end
0
   rescue => e
...
20
21
22
23
24
25
26
27
28
29
30
31
32
...
55
56
57
58
59
60
61
 
 
 
 
 
 
 
 
62
63
 
64
65
 
 
 
 
 
 
 
 
 
 
 
66
 
 
 
 
 
 
 
 
 
67
68
 
 
 
69
70
71
72
 
73
74
75
 
76
77
78
79
80
81
82
83
 
 
84
85
86
87
 
 
88
89
90
 
91
92
93
94
 
95
96
 
97
98
99
 
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
 
138
139
140
 
141
142
143
144
...
20
21
22
 
 
 
 
 
 
 
23
24
25
...
48
49
50
 
 
 
 
51
52
53
54
55
56
57
58
59
60
61
62
 
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 
85
86
87
88
89
90
 
91
92
93
 
94
95
96
97
98
99
100
 
 
101
102
103
104
 
 
105
106
107
108
 
109
110
111
112
 
113
114
 
115
116
117
 
118
119
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
122
 
 
123
124
125
 
126
0
@@ -20,13 +20,6 @@ end
0
 
0
 module Ebb
0
   class Runner
0
- DEFAULT_OPTIONS = {
0
- :port => 4001,
0
- :timeout => 60,
0
- :workers => 1,
0
- :threaded_processing => true
0
- }
0
-
0
     # Kill the process which PID is stored in +pid_file+.
0
     def self.kill(pid_file, timeout=60)
0
       raise ArgumentError, 'You must specify a pid_file to stop deamonized server' unless pid_file
0
@@ -55,90 +48,79 @@ module Ebb
0
       File.chmod(0644, file)
0
     end
0
     
0
- def initialize(name, &definitions)
0
- @name = name
0
- instance_eval(&definitions)
0
- run
0
+ def initialize(argv)
0
+ @argv = argv
0
+ @parser = OptionParser.new
0
+ @options = {
0
+ :port => 4001,
0
+ :timeout => 60,
0
+ :threaded_processing => true
0
+ }
0
     end
0
     
0
+
0
     def run
0
- option_parser, options = get_options_from_command_line
0
+ @parser.banner = "Usage: #{self.class} [options] start | stop"
0
+ @parser.separator ""
0
+ extra_options if respond_to?(:extra_options)
0
+
0
+ @parser.separator ""
0
+ # opts.on("-s", "--socket SOCKET", "listen on socket") { |socket| options[:socket] = socket }
0
+ @parser.on("-p", "--port PORT", "(default: #{@options[:port]})") { |p| @options[:port]=p }
0
+ @parser.on("-d", "--daemonize", "Daemonize") { @options[:daemonize] = true }
0
+ @parser.on("-l", "--log-file FILE", "File to redirect output") { |f| @options[:log_file]=f }
0
+ @parser.on("-P", "--pid-file FILE", "File to store PID") { |f| @options[:pid_file]=f }
0
+ # @parser.on("-t", "--timeout SECONDS", "(default: #{@options[:timeout]})") { |s| @options[:timeout]=s }
0
       
0
+ @parser.separator ""
0
+ @parser.on_tail("-h", "--help", "Show this message") do
0
+ puts @parser
0
+ exit
0
+ end
0
+ @parser.on_tail('-v', '--version', "Show version") do
0
+ puts "Ebb #{Ebb::VERSION}"
0
+ exit
0
+ end
0
       
0
- case ARGV[0]
0
+ @parser.parse!(@argv)
0
+
0
+ case @argv[0]
0
       when 'start'
0
         STDOUT.print("Ebb is loading the application...")
0
         STDOUT.flush()
0
- @app = app(options)
0
+ @app = app(@options)
0
         STDOUT.puts("loaded")
0
         
0
- if options[:daemonize]
0
+ if @options[:daemonize]
0
           pwd = Dir.pwd # Current directory is changed during daemonization, so store it
0
           Kernel.daemonize
0
           Dir.chdir pwd
0
           trap('HUP', 'IGNORE') # Don't die upon logout
0
         end
0
         
0
- if options[:log_file]
0
- [STDOUT, STDERR].each { |f| f.reopen log_file, 'a' }
0
+ if @options[:log_file]
0
+ [STDOUT, STDERR].each { |f| f.reopen @options[:log_file], 'a' }
0
         end
0
         
0
- if options[:pid_file]
0
- Runner.write_pid_file(options[:pid_file])
0
+ if @options[:pid_file]
0
+ Runner.write_pid_file(@options[:pid_file])
0
           at_exit do
0
             puts ">> Exiting!"
0
- Runner.remove_pid_file(options[:pid_file])
0
+ Runner.remove_pid_file(@options[:pid_file])
0
           end
0
         end
0
         
0
- Ebb::start_server(@app, options)
0
+ Ebb::start_server(@app, @options)
0
       when 'stop'
0
- Ebb::Runner.kill options[:pid_file], options[:timeout]
0
+ Ebb::Runner.kill @options[:pid_file], @options[:timeout]
0
       when nil
0
         puts "Command required"
0
- puts option_parser
0
+ puts @parser
0
         exit 1
0
       else
0
- abort "Invalid command : #{ARGV[0]}"
0
- end
0
- end
0
-
0
-
0
- def get_options_from_command_line
0
- options = DEFAULT_OPTIONS.dup
0
- option_parser = OptionParser.new do |parser|
0
- parser.banner = "Usage: #{@name} [options] start | stop"
0
- parser.separator ""
0
- if respond_to?(:add_extra_options)
0
- add_extra_options(parser, options)
0
- end
0
- parser.separator ""
0
- # opts.on("-s", "--socket SOCKET", "listen on socket") { |socket| options[:socket] = socket }
0
- parser.on("-p", "--port PORT", "(default: #{options[:port]})") { |p| options[:port]=p }
0
- parser.on("-d", "--daemonize", "Daemonize") { options[:daemonize] = true }
0
- parser.on("-l", "--log-file FILE", "File to redirect output") { |f| options[:log_file]=f }
0
- parser.on("-P", "--pid-file FILE", "File to store PID") { |f| options[:pid_file]=f }
0
- parser.on("-t", "--timeout SECONDS", "(default: #{options[:timeout]})") { |s| options[:timeout]=s }
0
- #parser.on("-w", "--workers WORKERS", "Number of worker threads (default: #{options[:workers]})") { |w| options[:workers]=w }
0
- parser.on("-w", "-- WORKERS", "Number of worker threads (default: #{options[:workers]})") { |w| options[:workers]=w }
0
-
0
- parser.on("-S", "--sequential", "do not use threaded processing") do
0
- options[:threaded_processing] = false
0
- end
0
-
0
- parser.separator ""
0
- parser.on_tail("-h", "--help", "Show this message") do
0
- puts parser
0
- exit
0
- end
0
- parser.on_tail('-v', '--version', "Show version") do
0
- puts "Ebb #{Ebb::VERSION}"
0
- exit
0
- end
0
+ abort "Invalid command : #{argv[0]}"
0
       end
0
- option_parser.parse!(ARGV)
0
- [option_parser, options]
0
+
0
     end
0
   end
0
-
0
 end

Comments

    No one has commented yet.