hayabusa 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +5 -3
- data/VERSION +1 -1
- data/bin/hayabusa_fcgi.fcgi +2 -129
- data/bin/hayabusa_fcgi.rb +2 -129
- data/hayabusa.gemspec +6 -2
- data/lib/hayabusa.rb +58 -34
- data/lib/hayabusa_cgi_session.rb +25 -2
- data/lib/hayabusa_cgi_tools.rb +45 -34
- data/lib/hayabusa_ext/threadding.rb +2 -2
- data/lib/hayabusa_ext/translations.rb +5 -3
- data/lib/hayabusa_fcgi.rb +172 -0
- data/lib/hayabusa_http_server.rb +5 -5
- data/lib/hayabusa_http_session.rb +19 -18
- data/lib/hayabusa_http_session_request.rb +15 -3
- data/lib/hayabusa_http_session_response.rb +4 -1
- data/lib/kernel_ext/gettext_methods.rb +1 -1
- data/lib/kernel_ext/magic_methods.rb +0 -1
- metadata +25 -13
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -11,8 +11,8 @@ GEM
|
|
11
11
|
bundler (~> 1.0)
|
12
12
|
git (>= 1.2.5)
|
13
13
|
rake
|
14
|
-
json (1.7.
|
15
|
-
knjrbfw (0.0.
|
14
|
+
json (1.7.5)
|
15
|
+
knjrbfw (0.0.87)
|
16
16
|
datet
|
17
17
|
http2
|
18
18
|
php4r
|
@@ -23,7 +23,7 @@ GEM
|
|
23
23
|
mime-types (~> 1.16)
|
24
24
|
treetop (~> 1.4.8)
|
25
25
|
mime-types (1.19)
|
26
|
-
php4r (0.0.
|
26
|
+
php4r (0.0.3)
|
27
27
|
datet
|
28
28
|
http2
|
29
29
|
polyglot (0.3.3)
|
@@ -37,6 +37,7 @@ GEM
|
|
37
37
|
diff-lcs (~> 1.1.2)
|
38
38
|
rspec-mocks (2.3.0)
|
39
39
|
sqlite3 (1.3.6)
|
40
|
+
tpool (0.0.1)
|
40
41
|
treetop (1.4.10)
|
41
42
|
polyglot
|
42
43
|
polyglot (>= 0.3.1)
|
@@ -57,3 +58,4 @@ DEPENDENCIES
|
|
57
58
|
mail
|
58
59
|
rspec (~> 2.3.0)
|
59
60
|
sqlite3
|
61
|
+
tpool
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/bin/hayabusa_fcgi.fcgi
CHANGED
@@ -22,135 +22,8 @@ begin
|
|
22
22
|
require "fileutils"
|
23
23
|
require "#{File.dirname(Knj::Os.realpath(__FILE__))}/../lib/hayabusa.rb"
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
#We cant define the Hayabusa-server untuil we receive the first headers, so wait for the first request.
|
29
|
-
hayabusa = nil
|
30
|
-
hayabusa_fcgi_conf_path = nil
|
31
|
-
fcgi_proxy = nil
|
32
|
-
|
33
|
-
$stderr.puts "[hayabusa] Starting FCGI." if debug
|
34
|
-
FCGI.each_cgi do |cgi|
|
35
|
-
begin
|
36
|
-
#cgi.print "Content-Type: text/html\r\n"
|
37
|
-
#cgi.print "\r\n"
|
38
|
-
|
39
|
-
#Set 'cgi'-variable for CGI-tools.
|
40
|
-
cgi_tools.cgi = cgi
|
41
|
-
|
42
|
-
#Ensure the same FCGI-process isnt active for more than one website.
|
43
|
-
raise "Expected 'HTTP_HAYABUSA_FCGI_CONFIG' to be '#{hayabusa_fcgi_conf_path}' but it wasnt: '#{cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]}'." if hayabusa_fcgi_conf_path and hayabusa_fcgi_conf_path != cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]
|
44
|
-
|
45
|
-
if !hayabusa
|
46
|
-
raise "No HTTP_HAYABUSA_FCGI_CONFIG-header was given." if !cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]
|
47
|
-
hayabusa_fcgi_conf_path = cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]
|
48
|
-
require hayabusa_fcgi_conf_path
|
49
|
-
raise "No 'Hayabusa::FCGI_CONF'-constant was spawned by '#{cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]}'." if !Hayabusa.const_defined?(:FCGI_CONF)
|
50
|
-
conf = Hayabusa::FCGI_CONF
|
51
|
-
|
52
|
-
hayabusa_conf = Hayabusa::FCGI_CONF[:hayabusa]
|
53
|
-
hayabusa_conf.merge!(
|
54
|
-
:cmdline => false,
|
55
|
-
:port => 0 #Ruby picks random port and we get the actual port after starting the appserver.
|
56
|
-
)
|
57
|
-
|
58
|
-
#Figure out if this should be a host-FCGI-process or a proxy-FCGI-process.
|
59
|
-
fcgi_config_fp = "#{Knj::Os.tmpdir}/hayabusa_fcgi_#{hayabusa_conf[:title]}_fcgi.conf"
|
60
|
-
FileUtils.touch(fcgi_config_fp) if !File.exists?(fcgi_config_fp)
|
61
|
-
|
62
|
-
begin
|
63
|
-
File.open(fcgi_config_fp) do |fp|
|
64
|
-
fp.flock(File::LOCK_EX)
|
65
|
-
|
66
|
-
fcgi_config_cont = File.read(fcgi_config_fp)
|
67
|
-
|
68
|
-
if !fcgi_config_cont.empty?
|
69
|
-
fcgi_config = Marshal.load(File.read(fcgi_config_fp))
|
70
|
-
pid = fcgi_config[:pid]
|
71
|
-
|
72
|
-
if Knj::Unix_proc.pid_running?(pid)
|
73
|
-
fcgi_proxy = fcgi_config
|
74
|
-
|
75
|
-
require "http2"
|
76
|
-
http = Http2.new(:host => "localhost", :port => fcgi_proxy[:port].to_i)
|
77
|
-
fcgi_proxy[:http] = http
|
78
|
-
end
|
79
|
-
else
|
80
|
-
fcgi_config = nil
|
81
|
-
end
|
82
|
-
|
83
|
-
if !fcgi_proxy
|
84
|
-
File.open(fcgi_config_fp, "w") do |fp|
|
85
|
-
hayabusa = Hayabusa.new(hayabusa_conf)
|
86
|
-
|
87
|
-
#Start web-server for proxy-requests.
|
88
|
-
hayabusa.start
|
89
|
-
|
90
|
-
fp.write(Marshal.dump(
|
91
|
-
:pid => Process.pid,
|
92
|
-
:port => hayabusa.port
|
93
|
-
))
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
ensure
|
98
|
-
File.open(fcgi_config_fp).flock(File::LOCK_UN)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
if fcgi_proxy
|
105
|
-
#Proxy request to the host-FCGI-process.
|
106
|
-
$stderr.puts "[hayabusa] Proxying request." if debug
|
107
|
-
cgi_tools.proxy_request_to(:cgi => cgi, :http => fcgi_proxy[:http])
|
108
|
-
else
|
109
|
-
#Host the FCGI-process.
|
110
|
-
$stderr.puts "[hayabusa] Running request as CGI." if debug
|
111
|
-
|
112
|
-
#Enforce $stdout variable.
|
113
|
-
$stdout = hayabusa.cio
|
114
|
-
|
115
|
-
#The rest is copied from the FCGI-part.
|
116
|
-
headers = {}
|
117
|
-
cgi.env_table.each do |key, val|
|
118
|
-
if key[0, 5] == "HTTP_" and key != "HTTP_HAYABUSA_FCGI_CONFIG"
|
119
|
-
key = key[5, key.length].gsub("_", " ").gsub(" ", "-")
|
120
|
-
headers[key] = val
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
meta = cgi.env_table.to_hash
|
125
|
-
|
126
|
-
uri = Knj::Web.parse_uri(meta["REQUEST_URI"])
|
127
|
-
meta["PATH_TRANSLATED"] = File.basename(uri[:path])
|
128
|
-
|
129
|
-
cgi_data = {
|
130
|
-
:cgi => cgi,
|
131
|
-
:headers => headers,
|
132
|
-
:get => Knj::Web.parse_urlquery(cgi.env_table["QUERY_STRING"], :urldecode => true, :force_utf8 => true),
|
133
|
-
:meta => meta
|
134
|
-
}
|
135
|
-
if cgi.request_method == "POST"
|
136
|
-
cgi_data[:post] = cgi_tools.convert_fcgi_post(cgi.params)
|
137
|
-
else
|
138
|
-
cgi_data[:post] = {}
|
139
|
-
end
|
140
|
-
|
141
|
-
hayabusa.config[:cgi] = cgi_data
|
142
|
-
|
143
|
-
|
144
|
-
#Handle request.
|
145
|
-
hayabusa.start_cgi_request
|
146
|
-
end
|
147
|
-
rescue Exception => e
|
148
|
-
cgi.print "Content-Type: text/html\r\n"
|
149
|
-
cgi.print "\r\n"
|
150
|
-
cgi.print Knj::Errors.error_str(e, :html => true)
|
151
|
-
cgi.print Knj.p(cgi_data, true) if cgi_data
|
152
|
-
end
|
153
|
-
end
|
25
|
+
fcgi = Hayabusa::Fcgi.new
|
26
|
+
fcgi.fcgi_loop
|
154
27
|
rescue Exception => e
|
155
28
|
if !e.is_a?(Interrupt)
|
156
29
|
File.open(error_log_file, "w") do |fp|
|
data/bin/hayabusa_fcgi.rb
CHANGED
@@ -22,135 +22,8 @@ begin
|
|
22
22
|
require "fileutils"
|
23
23
|
require "#{File.dirname(Knj::Os.realpath(__FILE__))}/../lib/hayabusa.rb"
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
#We cant define the Hayabusa-server untuil we receive the first headers, so wait for the first request.
|
29
|
-
hayabusa = nil
|
30
|
-
hayabusa_fcgi_conf_path = nil
|
31
|
-
fcgi_proxy = nil
|
32
|
-
|
33
|
-
$stderr.puts "[hayabusa] Starting FCGI." if debug
|
34
|
-
FCGI.each_cgi do |cgi|
|
35
|
-
begin
|
36
|
-
#cgi.print "Content-Type: text/html\r\n"
|
37
|
-
#cgi.print "\r\n"
|
38
|
-
|
39
|
-
#Set 'cgi'-variable for CGI-tools.
|
40
|
-
cgi_tools.cgi = cgi
|
41
|
-
|
42
|
-
#Ensure the same FCGI-process isnt active for more than one website.
|
43
|
-
raise "Expected 'HTTP_HAYABUSA_FCGI_CONFIG' to be '#{hayabusa_fcgi_conf_path}' but it wasnt: '#{cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]}'." if hayabusa_fcgi_conf_path and hayabusa_fcgi_conf_path != cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]
|
44
|
-
|
45
|
-
if !hayabusa
|
46
|
-
raise "No HTTP_HAYABUSA_FCGI_CONFIG-header was given." if !cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]
|
47
|
-
hayabusa_fcgi_conf_path = cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]
|
48
|
-
require hayabusa_fcgi_conf_path
|
49
|
-
raise "No 'Hayabusa::FCGI_CONF'-constant was spawned by '#{cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]}'." if !Hayabusa.const_defined?(:FCGI_CONF)
|
50
|
-
conf = Hayabusa::FCGI_CONF
|
51
|
-
|
52
|
-
hayabusa_conf = Hayabusa::FCGI_CONF[:hayabusa]
|
53
|
-
hayabusa_conf.merge!(
|
54
|
-
:cmdline => false,
|
55
|
-
:port => 0 #Ruby picks random port and we get the actual port after starting the appserver.
|
56
|
-
)
|
57
|
-
|
58
|
-
#Figure out if this should be a host-FCGI-process or a proxy-FCGI-process.
|
59
|
-
fcgi_config_fp = "#{Knj::Os.tmpdir}/hayabusa_fcgi_#{hayabusa_conf[:title]}_fcgi.conf"
|
60
|
-
FileUtils.touch(fcgi_config_fp) if !File.exists?(fcgi_config_fp)
|
61
|
-
|
62
|
-
begin
|
63
|
-
File.open(fcgi_config_fp) do |fp|
|
64
|
-
fp.flock(File::LOCK_EX)
|
65
|
-
|
66
|
-
fcgi_config_cont = File.read(fcgi_config_fp)
|
67
|
-
|
68
|
-
if !fcgi_config_cont.empty?
|
69
|
-
fcgi_config = Marshal.load(File.read(fcgi_config_fp))
|
70
|
-
pid = fcgi_config[:pid]
|
71
|
-
|
72
|
-
if Knj::Unix_proc.pid_running?(pid)
|
73
|
-
fcgi_proxy = fcgi_config
|
74
|
-
|
75
|
-
require "http2"
|
76
|
-
http = Http2.new(:host => "localhost", :port => fcgi_proxy[:port].to_i)
|
77
|
-
fcgi_proxy[:http] = http
|
78
|
-
end
|
79
|
-
else
|
80
|
-
fcgi_config = nil
|
81
|
-
end
|
82
|
-
|
83
|
-
if !fcgi_proxy
|
84
|
-
File.open(fcgi_config_fp, "w") do |fp|
|
85
|
-
hayabusa = Hayabusa.new(hayabusa_conf)
|
86
|
-
|
87
|
-
#Start web-server for proxy-requests.
|
88
|
-
hayabusa.start
|
89
|
-
|
90
|
-
fp.write(Marshal.dump(
|
91
|
-
:pid => Process.pid,
|
92
|
-
:port => hayabusa.port
|
93
|
-
))
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
ensure
|
98
|
-
File.open(fcgi_config_fp).flock(File::LOCK_UN)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
if fcgi_proxy
|
105
|
-
#Proxy request to the host-FCGI-process.
|
106
|
-
$stderr.puts "[hayabusa] Proxying request." if debug
|
107
|
-
cgi_tools.proxy_request_to(:cgi => cgi, :http => fcgi_proxy[:http])
|
108
|
-
else
|
109
|
-
#Host the FCGI-process.
|
110
|
-
$stderr.puts "[hayabusa] Running request as CGI." if debug
|
111
|
-
|
112
|
-
#Enforce $stdout variable.
|
113
|
-
$stdout = hayabusa.cio
|
114
|
-
|
115
|
-
#The rest is copied from the FCGI-part.
|
116
|
-
headers = {}
|
117
|
-
cgi.env_table.each do |key, val|
|
118
|
-
if key[0, 5] == "HTTP_" and key != "HTTP_HAYABUSA_FCGI_CONFIG"
|
119
|
-
key = key[5, key.length].gsub("_", " ").gsub(" ", "-")
|
120
|
-
headers[key] = val
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
meta = cgi.env_table.to_hash
|
125
|
-
|
126
|
-
uri = Knj::Web.parse_uri(meta["REQUEST_URI"])
|
127
|
-
meta["PATH_TRANSLATED"] = File.basename(uri[:path])
|
128
|
-
|
129
|
-
cgi_data = {
|
130
|
-
:cgi => cgi,
|
131
|
-
:headers => headers,
|
132
|
-
:get => Knj::Web.parse_urlquery(cgi.env_table["QUERY_STRING"], :urldecode => true, :force_utf8 => true),
|
133
|
-
:meta => meta
|
134
|
-
}
|
135
|
-
if cgi.request_method == "POST"
|
136
|
-
cgi_data[:post] = cgi_tools.convert_fcgi_post(cgi.params)
|
137
|
-
else
|
138
|
-
cgi_data[:post] = {}
|
139
|
-
end
|
140
|
-
|
141
|
-
hayabusa.config[:cgi] = cgi_data
|
142
|
-
|
143
|
-
|
144
|
-
#Handle request.
|
145
|
-
hayabusa.start_cgi_request
|
146
|
-
end
|
147
|
-
rescue Exception => e
|
148
|
-
cgi.print "Content-Type: text/html\r\n"
|
149
|
-
cgi.print "\r\n"
|
150
|
-
cgi.print Knj::Errors.error_str(e, :html => true)
|
151
|
-
cgi.print Knj.p(cgi_data, true) if cgi_data
|
152
|
-
end
|
153
|
-
end
|
25
|
+
fcgi = Hayabusa::Fcgi.new
|
26
|
+
fcgi.fcgi_loop
|
154
27
|
rescue Exception => e
|
155
28
|
if !e.is_a?(Interrupt)
|
156
29
|
File.open(error_log_file, "w") do |fp|
|
data/hayabusa.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{hayabusa}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kasper Johansen"]
|
12
|
-
s.date = %q{2012-08-
|
12
|
+
s.date = %q{2012-08-19}
|
13
13
|
s.description = %q{A threadded web/app-server that focuses on threadding, shared ressources, speed and more.}
|
14
14
|
s.email = %q{k@spernj.org}
|
15
15
|
s.executables = ["check_running.rb", "hayabusa_benchmark.rb", "hayabusa_cgi.rb", "hayabusa_fcgi.fcgi", "hayabusa_fcgi.rb", "knjappserver_start.rb"]
|
@@ -52,6 +52,7 @@ Gem::Specification.new do |s|
|
|
52
52
|
"lib/hayabusa_ext/threadding_timeout.rb",
|
53
53
|
"lib/hayabusa_ext/translations.rb",
|
54
54
|
"lib/hayabusa_ext/web.rb",
|
55
|
+
"lib/hayabusa_fcgi.rb",
|
55
56
|
"lib/hayabusa_http_server.rb",
|
56
57
|
"lib/hayabusa_http_session.rb",
|
57
58
|
"lib/hayabusa_http_session_contentgroup.rb",
|
@@ -119,6 +120,7 @@ Gem::Specification.new do |s|
|
|
119
120
|
s.add_runtime_dependency(%q<mail>, [">= 0"])
|
120
121
|
s.add_runtime_dependency(%q<datet>, [">= 0"])
|
121
122
|
s.add_runtime_dependency(%q<http2>, [">= 0"])
|
123
|
+
s.add_runtime_dependency(%q<tpool>, [">= 0"])
|
122
124
|
s.add_development_dependency(%q<json>, [">= 0"])
|
123
125
|
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
124
126
|
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
@@ -130,6 +132,7 @@ Gem::Specification.new do |s|
|
|
130
132
|
s.add_dependency(%q<mail>, [">= 0"])
|
131
133
|
s.add_dependency(%q<datet>, [">= 0"])
|
132
134
|
s.add_dependency(%q<http2>, [">= 0"])
|
135
|
+
s.add_dependency(%q<tpool>, [">= 0"])
|
133
136
|
s.add_dependency(%q<json>, [">= 0"])
|
134
137
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
135
138
|
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
@@ -142,6 +145,7 @@ Gem::Specification.new do |s|
|
|
142
145
|
s.add_dependency(%q<mail>, [">= 0"])
|
143
146
|
s.add_dependency(%q<datet>, [">= 0"])
|
144
147
|
s.add_dependency(%q<http2>, [">= 0"])
|
148
|
+
s.add_dependency(%q<tpool>, [">= 0"])
|
145
149
|
s.add_dependency(%q<json>, [">= 0"])
|
146
150
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
147
151
|
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
data/lib/hayabusa.rb
CHANGED
@@ -47,7 +47,8 @@ class Hayabusa
|
|
47
47
|
gems = [
|
48
48
|
[:Erubis, "erubis"],
|
49
49
|
[:Knj, "knjrbfw"],
|
50
|
-
[:Tsafe, "tsafe"]
|
50
|
+
[:Tsafe, "tsafe"],
|
51
|
+
[:Tpool, "tpool"]
|
51
52
|
]
|
52
53
|
|
53
54
|
gems.each do |gem|
|
@@ -96,6 +97,20 @@ class Hayabusa
|
|
96
97
|
|
97
98
|
|
98
99
|
@debug = @config[:debug]
|
100
|
+
if @debug
|
101
|
+
if !@config.key?(:debug_log) or @config[:debug_log]
|
102
|
+
@debug_log = true
|
103
|
+
else
|
104
|
+
@debug_log = false
|
105
|
+
end
|
106
|
+
|
107
|
+
if !@config.key?(:debug_print) or @config[:debug_print]
|
108
|
+
@debug_print = true
|
109
|
+
else
|
110
|
+
@debug_print = false
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
99
114
|
@paused = 0
|
100
115
|
@paused_mutex = Mutex.new
|
101
116
|
@should_restart = false
|
@@ -106,6 +121,11 @@ class Hayabusa
|
|
106
121
|
@eruby_cache = {}
|
107
122
|
@httpsessions_ids = {}
|
108
123
|
|
124
|
+
if @debug_log
|
125
|
+
@log_fp = File.open("/tmp/hayabusa_#{@config[:title]}.log", "w")
|
126
|
+
@log_fp.sync = true
|
127
|
+
end
|
128
|
+
|
109
129
|
@path_hayabusa = File.dirname(__FILE__)
|
110
130
|
|
111
131
|
|
@@ -115,7 +135,7 @@ class Hayabusa
|
|
115
135
|
"#{@path_hayabusa}/class_customio.rb"
|
116
136
|
]
|
117
137
|
|
118
|
-
|
138
|
+
self.log_puts "Auto restarting." if @debug
|
119
139
|
@mod_event = Knj::Event_filemod.new(:wait => 2, :paths => paths, &self.method(:on_event_filemod))
|
120
140
|
end
|
121
141
|
|
@@ -149,12 +169,12 @@ class Hayabusa
|
|
149
169
|
]
|
150
170
|
|
151
171
|
files.each do |file|
|
152
|
-
|
172
|
+
self.log_puts "Loading: '#{file}'." if @debug
|
153
173
|
self.loadfile(file)
|
154
174
|
end
|
155
175
|
|
156
176
|
|
157
|
-
|
177
|
+
self.log_puts "Setting up database." if @debug
|
158
178
|
if @config[:db].is_a?(Knj::Db)
|
159
179
|
@db = @config[:db]
|
160
180
|
elsif @config[:db].is_a?(Hash)
|
@@ -182,7 +202,7 @@ class Hayabusa
|
|
182
202
|
|
183
203
|
|
184
204
|
if !@config.key?(:dbrev) or @config[:dbrev]
|
185
|
-
|
205
|
+
self.log_puts "Updating database." if @debug
|
186
206
|
dbrev_args = {"schema" => Hayabusa::Database::SCHEMA, "db" => @db}
|
187
207
|
dbrev_args.merge!(@config[:dbrev_args]) if @config.key?(:dbrev_args)
|
188
208
|
Knj::Db::Revision.new.init_db(dbrev_args)
|
@@ -190,7 +210,7 @@ class Hayabusa
|
|
190
210
|
end
|
191
211
|
|
192
212
|
|
193
|
-
|
213
|
+
self.log_puts "Spawning objects." if @debug
|
194
214
|
@ob = Knj::Objects.new(
|
195
215
|
:db => db,
|
196
216
|
:class_path => @path_hayabusa,
|
@@ -216,12 +236,12 @@ class Hayabusa
|
|
216
236
|
require "#{@path_hayabusa}/kernel_ext/gettext_methods" if @config[:locales_gettext_funcs]
|
217
237
|
|
218
238
|
if @config[:magic_methods] or !@config.has_key?(:magic_methods)
|
219
|
-
|
239
|
+
self.log_puts "Loading magic-methods." if @debug
|
220
240
|
require "#{@path_hayabusa}/kernel_ext/magic_methods"
|
221
241
|
end
|
222
242
|
|
223
243
|
if @config[:customio] or !@config.has_key?(:customio)
|
224
|
-
|
244
|
+
self.log_puts "Loading custom-io." if @debug
|
225
245
|
|
226
246
|
if $stdout.class.name != "Hayabusa::Custom_io"
|
227
247
|
@cio = Hayabusa::Custom_io.new
|
@@ -231,7 +251,7 @@ class Hayabusa
|
|
231
251
|
|
232
252
|
|
233
253
|
#Save the PID to the run-file.
|
234
|
-
|
254
|
+
self.log_puts "Setting run-file." if @debug
|
235
255
|
tmpdir = "#{Knj::Os.tmpdir}/hayabusa"
|
236
256
|
tmppath = "#{tmpdir}/run_#{@config[:title]}"
|
237
257
|
|
@@ -248,7 +268,7 @@ class Hayabusa
|
|
248
268
|
|
249
269
|
#Set up various events for the appserver.
|
250
270
|
if !@config.key?(:events) or @config[:events]
|
251
|
-
|
271
|
+
self.log_puts "Loading events." if @debug
|
252
272
|
@events = Knj::Event_handler.new
|
253
273
|
@events.add_event(
|
254
274
|
:name => :check_page_access,
|
@@ -284,34 +304,34 @@ class Hayabusa
|
|
284
304
|
|
285
305
|
|
286
306
|
#Initialize the various feature-modules.
|
287
|
-
|
307
|
+
self.log_puts "Init sessions." if @debug
|
288
308
|
self.initialize_sessions
|
289
309
|
|
290
310
|
if !@config.key?(:threadding) or @config[:threadding]
|
291
311
|
self.loadfile("#{@path_hayabusa}/hayabusa_ext/threadding.rb")
|
292
312
|
self.loadfile("#{@path_hayabusa}/hayabusa_ext/threadding_timeout.rb")
|
293
|
-
|
313
|
+
self.log_puts "Init threadding." if @debug
|
294
314
|
self.initialize_threadding
|
295
315
|
end
|
296
316
|
|
297
|
-
|
317
|
+
self.log_puts "Init mailing." if @debug
|
298
318
|
self.initialize_mailing
|
299
319
|
|
300
|
-
|
320
|
+
self.log_puts "Init errors." if @debug
|
301
321
|
self.initialize_errors
|
302
322
|
|
303
|
-
|
323
|
+
self.log_puts "Init logging." if @debug
|
304
324
|
self.initialize_logging
|
305
325
|
|
306
326
|
if !@config.key?(:cleaner) or @config[:cleaner]
|
307
327
|
self.loadfile("#{@path_hayabusa}/hayabusa_ext/cleaner.rb")
|
308
|
-
|
328
|
+
self.log_puts "Init cleaner." if @debug
|
309
329
|
self.initialize_cleaner
|
310
330
|
end
|
311
331
|
|
312
332
|
if !@config.key?(:cmdline) or @config[:cmdline]
|
313
333
|
self.loadfile("#{@path_hayabusa}/hayabusa_ext/cmdline.rb")
|
314
|
-
|
334
|
+
self.log_puts "Init cmdline." if @debug
|
315
335
|
self.initialize_cmdline
|
316
336
|
end
|
317
337
|
|
@@ -320,7 +340,13 @@ class Hayabusa
|
|
320
340
|
Kernel.at_exit(&self.method(:stop))
|
321
341
|
|
322
342
|
|
323
|
-
|
343
|
+
self.log_puts "Appserver spawned." if @debug
|
344
|
+
end
|
345
|
+
|
346
|
+
#Outputs to stderr and logs it.
|
347
|
+
def log_puts(str)
|
348
|
+
@log_fp.puts str if @debug_log
|
349
|
+
STDOUT.puts str if @debug_print
|
324
350
|
end
|
325
351
|
|
326
352
|
def no_date(event, classname)
|
@@ -328,7 +354,7 @@ class Hayabusa
|
|
328
354
|
end
|
329
355
|
|
330
356
|
def on_event_filemod(event, path)
|
331
|
-
|
357
|
+
self.log_puts "File changed - restart server: #{path}"
|
332
358
|
@should_restart = true
|
333
359
|
@mod_event.destroy if @mod_event
|
334
360
|
end
|
@@ -360,25 +386,23 @@ class Hayabusa
|
|
360
386
|
#Starts the HTTP-server and threadpool.
|
361
387
|
def start
|
362
388
|
#Start the appserver.
|
363
|
-
|
389
|
+
self.log_puts "Spawning appserver." if @debug
|
364
390
|
@httpserv = Hayabusa::Http_server.new(self)
|
391
|
+
@httpserv.start
|
365
392
|
|
366
393
|
|
367
|
-
|
394
|
+
self.log_puts "Starting appserver." if @debug
|
368
395
|
Thread.current[:hayabusa] = {:hb => self} if !Thread.current[:hayabusa]
|
369
396
|
|
370
397
|
if @config[:autoload]
|
371
|
-
|
398
|
+
self.log_puts "Autoloading #{@config[:autoload]}" if @debug
|
372
399
|
require @config[:autoload]
|
373
400
|
end
|
374
401
|
|
375
402
|
begin
|
376
|
-
|
377
|
-
STDOUT.print "Threadpool startet.\n" if @debug
|
378
|
-
@httpserv.start
|
379
|
-
STDOUT.print "Appserver startet.\n" if @debug
|
403
|
+
self.log_puts "Appserver startet." if @debug
|
380
404
|
rescue Interrupt => e
|
381
|
-
|
405
|
+
self.log_puts "Got interrupt - trying to stop appserver." if @debug
|
382
406
|
self.stop
|
383
407
|
raise e
|
384
408
|
end
|
@@ -390,17 +414,17 @@ class Hayabusa
|
|
390
414
|
@stop_called = true
|
391
415
|
|
392
416
|
proc_stop = proc{
|
393
|
-
|
417
|
+
self.log_puts "Stopping appserver." if @debug
|
394
418
|
@httpserv.stop if @httpserv and @httpserv.respond_to?(:stop)
|
395
419
|
|
396
|
-
|
420
|
+
self.log_puts "Stopping threadpool." if @debug
|
397
421
|
@threadpool.stop if @threadpool
|
398
422
|
|
399
423
|
#This should be done first to be sure it finishes (else we have a serious bug).
|
400
|
-
|
424
|
+
self.log_puts "Flush out loaded sessions." if @debug
|
401
425
|
self.sessions_flush
|
402
426
|
|
403
|
-
|
427
|
+
self.log_puts "Stopping done..." if @debug
|
404
428
|
}
|
405
429
|
|
406
430
|
#If we cant get a paused-execution in 5 secs - we just force the stop.
|
@@ -409,7 +433,7 @@ class Hayabusa
|
|
409
433
|
self.paused_exec(&proc_stop)
|
410
434
|
end
|
411
435
|
rescue Timeout::Error, SystemExit, Interrupt
|
412
|
-
|
436
|
+
self.log_puts "Forcing stop-appserver - couldnt get timing window." if @debug
|
413
437
|
proc_stop.call
|
414
438
|
end
|
415
439
|
end
|
@@ -472,7 +496,7 @@ class Hayabusa
|
|
472
496
|
if @should_restart
|
473
497
|
loop do
|
474
498
|
if @should_restart_done
|
475
|
-
|
499
|
+
self.log_puts "Ending join because the restart is done."
|
476
500
|
break
|
477
501
|
end
|
478
502
|
|
@@ -508,7 +532,7 @@ class Hayabusa
|
|
508
532
|
def translations
|
509
533
|
if !@translations
|
510
534
|
#Start the Knj::Gettext_threadded- and Knj::Translations modules for translations.
|
511
|
-
|
535
|
+
self.log_puts "Loading Gettext and translations." if @debug
|
512
536
|
@translations = Knj::Translations.new(:db => @db)
|
513
537
|
@ob.requireclass(:Translation, :require => false, :class => Knj::Translations::Translation)
|
514
538
|
end
|