ramaze 2009.04 → 2009.05
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +168 -0
- data/MANIFEST +16 -6
- data/{README.markdown → README.md} +0 -14
- data/Rakefile +20 -20
- data/benchmark/bench_templates/bench.rb +67 -0
- data/benchmark/bench_templates/view/large.erb +79 -0
- data/benchmark/bench_templates/view/large.haml +41 -0
- data/benchmark/bench_templates/view/large.xhtml +79 -0
- data/benchmark/bench_templates/view/small.erb +21 -0
- data/benchmark/bench_templates/view/small.haml +12 -0
- data/benchmark/bench_templates/view/small.xhtml +21 -0
- data/benchmark/run.rb +14 -21
- data/benchmark/suite/minimal.rb +3 -5
- data/benchmark/suite/no_informer.rb +0 -2
- data/benchmark/suite/no_sessions.rb +3 -4
- data/benchmark/suite/no_template.rb +1 -3
- data/benchmark/suite/simple.rb +1 -3
- data/benchmark/suite/template_erubis.rb +0 -2
- data/benchmark/suite/template_etanni.rb +8 -0
- data/benchmark/suite/template_ezamar.rb +1 -3
- data/benchmark/suite/template_haml.rb +0 -2
- data/benchmark/suite/template_liquid.rb +0 -2
- data/benchmark/suite/template_markaby.rb +0 -2
- data/benchmark/suite/template_nagoro.rb +1 -3
- data/benchmark/suite/template_redcloth.rb +0 -2
- data/benchmark/suite/template_tenjin.rb +0 -2
- data/bin/ramaze +7 -300
- data/doc/AUTHORS +11 -7
- data/examples/app/chat/layout/{default.nag → default.xhtml} +0 -0
- data/examples/app/chat/view/{chat.nag → chat.xhtml} +0 -0
- data/examples/app/chat/view/{index.nag → index.xhtml} +0 -0
- data/examples/helpers/cache.rb +6 -4
- data/lib/ramaze.rb +2 -3
- data/lib/ramaze/cache/sequel.rb +17 -5
- data/lib/ramaze/gestalt.rb +3 -0
- data/lib/ramaze/helper/gestalt.rb +32 -0
- data/lib/ramaze/helper/paginate.rb +1 -0
- data/lib/ramaze/helper/ultraviolet.rb +2 -0
- data/lib/ramaze/log/rotatinginformer.rb +10 -10
- data/lib/ramaze/request.rb +1 -4
- data/lib/ramaze/tool/bin.rb +330 -0
- data/lib/ramaze/version.rb +1 -1
- data/lib/ramaze/view.rb +3 -13
- data/lib/ramaze/view/erubis.rb +2 -2
- data/lib/ramaze/view/ezamar.rb +2 -2
- data/lib/ramaze/view/gestalt.rb +14 -0
- data/lib/ramaze/view/haml.rb +1 -1
- data/lib/ramaze/view/liquid.rb +2 -2
- data/lib/ramaze/view/maruku.rb +2 -1
- data/lib/ramaze/view/sass.rb +1 -1
- data/lib/ramaze/view/tenjin.rb +7 -4
- data/lib/vendor/route_exceptions.rb +8 -9
- data/ramaze.gemspec +6 -9
- data/spec/examples/caching.rb +2 -4
- data/spec/examples/element.rb +1 -0
- data/spec/examples/templates/template_ezamar.rb +1 -0
- data/spec/examples/templates/template_nagoro.rb +1 -0
- data/spec/ramaze/error.rb +1 -1
- data/spec/ramaze/gestalt.rb +22 -16
- data/spec/ramaze/helper/localize.rb +10 -8
- data/spec/ramaze/helper/sequel_form.rb +2 -0
- data/spec/ramaze/helper/user.rb +2 -2
- data/spec/ramaze/view/gestalt.rb +94 -0
- data/spec/ramaze/view/gestalt/external.ges +8 -0
- data/tasks/install_dependencies.rake +1 -1
- data/tasks/release.rake +5 -4
- metadata +20 -20
- data/benchmark/suite/template_builder.rb +0 -12
- data/lib/ramaze/snippets/kernel/constant.rb +0 -41
@@ -0,0 +1,41 @@
|
|
1
|
+
%html
|
2
|
+
%head
|
3
|
+
%title
|
4
|
+
- if @title
|
5
|
+
= @title
|
6
|
+
%body
|
7
|
+
%h1
|
8
|
+
- if @h1
|
9
|
+
= @h1
|
10
|
+
%div
|
11
|
+
- if @v1
|
12
|
+
- if @v2
|
13
|
+
- if @v3
|
14
|
+
- if @v4
|
15
|
+
- if @v5
|
16
|
+
- if @v6
|
17
|
+
- if @v7
|
18
|
+
- if @v8
|
19
|
+
- if @v9
|
20
|
+
- if @v10
|
21
|
+
- if @v11
|
22
|
+
- if @v12
|
23
|
+
- if @v13
|
24
|
+
- if @v14
|
25
|
+
- if @v15
|
26
|
+
- if @v16
|
27
|
+
- if @v17
|
28
|
+
- if @v18
|
29
|
+
- if @v19
|
30
|
+
- if @v20
|
31
|
+
- if @v21
|
32
|
+
- if @v22
|
33
|
+
- if @v23
|
34
|
+
- if @v24
|
35
|
+
- if @v25
|
36
|
+
- if @v26
|
37
|
+
- if @v27
|
38
|
+
- if @v28
|
39
|
+
- if @v29
|
40
|
+
- if @v30
|
41
|
+
= stuff
|
@@ -0,0 +1,79 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>
|
4
|
+
<?r if @title ?>
|
5
|
+
#{@title}
|
6
|
+
<?r end ?>
|
7
|
+
</title>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<h1>
|
11
|
+
<?r if @h1 ?>
|
12
|
+
#{@h1}
|
13
|
+
<?r end ?>
|
14
|
+
</h1>
|
15
|
+
<div>
|
16
|
+
<?r if @v1 ?>
|
17
|
+
<?r if @v2 ?>
|
18
|
+
<?r if @v3 ?>
|
19
|
+
<?r if @v4 ?>
|
20
|
+
<?r if @v5 ?>
|
21
|
+
<?r if @v6 ?>
|
22
|
+
<?r if @v7 ?>
|
23
|
+
<?r if @v8 ?>
|
24
|
+
<?r if @v9 ?>
|
25
|
+
<?r if @v10 ?>
|
26
|
+
<?r if @v11 ?>
|
27
|
+
<?r if @v12 ?>
|
28
|
+
<?r if @v13 ?>
|
29
|
+
<?r if @v14 ?>
|
30
|
+
<?r if @v15 ?>
|
31
|
+
<?r if @v16 ?>
|
32
|
+
<?r if @v17 ?>
|
33
|
+
<?r if @v18 ?>
|
34
|
+
<?r if @v19 ?>
|
35
|
+
<?r if @v20 ?>
|
36
|
+
<?r if @v21 ?>
|
37
|
+
<?r if @v22 ?>
|
38
|
+
<?r if @v23 ?>
|
39
|
+
<?r if @v24 ?>
|
40
|
+
<?r if @v25 ?>
|
41
|
+
<?r if @v26 ?>
|
42
|
+
<?r if @v27 ?>
|
43
|
+
<?r if @v28 ?>
|
44
|
+
<?r if @v29 ?>
|
45
|
+
<?r if @v30 ?>
|
46
|
+
#{stuff}
|
47
|
+
<?r end ?>
|
48
|
+
<?r end ?>
|
49
|
+
<?r end ?>
|
50
|
+
<?r end ?>
|
51
|
+
<?r end ?>
|
52
|
+
<?r end ?>
|
53
|
+
<?r end ?>
|
54
|
+
<?r end ?>
|
55
|
+
<?r end ?>
|
56
|
+
<?r end ?>
|
57
|
+
<?r end ?>
|
58
|
+
<?r end ?>
|
59
|
+
<?r end ?>
|
60
|
+
<?r end ?>
|
61
|
+
<?r end ?>
|
62
|
+
<?r end ?>
|
63
|
+
<?r end ?>
|
64
|
+
<?r end ?>
|
65
|
+
<?r end ?>
|
66
|
+
<?r end ?>
|
67
|
+
<?r end ?>
|
68
|
+
<?r end ?>
|
69
|
+
<?r end ?>
|
70
|
+
<?r end ?>
|
71
|
+
<?r end ?>
|
72
|
+
<?r end ?>
|
73
|
+
<?r end ?>
|
74
|
+
<?r end ?>
|
75
|
+
<?r end ?>
|
76
|
+
<?r end ?>
|
77
|
+
</div>
|
78
|
+
</body>
|
79
|
+
</html>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>
|
4
|
+
<% if @title %>
|
5
|
+
<%= @title %>
|
6
|
+
<% end %>
|
7
|
+
</title>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<h1>
|
11
|
+
<% if @h1 %>
|
12
|
+
<%= @h1 %>
|
13
|
+
<% end %>
|
14
|
+
</h1>
|
15
|
+
<div>
|
16
|
+
<% if @div %>
|
17
|
+
<%= @div %>
|
18
|
+
<% end %>
|
19
|
+
</div>
|
20
|
+
</body>
|
21
|
+
</html>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>
|
4
|
+
<?r if @title ?>
|
5
|
+
#{@title}
|
6
|
+
<?r end ?>
|
7
|
+
</title>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<h1>
|
11
|
+
<?r if @h1 ?>
|
12
|
+
#{@h1}
|
13
|
+
<?r end ?>
|
14
|
+
</h1>
|
15
|
+
<div>
|
16
|
+
<?r if @div ?>
|
17
|
+
#{@div}
|
18
|
+
<?r end ?>
|
19
|
+
</div>
|
20
|
+
</body>
|
21
|
+
</html>
|
data/benchmark/run.rb
CHANGED
@@ -144,8 +144,8 @@ class RamazeBenchmark
|
|
144
144
|
end
|
145
145
|
|
146
146
|
attr_accessor :requests, :adapters, :port, :log, :display_code, :target
|
147
|
-
attr_accessor :concurrent, :paths, :benchmarker, :informer
|
148
|
-
attr_accessor :
|
147
|
+
attr_accessor :concurrent, :paths, :benchmarker, :informer
|
148
|
+
attr_accessor :mode, :show_log, :formats
|
149
149
|
|
150
150
|
def initialize()
|
151
151
|
@adapters = [:webrick]
|
@@ -157,10 +157,9 @@ class RamazeBenchmark
|
|
157
157
|
@paths = ["/"]
|
158
158
|
@target = /.+/
|
159
159
|
@informer = true
|
160
|
-
@sessions = true
|
161
|
-
@ignored_tags = [:debug, :dev]
|
162
160
|
@formats = ["text"]
|
163
161
|
@writers = []
|
162
|
+
@mode = :live
|
164
163
|
yield self
|
165
164
|
end
|
166
165
|
|
@@ -175,8 +174,8 @@ class RamazeBenchmark
|
|
175
174
|
end
|
176
175
|
|
177
176
|
# benchmarks
|
178
|
-
|
179
|
-
Dir
|
177
|
+
glob = File.expand_path('../suite/*.rb', __FILE__)
|
178
|
+
Dir.glob(glob) do |filename|
|
180
179
|
@adapters.each do |adapter|
|
181
180
|
@paths.each do |path|
|
182
181
|
benchmark(filename, adapter, path) if @target.match(filename)
|
@@ -199,7 +198,6 @@ class RamazeBenchmark
|
|
199
198
|
l :Concurrent, @concurrent
|
200
199
|
l :Path, path
|
201
200
|
l :Informer, @informer
|
202
|
-
l :Sessions, @sessions
|
203
201
|
if @display_code
|
204
202
|
l :Code, "<code ruby>\n#{File.read(filename)}\n</code>\n\n"
|
205
203
|
end
|
@@ -248,17 +246,17 @@ class RamazeBenchmark
|
|
248
246
|
def ramaze(filename, adapter)
|
249
247
|
pid = fork do
|
250
248
|
begin
|
251
|
-
require
|
252
|
-
Ramaze
|
249
|
+
require 'ramaze'
|
250
|
+
Ramaze.options.mode = @mode
|
253
251
|
if @informer
|
254
252
|
unless @show_log
|
255
|
-
|
253
|
+
require 'ramaze/log/informer'
|
254
|
+
Ramaze::Log.loggers = [Ramaze::Logger::Informer.new("/dev/null")]
|
256
255
|
end
|
257
256
|
else
|
258
257
|
Ramaze::Log.loggers = []
|
259
258
|
end
|
260
|
-
|
261
|
-
Ramaze::Global.sourcereload = false
|
259
|
+
require filename
|
262
260
|
Ramaze.start :adapter => adapter, :port => @port
|
263
261
|
rescue LoadError => ex; l :Error, ex; end
|
264
262
|
end
|
@@ -324,23 +322,18 @@ RamazeBenchmark.new do |bm|
|
|
324
322
|
bm.paths = paths.split(",")
|
325
323
|
end
|
326
324
|
|
327
|
-
opt.on('--
|
328
|
-
bm.
|
325
|
+
opt.on('--mode MODE', '[live] Ramaze mode') do |mode|
|
326
|
+
bm.mode = mode.to_sym
|
329
327
|
end
|
330
328
|
|
331
|
-
opt.on('--
|
332
|
-
|
333
|
-
bm.ignored_tags = tags.split(",").map{|e| e.to_sym }
|
329
|
+
opt.on('--no-informer', 'Disable informer') do
|
330
|
+
bm.informer = false
|
334
331
|
end
|
335
332
|
|
336
333
|
opt.on('--show-log', 'Show log') do
|
337
334
|
bm.show_log = true
|
338
335
|
end
|
339
336
|
|
340
|
-
opt.on('--no-sessions', 'Disable sessions') do
|
341
|
-
bm.sessions = false
|
342
|
-
end
|
343
|
-
|
344
337
|
opt.on('--target REGEXP',
|
345
338
|
'[/.+/] Specify benchmark scripts to measure') do |name|
|
346
339
|
bm.target = Regexp.compile(name)
|
data/benchmark/suite/minimal.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'ramaze'
|
2
|
-
|
3
1
|
class MainController < Ramaze::Controller
|
4
2
|
engine :None
|
5
3
|
|
@@ -8,6 +6,6 @@ class MainController < Ramaze::Controller
|
|
8
6
|
end
|
9
7
|
end
|
10
8
|
|
11
|
-
Ramaze
|
12
|
-
Ramaze
|
13
|
-
Ramaze::Log.loggers
|
9
|
+
Ramaze.middleware!(:bench){|m| m.run(Ramaze::AppMap) }
|
10
|
+
Ramaze.options.mode = :bench
|
11
|
+
Ramaze::Log.loggers.clear
|
@@ -1,10 +1,9 @@
|
|
1
|
-
require 'ramaze'
|
2
|
-
|
3
1
|
class MainController < Ramaze::Controller
|
4
2
|
def index
|
5
3
|
"Hello, World!"
|
6
4
|
end
|
7
5
|
end
|
8
6
|
|
9
|
-
Ramaze
|
10
|
-
Ramaze
|
7
|
+
Ramaze.middleware!(:nosessions){|m| m.run(Ramaze::AppMap) }
|
8
|
+
Ramaze.options.mode = :nosessions
|
9
|
+
Ramaze::Log.loggers.clear
|
data/benchmark/suite/simple.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
require 'ramaze'
|
2
|
-
|
3
1
|
class MainController < Ramaze::Controller
|
4
2
|
engine :Ezamar
|
5
3
|
|
6
4
|
def index
|
7
5
|
@hello = "Hello, World!"
|
8
|
-
'<html><body><? 10.times do ?><span>#{@hello}</span><?r end ?></body></html>'
|
6
|
+
'<html><body><?r 10.times do ?><span>#{@hello}</span><?r end ?></body></html>'
|
9
7
|
end
|
10
8
|
end
|
@@ -1,10 +1,8 @@
|
|
1
|
-
require 'ramaze'
|
2
|
-
|
3
1
|
class MainController < Ramaze::Controller
|
4
2
|
engine :Nagoro
|
5
3
|
|
6
4
|
def index
|
7
5
|
@hello = "Hello, World!"
|
8
|
-
'<html><body><span times=10>#{@hello}</span></body></html>'
|
6
|
+
'<html><body><span times="10">#{@hello}</span></body></html>'
|
9
7
|
end
|
10
8
|
end
|
data/bin/ramaze
CHANGED
@@ -1,303 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
def include_ramaze
|
4
|
-
begin
|
5
|
-
$:.unshift File.join(File.dirname(__FILE__), '/../lib')
|
6
|
-
require 'ramaze'
|
7
|
-
rescue LoadError
|
8
|
-
$:.shift
|
9
|
-
|
10
|
-
begin
|
11
|
-
require 'rubygems'
|
12
|
-
rescue LoadError
|
13
|
-
end
|
14
|
-
require 'ramaze'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def usage
|
19
|
-
txt = <<-TXT
|
20
|
-
Usage:
|
21
|
-
|
22
|
-
ramaze <start [PIDFILE]|stop [PIDFILE]|restart [PIDFILE]|status [PIDFILE]|create PROJECT|console> [ruby/rack options]
|
23
|
-
|
24
|
-
Commands:
|
25
|
-
* All commands which take an optional PIDFILE default to PROJECT.pid if you do not supply one.
|
26
|
-
* All commands which start a ramaze instance will default to webrick on port 7000 unless you supply
|
27
|
-
the rack options -p/--port PORT and/or * -s/--server SERVER.
|
28
|
-
|
29
|
-
start - Starts an instance of this application.
|
30
|
-
|
31
|
-
stop - Stops a running instance of this application.
|
32
|
-
|
33
|
-
restart - Stops running instance of this application, then starts it back up. Pidfile
|
34
|
-
(if supplied) is used for both stop and start.
|
35
|
-
|
36
|
-
status - Gives status of a running ramaze instance
|
37
|
-
|
38
|
-
create - Creates a new prototype Ramaze application in a directory named PROJECT in
|
39
|
-
the current directory. ramaze create foo would make ./foo containing an
|
40
|
-
application prototype. Rack options are ignored here.
|
41
|
-
|
42
|
-
console - Starts an irb console with app.rb (and irb completion) loaded. This command
|
43
|
-
ignores rack options, ARGV is passed on to IRB.
|
44
|
-
TXT
|
45
|
-
if is_windows?
|
46
|
-
txt << %x{ruby #{rackup_path} --help}.split("\n").reject { |line| line.match(/^Usage:/) }.join("\n\t")
|
47
|
-
else
|
48
|
-
txt << %x{#{rackup_path} --help}.split("\n").reject { |line| line.match(/^Usage:/) }.join("\n\t")
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
## Methods for commands {{{
|
53
|
-
def start
|
54
|
-
# Find the name of this app
|
55
|
-
app_name = default_pidfile.sub(/\.pid$/,'')
|
56
|
-
added_args = []
|
57
|
-
if daemonize = OURARGS.detect { |arg| arg.match(/^(-[dD]|--daemonize)$/) }
|
58
|
-
if pid_arg = OURARGS.detect { |arg| arg.match(/^(-P|--pid)/) }
|
59
|
-
puts "User supplied pid: #{pid_arg}"
|
60
|
-
pid_file = OURARGS[OURARGS.index(pid_arg) + 1]
|
61
|
-
puts "Starting daemon with user defined pidfile: #{pid_file}"
|
62
|
-
else
|
63
|
-
puts "Starting daemon with default pidfile: #{pid_file = default_pidfile}"
|
64
|
-
added_args += ["-P", pid_file]
|
65
|
-
end
|
66
|
-
if check_running?(pid_file)
|
67
|
-
$stderr.puts "Ramaze is already running with pidfile: #{pid_file}"
|
68
|
-
exit 127
|
69
|
-
end
|
70
|
-
end
|
71
|
-
added_args += ["-p", "7000"] unless OURARGS.detect { |arg| arg.match(/^(-p|--port)/) }
|
72
|
-
added_args += ["-s", "webrick"] unless OURARGS.detect { |arg| arg.match(/^(-s|--server)/) }
|
73
|
-
if is_windows?
|
74
|
-
exec("ruby", rackup_path.to_s, "config.ru", *(ARGV + added_args))
|
75
|
-
else
|
76
|
-
exec(rackup_path.to_s, "config.ru", *(ARGV + added_args))
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def create(command)
|
81
|
-
project_name = OURARGS[OURARGS.index(command) + 1]
|
82
|
-
if project_name.nil?
|
83
|
-
$stderr.puts "Must supply a project name" if project_name.nil?
|
84
|
-
puts usage
|
85
|
-
exit 1
|
86
|
-
end
|
87
|
-
opts = {}
|
88
|
-
if OURARGS.detect { |arg| arg.match(/^(--force)/) }
|
89
|
-
puts "Overwriting any existing files as requested."
|
90
|
-
opts[:force] = true
|
91
|
-
end
|
92
|
-
if OURARGS.detect { |arg| arg.match(/^(--amend)/) }
|
93
|
-
puts "Only amending missing files as requested."
|
94
|
-
opts[:amend] = true
|
95
|
-
end
|
96
|
-
include_ramaze
|
97
|
-
require 'ramaze/tool/create'
|
98
|
-
Ramaze::Tool::Create.create(project_name, opts)
|
99
|
-
end
|
100
|
-
|
101
|
-
def stop(command)
|
102
|
-
unless pid_file = find_pid(OURARGS[OURARGS.index(command) + 1])
|
103
|
-
$stderr.puts "No pid_file found! Cannot stop ramaze (may not be started)."
|
104
|
-
return false
|
105
|
-
end
|
106
|
-
pid = File.read(pid_file).to_i
|
107
|
-
puts "Stopping pid #{pid}"
|
108
|
-
Process.kill("INT", pid)
|
109
|
-
sleep 2
|
110
|
-
if is_running?(pid)
|
111
|
-
$stderr.puts "Process #{pid} did not die, forcing it with -9"
|
112
|
-
Process.kill(9, pid)
|
113
|
-
File.unlink(pid_file) if File.file?(pid_file)
|
114
|
-
true
|
115
|
-
else
|
116
|
-
File.unlink(pid_file) if File.file?(pid_file)
|
117
|
-
true
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def status(command)
|
122
|
-
unless pid_file = find_pid(OURARGS[OURARGS.index(command) + 1])
|
123
|
-
$stderr.puts "No pid_file found! Ramaze may not be started."
|
124
|
-
exit 1
|
125
|
-
end
|
126
|
-
puts "Pid file #{pid_file} found, PID is #{pid = File.read(pid_file)}"
|
127
|
-
unless is_running?(pid.to_i)
|
128
|
-
$stderr.puts "PID #{pid} is not running"
|
129
|
-
exit 1
|
130
|
-
end
|
131
|
-
if is_windows?
|
132
|
-
wmi = WIN32OLE.connect("winmgmts://")
|
133
|
-
processes, ours = wmi.ExecQuery("select * from win32_process where ProcessId = #{pid}"), []
|
134
|
-
processes.each { |p| ours << [p.Name, p.CommandLine, p.VirtualSize, p.CreationDate, p.ExecutablePath, p.Status ] }
|
135
|
-
puts "Ramaze is running!\n\tName: %s\n\tCommand Line: %s\n\tVirtual Size: %s\n\tStarted: %s\n\tExec Path: %s\n\tStatus: %s" % ours.first
|
136
|
-
else
|
137
|
-
require "pathname"
|
138
|
-
# Check for /proc
|
139
|
-
if File.directory?(proc_dir = Pathname.new("/proc"))
|
140
|
-
proc_dir = proc_dir.join(pid)
|
141
|
-
# If we have a "stat" file, we'll assume linux and get as much info
|
142
|
-
# as we can
|
143
|
-
if File.file?(stat_file = proc_dir.join("stat"))
|
144
|
-
stats = File.read(stat_file).split
|
145
|
-
puts "Ramaze is running!\n\tCommand Line: %s\n\tVirtual Size: %s\n\tStarted: %s\n\tExec Path: %s\n\tStatus: %s" % [
|
146
|
-
File.read(proc_dir.join("cmdline")).split("\000").join(" "),
|
147
|
-
"%s k" % (stats[22].to_f / 1024),
|
148
|
-
File.mtime(proc_dir),
|
149
|
-
File.readlink(proc_dir.join("exe")),
|
150
|
-
stats[2]
|
151
|
-
]
|
152
|
-
exit
|
153
|
-
end
|
154
|
-
end
|
155
|
-
# Fallthrough status, just print a ps
|
156
|
-
puts "Ramaze process #{pid} is running!"
|
157
|
-
begin
|
158
|
-
puts %x{ps l #{pid}}
|
159
|
-
rescue
|
160
|
-
puts "No further information available"
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
## End Command methods }}}
|
166
|
-
|
167
|
-
# Helper methods {{{
|
168
|
-
def default_pidfile
|
169
|
-
return @default_pidfile if @default_pidfile
|
2
|
+
begin
|
170
3
|
require "pathname"
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
begin
|
177
|
-
require "win32ole"
|
178
|
-
rescue LoadError
|
179
|
-
end
|
180
|
-
@is_win ||= Object.const_defined?("WIN32OLE")
|
181
|
-
end
|
182
|
-
|
183
|
-
def rackup_path
|
184
|
-
return @rackup_path if @rackup_path
|
185
|
-
# Use the supplied path if the user supplied -R
|
186
|
-
if path_supplied = ARGV.delete("-R")
|
187
|
-
@rackup_path = ARGV.delete(OURARGS[OURARGS.index("-R") + 1])
|
188
|
-
if @rackup_path and File.file?(@rackup_path)
|
189
|
-
return @rackup_path
|
190
|
-
else
|
191
|
-
$stderr.puts "rackup does not exist at #{@rackup_path} (given with -R)"
|
192
|
-
end
|
193
|
-
end
|
194
|
-
# Check with 'which' on platforms which support it
|
195
|
-
unless is_windows?
|
196
|
-
@rackup_path = %x{which rackup}.to_s.chomp
|
197
|
-
if @rackup_path.size > 0 and File.file?(@rackup_path)
|
198
|
-
return @rackup_path
|
199
|
-
end
|
200
|
-
end
|
201
|
-
# check for rackup in RUBYLIB
|
202
|
-
libs = ENV["RUBYLIB"].to_s.split(is_windows? ? ";" : ":")
|
203
|
-
if rack_lib = libs.detect { |r| r.match %r<(\\|/)rack\1> }
|
204
|
-
require "pathname"
|
205
|
-
@rackup_path = Pathname.new(rack_lib).parent.join("bin").join("rackup").expand_path
|
206
|
-
return @rackup_path if File.file?(@rackup_path)
|
207
|
-
end
|
208
|
-
begin
|
209
|
-
require "rubygems"
|
210
|
-
require "rack"
|
211
|
-
require "pathname"
|
212
|
-
@rackup_path = Pathname.new(Gem.bindir).join("rackup").to_s
|
213
|
-
return @rackup_path if File.file?(@rackup_path)
|
214
|
-
rescue LoadError
|
215
|
-
nil
|
216
|
-
end
|
217
|
-
@rackup_path = nil
|
218
|
-
raise "Cannot find path to rackup, please supply full path to rackup with -R"
|
219
|
-
end
|
220
|
-
|
221
|
-
def is_running?(pid)
|
222
|
-
if is_windows?
|
223
|
-
wmi = WIN32OLE.connect("winmgmts://")
|
224
|
-
processes, ours = wmi.ExecQuery("select * from win32_process where ProcessId = #{pid}"), []
|
225
|
-
processes.each { |process| ours << process.Name }
|
226
|
-
ours.first.nil?
|
227
|
-
else
|
228
|
-
begin
|
229
|
-
prio = Process.getpriority(Process::PRIO_PROCESS, pid)
|
230
|
-
true
|
231
|
-
rescue Errno::ESRCH
|
232
|
-
false
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
def check_running?(pid_file)
|
238
|
-
return false unless File.file?(pid_file)
|
239
|
-
is_running?(File.read(pid_file).to_i)
|
240
|
-
end
|
241
|
-
|
242
|
-
def find_pid(pid_file)
|
243
|
-
if pid_file.nil? or not File.file?(pid_file)
|
244
|
-
pid_file = default_pidfile
|
245
|
-
end
|
246
|
-
unless File.file?(pid_file)
|
247
|
-
$stderr.puts "Could not find running process id."
|
248
|
-
return false
|
249
|
-
end
|
250
|
-
pid_file
|
251
|
-
end
|
252
|
-
|
253
|
-
## End helper methods }}}
|
254
|
-
|
255
|
-
OURARGS = ARGV.dup
|
256
|
-
command = ARGV.detect { |arg| arg.match(/^(?:--?)?(?:start|stop|restart|create|h(?:elp)?|v(?:ersion)?|console|status)/) }
|
257
|
-
if command.nil?
|
258
|
-
command = ""
|
259
|
-
else
|
260
|
-
ARGV.delete(command)
|
261
|
-
end
|
262
|
-
|
263
|
-
case command
|
264
|
-
when /^(?:--?)?status$/
|
265
|
-
status(command)
|
266
|
-
when /^(?:--?)?restart$/
|
267
|
-
stop(command)
|
268
|
-
start
|
269
|
-
when /^(?:--?)?start$/
|
270
|
-
start
|
271
|
-
when /^(?:--?)?create$/
|
272
|
-
create(command)
|
273
|
-
when /^(?:--?)?stop$/
|
274
|
-
if stop(command)
|
275
|
-
puts "Ramazement has ended, go in peace."
|
276
|
-
$stdout.flush
|
277
|
-
else
|
278
|
-
puts "Ramaze failed to stop (or was not running)"
|
279
|
-
end
|
280
|
-
when /^(?:--?)?console$/
|
281
|
-
require "ramaze"
|
282
|
-
require "irb"
|
283
|
-
require "irb/completion"
|
284
|
-
Ramaze.options.started = true
|
285
|
-
require "start"
|
286
|
-
IRB.start
|
287
|
-
puts "Ramazement has ended, go in peace."
|
288
|
-
when /^(?:--?)?h(elp)?$/
|
289
|
-
puts usage
|
290
|
-
when /^(?:--?)?v(ersion)?$/
|
291
|
-
include_ramaze
|
292
|
-
puts Ramaze::VERSION
|
293
|
-
exit
|
294
|
-
when /^$/
|
295
|
-
puts "Must supply a valid command"
|
296
|
-
puts usage
|
297
|
-
exit 1
|
298
|
-
else
|
299
|
-
puts "#{command} not implemented"
|
300
|
-
puts usage
|
301
|
-
exit 1
|
4
|
+
require Pathname.new(__FILE__).expand_path.dirname.join("..", "lib", "ramaze")
|
5
|
+
require "ramaze/bin_ramaze"
|
6
|
+
rescue LoadError
|
7
|
+
require "rubygems"
|
8
|
+
require "ramaze/tool/bin"
|
302
9
|
end
|
303
|
-
|
10
|
+
Ramaze::Tool::Bin::Cmd.run(ARGV)
|