ramaze 2011.01.30 → 2011.07.25
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/.mailmap +2 -0
- data/.rvmrc +1 -0
- data/README.md +119 -197
- data/Rakefile +14 -97
- data/bin/ramaze +6 -14
- data/doc/AUTHORS +8 -4
- data/doc/CHANGELOG +3784 -3339
- data/examples/app/chat/start.rb +2 -2
- data/lib/proto/app.rb +2 -3
- data/lib/proto/config.ru +4 -5
- data/lib/proto/controller/init.rb +11 -4
- data/lib/proto/controller/main.rb +12 -7
- data/lib/proto/layout/default.xhtml +56 -23
- data/lib/proto/model/init.rb +3 -1
- data/lib/proto/public/css/grid.css +107 -0
- data/lib/proto/public/css/layout.css +81 -0
- data/lib/proto/public/css/reset.css +123 -0
- data/lib/proto/public/css/text.css +109 -0
- data/lib/proto/public/images/bg.png +0 -0
- data/lib/proto/spec/main.rb +2 -2
- data/lib/proto/start.rb +11 -1
- data/lib/proto/view/index.xhtml +27 -23
- data/lib/ramaze.rb +0 -1
- data/lib/ramaze/app.rb +85 -12
- data/lib/ramaze/app_graph.rb +107 -0
- data/lib/ramaze/bin/console.rb +87 -0
- data/lib/ramaze/bin/create.rb +94 -0
- data/lib/ramaze/bin/helper.rb +107 -0
- data/lib/ramaze/bin/restart.rb +95 -0
- data/lib/ramaze/bin/runner.rb +141 -0
- data/lib/ramaze/bin/start.rb +206 -0
- data/lib/ramaze/bin/status.rb +152 -0
- data/lib/ramaze/bin/stop.rb +112 -0
- data/lib/ramaze/cache.rb +9 -4
- data/lib/ramaze/cache/localmemcache.rb +10 -13
- data/lib/ramaze/cache/lru.rb +49 -7
- data/lib/ramaze/cache/memcache.rb +170 -92
- data/lib/ramaze/cache/sequel.rb +301 -118
- data/lib/ramaze/controller.rb +108 -9
- data/lib/ramaze/controller/default.rb +15 -2
- data/lib/ramaze/current.rb +14 -2
- data/lib/ramaze/dependencies.rb +46 -0
- data/lib/ramaze/files.rb +38 -3
- data/lib/ramaze/gestalt.rb +12 -12
- data/lib/ramaze/helper.rb +0 -2
- data/lib/ramaze/helper/auth.rb +30 -23
- data/lib/ramaze/helper/blue_form.rb +175 -126
- data/lib/ramaze/helper/csrf.rb +76 -91
- data/lib/ramaze/helper/email.rb +105 -0
- data/lib/ramaze/helper/erector.rb +16 -15
- data/lib/ramaze/helper/gestalt.rb +2 -2
- data/lib/ramaze/helper/layout.rb +89 -73
- data/lib/ramaze/helper/link.rb +7 -6
- data/lib/ramaze/helper/localize.rb +6 -5
- data/lib/ramaze/helper/markaby.rb +25 -23
- data/lib/ramaze/helper/maruku.rb +3 -3
- data/lib/ramaze/helper/paginate.rb +19 -27
- data/lib/ramaze/helper/remarkably.rb +3 -3
- data/lib/ramaze/helper/request_accessor.rb +3 -3
- data/lib/ramaze/helper/send_file.rb +12 -8
- data/lib/ramaze/helper/simple_captcha.rb +5 -6
- data/lib/ramaze/helper/stack.rb +7 -4
- data/lib/ramaze/helper/tagz.rb +10 -11
- data/lib/ramaze/helper/thread.rb +19 -16
- data/lib/ramaze/helper/ultraviolet.rb +7 -4
- data/lib/ramaze/helper/user.rb +40 -21
- data/lib/ramaze/helper/xhtml.rb +29 -20
- data/lib/ramaze/log.rb +3 -11
- data/lib/ramaze/log/analogger.rb +5 -4
- data/lib/ramaze/log/growl.rb +9 -7
- data/lib/ramaze/log/hub.rb +3 -5
- data/lib/ramaze/log/informer.rb +15 -12
- data/lib/ramaze/log/knotify.rb +3 -5
- data/lib/ramaze/log/logger.rb +3 -5
- data/lib/ramaze/log/logging.rb +6 -8
- data/lib/ramaze/log/rotatinginformer.rb +27 -17
- data/lib/ramaze/log/syslog.rb +7 -7
- data/lib/ramaze/log/xosd.rb +3 -5
- data/lib/ramaze/middleware_compiler.rb +27 -4
- data/lib/ramaze/reloader.rb +50 -12
- data/lib/ramaze/reloader/watch_inotify.rb +4 -5
- data/lib/ramaze/reloader/watch_stat.rb +3 -3
- data/lib/ramaze/request.rb +18 -8
- data/lib/ramaze/response.rb +38 -7
- data/lib/ramaze/rest.rb +36 -0
- data/lib/ramaze/setup.rb +101 -31
- data/lib/ramaze/spec.rb +1 -1
- data/lib/ramaze/spec/bacon.rb +6 -3
- data/lib/ramaze/spec/helper/bacon.rb +0 -1
- data/lib/ramaze/version.rb +1 -1
- data/lib/ramaze/view.rb +2 -11
- data/lib/ramaze/view/erector.rb +46 -31
- data/lib/ramaze/view/erubis.rb +7 -3
- data/lib/ramaze/view/ezamar.rb +7 -3
- data/lib/ramaze/view/gestalt.rb +9 -3
- data/lib/ramaze/view/haml.rb +7 -3
- data/lib/ramaze/view/liquid.rb +3 -3
- data/lib/ramaze/view/lokar.rb +7 -3
- data/lib/ramaze/view/mustache.rb +11 -5
- data/lib/ramaze/view/nagoro.rb +3 -3
- data/lib/ramaze/view/sass.rb +1 -1
- data/lib/ramaze/view/slippers.rb +40 -13
- data/lib/ramaze/view/tagz.rb +9 -5
- data/ramaze.gemspec +23 -128
- data/spec/helper.rb +5 -0
- data/spec/ramaze/bin/app/config.ru +11 -0
- data/spec/ramaze/bin/create.rb +28 -0
- data/spec/ramaze/bin/runner.rb +30 -0
- data/spec/ramaze/bin/start.rb +38 -0
- data/spec/ramaze/cache/memcache.rb +10 -3
- data/spec/ramaze/cache/sequel.rb +7 -0
- data/spec/ramaze/controller/provide_inheritance.rb +0 -10
- data/spec/ramaze/dispatcher/file.rb +19 -15
- data/spec/ramaze/helper/auth.rb +10 -9
- data/spec/ramaze/helper/blue_form.rb +121 -68
- data/spec/ramaze/helper/email.rb +69 -0
- data/spec/ramaze/helper/layout.rb +12 -15
- data/spec/ramaze/helper/layout/alternative.xhtml +5 -0
- data/spec/ramaze/helper/user.rb +2 -0
- data/spec/ramaze/log/growl.rb +14 -1
- data/spec/{contrib → ramaze}/rest.rb +1 -1
- data/spec/ramaze/session/memcache.rb +2 -2
- data/spec/ramaze/view/sass.rb +1 -1
- data/tasks/bacon.rake +3 -3
- data/tasks/gem.rake +17 -18
- data/tasks/rcov.rake +2 -3
- data/tasks/release.rake +8 -65
- data/tasks/setup.rake +10 -8
- data/tasks/todo.rake +9 -5
- data/tasks/yard.rake +3 -2
- metadata +105 -397
- data/MANIFEST +0 -532
- data/TODO.md +0 -19
- data/benchmark/bench_templates/bench.rb +0 -67
- data/benchmark/bench_templates/view/large.erb +0 -79
- data/benchmark/bench_templates/view/large.haml +0 -41
- data/benchmark/bench_templates/view/large.lok +0 -79
- data/benchmark/bench_templates/view/large.xhtml +0 -79
- data/benchmark/bench_templates/view/small.erb +0 -21
- data/benchmark/bench_templates/view/small.haml +0 -12
- data/benchmark/bench_templates/view/small.lok +0 -21
- data/benchmark/bench_templates/view/small.xhtml +0 -21
- data/benchmark/results.txt +0 -131
- data/benchmark/run.rb +0 -355
- data/benchmark/suite/minimal.rb +0 -11
- data/benchmark/suite/no_informer.rb +0 -7
- data/benchmark/suite/no_sessions.rb +0 -9
- data/benchmark/suite/no_template.rb +0 -7
- data/benchmark/suite/simple.rb +0 -5
- data/benchmark/suite/template_erubis.rb +0 -8
- data/benchmark/suite/template_etanni.rb +0 -8
- data/benchmark/suite/template_ezamar.rb +0 -8
- data/benchmark/suite/template_haml.rb +0 -13
- data/benchmark/suite/template_liquid.rb +0 -11
- data/benchmark/suite/template_markaby.rb +0 -9
- data/benchmark/suite/template_nagoro.rb +0 -8
- data/benchmark/suite/template_redcloth.rb +0 -13
- data/benchmark/suite/template_tenjin.rb +0 -8
- data/benchmark/test.rb +0 -35
- data/doc/FAQ +0 -92
- data/doc/INSTALL +0 -92
- data/doc/TODO +0 -29
- data/doc/meta/announcement.txt +0 -119
- data/doc/meta/configuration.txt +0 -163
- data/doc/meta/internals.txt +0 -278
- data/doc/meta/users.kml +0 -64
- data/doc/tutorial/todolist.html +0 -1512
- data/doc/tutorial/todolist.txt +0 -920
- data/examples/app/sourceview/public/coderay.css +0 -104
- data/examples/app/sourceview/public/images/file.gif +0 -0
- data/examples/app/sourceview/public/images/folder.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item.gif +0 -0
- data/examples/app/sourceview/public/jquery.js +0 -11
- data/examples/app/sourceview/public/jquery.treeview.css +0 -48
- data/examples/app/sourceview/public/jquery.treeview.js +0 -223
- data/examples/app/sourceview/public/sourceview.js +0 -52
- data/examples/app/sourceview/start.rb +0 -79
- data/examples/app/sourceview/view/index.haml +0 -59
- data/examples/helpers/httpdigest.rb +0 -107
- data/lib/proto/public/css/screen.css +0 -30
- data/lib/proto/public/js/jquery.js +0 -7179
- data/lib/ramaze/contrib/addressable_route.rb +0 -56
- data/lib/ramaze/contrib/app_graph.rb +0 -64
- data/lib/ramaze/contrib/email.rb +0 -88
- data/lib/ramaze/contrib/facebook.rb +0 -23
- data/lib/ramaze/contrib/facebook/facebook.rb +0 -171
- data/lib/ramaze/contrib/gettext.rb +0 -113
- data/lib/ramaze/contrib/gettext/mo.rb +0 -155
- data/lib/ramaze/contrib/gettext/parser.rb +0 -46
- data/lib/ramaze/contrib/gettext/po.rb +0 -109
- data/lib/ramaze/contrib/gzip_filter.rb +0 -1
- data/lib/ramaze/contrib/maruku_uv.rb +0 -59
- data/lib/ramaze/contrib/profiling.rb +0 -36
- data/lib/ramaze/contrib/rest.rb +0 -23
- data/lib/ramaze/contrib/sequel/create_join.rb +0 -26
- data/lib/ramaze/contrib/sequel/form_field.rb +0 -129
- data/lib/ramaze/contrib/sequel/image.rb +0 -196
- data/lib/ramaze/contrib/sequel/relation.rb +0 -98
- data/lib/ramaze/helper/httpdigest.rb +0 -96
- data/lib/ramaze/tool/bin.rb +0 -340
- data/lib/ramaze/tool/create.rb +0 -48
- data/lib/ramaze/tool/project_creator.rb +0 -120
- data/lib/ramaze/view/less.rb +0 -12
- data/lib/ramaze/view/maruku.rb +0 -15
- data/lib/ramaze/view/redcloth.rb +0 -21
- data/spec/contrib/addressable_route.rb +0 -30
- data/spec/examples/helpers/httpdigest.rb +0 -64
- data/spec/examples/templates/template_redcloth.rb +0 -13
- data/spec/ramaze/bin/ramaze.rb +0 -96
- data/spec/ramaze/helper/httpdigest.rb +0 -176
- data/spec/ramaze/view/less.rb +0 -60
- data/spec/ramaze/view/less/file.css.less +0 -8
- data/spec/ramaze/view/redcloth.rb +0 -66
- data/spec/ramaze/view/redcloth/external.redcloth +0 -8
- data/tasks/copyright.rake +0 -21
- data/tasks/gem_setup.rake +0 -112
- data/tasks/git.rake +0 -46
- data/tasks/grancher.rake +0 -12
- data/tasks/jquery.rake +0 -15
- data/tasks/manifest.rake +0 -4
- data/tasks/metric_changes.rake +0 -24
- data/tasks/reversion.rake +0 -8
- data/tasks/traits.rake +0 -21
@@ -0,0 +1,206 @@
|
|
1
|
+
module Ramaze
|
2
|
+
#:nodoc:
|
3
|
+
module Bin
|
4
|
+
##
|
5
|
+
# The start command is used to start a Ramaze application. The ramaze start
|
6
|
+
# command optionally takes a directory or path to a file. If it's a
|
7
|
+
# directory this command will look for a Rackup file in that directory,
|
8
|
+
# otherwise it assumes the specified file is a Rackup file.
|
9
|
+
#
|
10
|
+
# == Usage
|
11
|
+
#
|
12
|
+
# ramaze start
|
13
|
+
# ramaze start /home/foobar/projects/blog/config.ru
|
14
|
+
# ramaze start /home/foobar/projects/blog
|
15
|
+
#
|
16
|
+
# @author Yorick Peterse
|
17
|
+
# @since 21-07-2011
|
18
|
+
#
|
19
|
+
class Start
|
20
|
+
include Ramaze::Bin::Helper
|
21
|
+
|
22
|
+
# The description of this command, displayed when the global help menu is
|
23
|
+
# invoked.
|
24
|
+
Description = 'Starts an instance of an application'
|
25
|
+
|
26
|
+
# The banner of this command, displayed when it's invoked with the -h or
|
27
|
+
# --help option.
|
28
|
+
Banner = <<-TXT.strip
|
29
|
+
Starts an instance of an application using the settings
|
30
|
+
specified in a Rackup file in the current directory.
|
31
|
+
|
32
|
+
Usage:
|
33
|
+
ramaze start [RACKUP CONFIG] [OPTIONS]
|
34
|
+
|
35
|
+
Example:
|
36
|
+
ramaze start --help
|
37
|
+
TXT
|
38
|
+
|
39
|
+
##
|
40
|
+
# Creates a new instance of the command and prepares OptionParser.
|
41
|
+
#
|
42
|
+
# @author Yorick Peterse
|
43
|
+
# @since 21-07-2011
|
44
|
+
#
|
45
|
+
def initialize
|
46
|
+
@ruby_options = {}
|
47
|
+
@rack_options = {}
|
48
|
+
@options = OptionParser.new do |opt|
|
49
|
+
opt.banner = Banner
|
50
|
+
opt.summary_indent = ' '
|
51
|
+
|
52
|
+
# Sets all Ruby options
|
53
|
+
opt.separator "\nRuby Options:\n"
|
54
|
+
|
55
|
+
opt.on('-e', '--eval LINE', 'Evaluates a line of code') do |code|
|
56
|
+
@ruby_options['-e'] = code
|
57
|
+
end
|
58
|
+
|
59
|
+
opt.on('-d', '--debug', 'Set debugging flags (set $DEBUG to true)') do
|
60
|
+
@ruby_options['-d'] = nil
|
61
|
+
end
|
62
|
+
|
63
|
+
opt.on('-w', '--warn', 'Turns warnings on for the script') do
|
64
|
+
@ruby_options['-w'] = nil
|
65
|
+
end
|
66
|
+
|
67
|
+
opt.on('-I', '--include PATH', 'specifies the $LOAD_PATH') do |path|
|
68
|
+
@ruby_options['-I'] = path
|
69
|
+
end
|
70
|
+
|
71
|
+
opt.on(
|
72
|
+
'-r',
|
73
|
+
'--require LIBRARY',
|
74
|
+
'requires the library before starting'
|
75
|
+
) do |library|
|
76
|
+
@ruby_options['-r'] = library
|
77
|
+
end
|
78
|
+
|
79
|
+
# Set all Rack options
|
80
|
+
opt.separator "\nRack Options:\n"
|
81
|
+
|
82
|
+
opt.on(
|
83
|
+
'-s',
|
84
|
+
'--server SERVER',
|
85
|
+
'Serve the application using the given server'
|
86
|
+
) do |server|
|
87
|
+
@rack_options['-s'] = server
|
88
|
+
end
|
89
|
+
|
90
|
+
opt.on(
|
91
|
+
'-o',
|
92
|
+
'--host HOST',
|
93
|
+
'Listens on the given host (0.0.0.0 by default)'
|
94
|
+
) do |host|
|
95
|
+
@rack_options['-o'] = host
|
96
|
+
end
|
97
|
+
|
98
|
+
opt.on(
|
99
|
+
'-p',
|
100
|
+
'--port PORT',
|
101
|
+
'Uses the given port, set to 9292 by default'
|
102
|
+
) do |port|
|
103
|
+
@rack_options['-p'] = port
|
104
|
+
end
|
105
|
+
|
106
|
+
opt.on(
|
107
|
+
'-O',
|
108
|
+
'--option NAME[=VALUE]',
|
109
|
+
'Passes the given option and it\'s value to the server'
|
110
|
+
) do |name|
|
111
|
+
@rack_options['-O'] = name
|
112
|
+
end
|
113
|
+
|
114
|
+
opt.on(
|
115
|
+
'-E',
|
116
|
+
'--env ENVIRONMENT',
|
117
|
+
'Uses the specified environment, set to development by default'
|
118
|
+
) do |env|
|
119
|
+
@rack_options['-E'] = env
|
120
|
+
end
|
121
|
+
|
122
|
+
opt.on('-D', '--daemonize', 'Runs as a daemon in the background') do
|
123
|
+
@rack_options['-D'] = nil
|
124
|
+
end
|
125
|
+
|
126
|
+
opt.on(
|
127
|
+
'-P',
|
128
|
+
'--pid FILE',
|
129
|
+
'File to store the PID in, defaults to rack.pid'
|
130
|
+
) do |pid|
|
131
|
+
@rack_options['-P'] = pid
|
132
|
+
end
|
133
|
+
|
134
|
+
# Set all common options
|
135
|
+
opt.separator "\nOptions\n"
|
136
|
+
|
137
|
+
opt.on('-h', '--help', 'Shows this help message') do
|
138
|
+
puts @options
|
139
|
+
exit
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
##
|
145
|
+
# Runs the command based on the given command line arguments.
|
146
|
+
#
|
147
|
+
# @author Yorick Peterse
|
148
|
+
# @since 21-07-2011
|
149
|
+
# @param [Array] argv An array of command line arguments.
|
150
|
+
#
|
151
|
+
def run(argv = [])
|
152
|
+
begin
|
153
|
+
@options.parse!(argv)
|
154
|
+
rescue => e
|
155
|
+
warn "Error: #{e.message}"
|
156
|
+
abort @options.to_s
|
157
|
+
end
|
158
|
+
|
159
|
+
# Remove all trailing/leading whitespace from the options
|
160
|
+
@rack_options.each do |k, v|
|
161
|
+
@rack_options[k] = v.strip if v.respond_to?(:strip)
|
162
|
+
end
|
163
|
+
|
164
|
+
@ruby_options.each do |k, v|
|
165
|
+
@ruby_options[k] = v.strip if v.respond_to?(:strip)
|
166
|
+
end
|
167
|
+
|
168
|
+
rackup_config = argv.delete_at(0)
|
169
|
+
rackup_config = File.join(Dir.pwd, 'config.ru') if rackup_config.nil?
|
170
|
+
|
171
|
+
# Check if the config is a directory or file
|
172
|
+
if File.directory?(rackup_config)
|
173
|
+
rackup_config = File.join(rackup_config, 'config.ru')
|
174
|
+
end
|
175
|
+
|
176
|
+
if !File.exist?(rackup_config)
|
177
|
+
abort "The Rackup config #{rackup_config} does not exist"
|
178
|
+
end
|
179
|
+
|
180
|
+
# Set the default port and server to use.
|
181
|
+
if !@rack_options['-p']
|
182
|
+
@rack_options['-p'] = 7000
|
183
|
+
end
|
184
|
+
|
185
|
+
# Set the default server to use
|
186
|
+
if !@rack_options['-s']
|
187
|
+
@rack_options['-s'] = Ramaze.options.adapter.handler.to_s
|
188
|
+
end
|
189
|
+
|
190
|
+
# If a PID is supplied we should first check to see if Ramaze isn't
|
191
|
+
# already running.
|
192
|
+
if @rack_options.key?('-P') and is_running?(@rack_options['-P'])
|
193
|
+
abort 'This application is already running'
|
194
|
+
end
|
195
|
+
|
196
|
+
params = []
|
197
|
+
|
198
|
+
@ruby_options.merge(@rack_options).each do |opt, value|
|
199
|
+
params.push("#{opt}#{value}")
|
200
|
+
end
|
201
|
+
|
202
|
+
exec('ruby', rackup_path, rackup_config, *params)
|
203
|
+
end
|
204
|
+
end # Start
|
205
|
+
end # Bin
|
206
|
+
end # Ramaze
|
@@ -0,0 +1,152 @@
|
|
1
|
+
module Ramaze
|
2
|
+
#:nodoc:
|
3
|
+
module Bin
|
4
|
+
##
|
5
|
+
# The status command can be used to show the details, such as the PID and
|
6
|
+
# the CPU usage, of a running Ramaze application.
|
7
|
+
#
|
8
|
+
# == Usage
|
9
|
+
#
|
10
|
+
# ramaze status
|
11
|
+
# ramaze status /home/projects/ramaze/ramaze.pid
|
12
|
+
#
|
13
|
+
# @author Yorick Peterse
|
14
|
+
# @author TJ Vanderpoel
|
15
|
+
# @since 21-07-2011
|
16
|
+
#
|
17
|
+
class Status
|
18
|
+
include Ramaze::Bin::Helper
|
19
|
+
|
20
|
+
# Description of this command, displayed in the glboal help message.
|
21
|
+
Description = 'Shows the status of a running Ramaze application'
|
22
|
+
|
23
|
+
# The banner of this command, displayed when the -h or --help option is
|
24
|
+
# specified.
|
25
|
+
Banner = <<-TXT.strip
|
26
|
+
Shows the status of a running Ramaze application. If a PID is specified this
|
27
|
+
command will use that PID, otherwise it will try to look for a PID in the
|
28
|
+
current directory.
|
29
|
+
|
30
|
+
Usage:
|
31
|
+
ramaze status [PID] [OPTIONS]
|
32
|
+
|
33
|
+
Example:
|
34
|
+
ramaze status blog/blog.pid
|
35
|
+
TXT
|
36
|
+
|
37
|
+
# String containing the message that's used to display all statistics
|
38
|
+
Statistics = <<-TXT.strip
|
39
|
+
Ramaze is running!
|
40
|
+
Name: %s
|
41
|
+
Command Line: %s
|
42
|
+
Virtual Size: %s
|
43
|
+
Started: %s
|
44
|
+
Exec Path: %s
|
45
|
+
Status: %s
|
46
|
+
TXT
|
47
|
+
|
48
|
+
##
|
49
|
+
# Creates a new instance of the command and sets all the option parser
|
50
|
+
# options.
|
51
|
+
#
|
52
|
+
# @author Yorick Peterse
|
53
|
+
# @since 21-07-2011
|
54
|
+
#
|
55
|
+
def initialize
|
56
|
+
@options = OptionParser.new do |opt|
|
57
|
+
opt.banner = Banner
|
58
|
+
opt.summary_indent = ' '
|
59
|
+
|
60
|
+
opt.separator "\nOptions:\n"
|
61
|
+
|
62
|
+
opt.on('-h', '--help', 'Shows this help message') do
|
63
|
+
puts @options
|
64
|
+
exit
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# Runs the command based on the given command line arguments.
|
71
|
+
#
|
72
|
+
# @author Yorick Peterse
|
73
|
+
# @author TJ Vanderpoel
|
74
|
+
# @since 21-07-2011
|
75
|
+
# @param [Array] argv Array containing all teh command line arguments.
|
76
|
+
#
|
77
|
+
def run(argv = [])
|
78
|
+
@options.parse!(argv)
|
79
|
+
|
80
|
+
pid_path = argv.delete_at(0)
|
81
|
+
dirname = Pathname.new('.').realpath.basename.to_s
|
82
|
+
pid_path = File.join(Dir.pwd, dirname + '.pid') if pid_path.nil?
|
83
|
+
|
84
|
+
# Is it a directory?
|
85
|
+
if File.directory?(pid_path)
|
86
|
+
pid_path = File.join(pid_path, File.basename(pid_path) + '.pid')
|
87
|
+
end
|
88
|
+
|
89
|
+
pid_path = Pathname.new(pid_path).expand_path.to_s
|
90
|
+
|
91
|
+
if !File.exist?(pid_path)
|
92
|
+
abort "The PID #{pid_path} does not exist"
|
93
|
+
end
|
94
|
+
|
95
|
+
# Is the app running?
|
96
|
+
unless is_running?(pid_path)
|
97
|
+
abort "The Ramaze application for #{pid_path} isn't running"
|
98
|
+
end
|
99
|
+
|
100
|
+
pid = File.read(pid_path).to_i
|
101
|
+
|
102
|
+
# Gather various statistics about the process
|
103
|
+
if is_windows?
|
104
|
+
wmi = WIN32OLE.connect("winmgmts://")
|
105
|
+
ours = []
|
106
|
+
processes = wmi.ExecQuery(
|
107
|
+
"select * from win32_process where ProcessId = #{pid}"
|
108
|
+
)
|
109
|
+
|
110
|
+
processes.each do |p|
|
111
|
+
ours << [
|
112
|
+
p.Name,
|
113
|
+
p.CommandLine,
|
114
|
+
p.VirtualSize,
|
115
|
+
p.CreationDate,
|
116
|
+
p.ExecutablePath,
|
117
|
+
p.Status
|
118
|
+
]
|
119
|
+
end
|
120
|
+
|
121
|
+
puts Statistics % ours.first
|
122
|
+
# Unix like systems
|
123
|
+
else
|
124
|
+
if File.directory?(proc_dir = Pathname.new('/proc'))
|
125
|
+
proc_dir = proc_dir.join(pid.to_s)
|
126
|
+
# If we have a "stat" file, we'll assume linux and get as much info
|
127
|
+
# as we can
|
128
|
+
if File.file?(stat_file = proc_dir.join("stat"))
|
129
|
+
stats = File.read(stat_file).split
|
130
|
+
|
131
|
+
puts Statistics % [
|
132
|
+
nil,
|
133
|
+
File.read(proc_dir.join("cmdline")).split("\000").join(" "),
|
134
|
+
"%s k" % (stats[22].to_f / 1024),
|
135
|
+
File.mtime(proc_dir),
|
136
|
+
File.readlink(proc_dir.join("exe")),
|
137
|
+
stats[2]
|
138
|
+
]
|
139
|
+
end
|
140
|
+
# /proc does not exist, use "ps"
|
141
|
+
else
|
142
|
+
begin
|
143
|
+
puts %x{ps l #{pid}}
|
144
|
+
rescue
|
145
|
+
puts "Sadly no more information is available"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end # Status
|
151
|
+
end # Bin
|
152
|
+
end # Ramaze
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module Ramaze
|
2
|
+
#:nodoc:
|
3
|
+
module Bin
|
4
|
+
##
|
5
|
+
# Stops a running instance of Ramaze by killing it's process. The PID of
|
6
|
+
# this process can be supplied via the command line. If no PID is given this
|
7
|
+
# command tries to find it in the current directory. If the latter is the
|
8
|
+
# case this command tries to find a file of which the name matches the name
|
9
|
+
# of the current directory.
|
10
|
+
#
|
11
|
+
# == Usage
|
12
|
+
#
|
13
|
+
# ramaze stop
|
14
|
+
# ramaze stop /home/foobar/projects/ramaze/ramaze.pid
|
15
|
+
#
|
16
|
+
# @author Yorick Peterse
|
17
|
+
# @author TJ Vanderpoel
|
18
|
+
# @since 21-07-2011
|
19
|
+
#
|
20
|
+
class Stop
|
21
|
+
include Ramaze::Bin::Helper
|
22
|
+
|
23
|
+
# The description of this command, shown when the global help menu is
|
24
|
+
# displayed.
|
25
|
+
Description = 'Stops a running instance of Ramaze'
|
26
|
+
|
27
|
+
# The banner of this command.
|
28
|
+
Banner = <<-TXT.strip
|
29
|
+
Stops a running instance of Ramaze by killing it's process using a PID. If no
|
30
|
+
PID is given this command tries to look for it in the current directory.
|
31
|
+
|
32
|
+
Usage:
|
33
|
+
ramaze stop [PID] [OPTIONS]
|
34
|
+
|
35
|
+
Example:
|
36
|
+
ramaze stop /home/foobar/projects/ramaze/ramaze.pid
|
37
|
+
TXT
|
38
|
+
|
39
|
+
##
|
40
|
+
# Creates a new instance of the command and sets all the OptionParser
|
41
|
+
# options.
|
42
|
+
#
|
43
|
+
# @author Yorick Peterse
|
44
|
+
# @since 21-07-2011
|
45
|
+
#
|
46
|
+
def initialize
|
47
|
+
@options = OptionParser.new do |opt|
|
48
|
+
opt.banner = Banner
|
49
|
+
opt.summary_indent = ' '
|
50
|
+
|
51
|
+
opt.separator "\nOptions:\n"
|
52
|
+
|
53
|
+
opt.on('-h', '--help', 'Shows this help message') do
|
54
|
+
puts @options
|
55
|
+
exit
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# Runs the command based on the specified command line arguments.
|
62
|
+
#
|
63
|
+
# @author Yorick Peterse
|
64
|
+
# @author TJ Vanderpoel
|
65
|
+
# @since 21-07-2011
|
66
|
+
# @param [Array] argv Array containing all the command line arguments.
|
67
|
+
#
|
68
|
+
def run(argv = [])
|
69
|
+
@options.parse!(argv)
|
70
|
+
|
71
|
+
pid_path = argv.delete_at(0)
|
72
|
+
dirname = Pathname.new('.').expand_path.basename.to_s
|
73
|
+
pid_path = File.join(Dir.pwd, dirname + '.pid') if pid_path.nil?
|
74
|
+
|
75
|
+
if File.directory?(pid_path)
|
76
|
+
pid_path = File.join(pid_path, File.basename(pid_path) + '.pid')
|
77
|
+
end
|
78
|
+
|
79
|
+
pid_path = Pathname.new(pid_path).expand_path.to_s
|
80
|
+
|
81
|
+
if !File.exist?(pid_path)
|
82
|
+
abort "The PID #{pid_path} does not exist"
|
83
|
+
end
|
84
|
+
|
85
|
+
pid = File.read(pid_path).to_i
|
86
|
+
puts 'Stopping the process using SIGINT'
|
87
|
+
|
88
|
+
begin
|
89
|
+
Process.kill('INT', pid)
|
90
|
+
rescue => e
|
91
|
+
abort "Failed to kill the process: #{e.message}"
|
92
|
+
end
|
93
|
+
|
94
|
+
sleep(2)
|
95
|
+
|
96
|
+
# Verify that the process has been killed
|
97
|
+
if is_running?(pid_path)
|
98
|
+
$stderr.puts "The process is still running, let's kill it with -9"
|
99
|
+
|
100
|
+
begin
|
101
|
+
Process.kill(9, pid)
|
102
|
+
rescue => e
|
103
|
+
abort "Failed to kill the process: #{e.message}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
File.unlink(pid_path) if File.exist?(pid_path)
|
108
|
+
puts 'Ramazement has ended, go in peace.'
|
109
|
+
end
|
110
|
+
end # Stop
|
111
|
+
end # Bin
|
112
|
+
end # Ramaze
|