nitro 0.31.0 → 0.40.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/nitro +135 -37
- data/doc/CHANGELOG.1 +108 -108
- data/doc/CHANGELOG.2 +89 -89
- data/doc/CHANGELOG.3 +105 -105
- data/{CHANGELOG → doc/CHANGELOG.4} +509 -509
- data/doc/{AUTHORS → CONTRIBUTORS} +49 -37
- data/doc/LIBRARIES +13 -0
- data/doc/LICENSE +2 -3
- data/doc/MIGRATION +45 -0
- data/doc/RELEASES +131 -11
- data/doc/TODO +67 -0
- data/lib/glue/magick.rb +0 -3
- data/lib/glue/sweeper.rb +30 -15
- data/lib/glue/thumbnails.rb +0 -2
- data/lib/glue/webfile.rb +23 -11
- data/lib/nitro.rb +37 -44
- data/lib/nitro/adapter/cgi.rb +0 -3
- data/lib/nitro/adapter/console.rb +0 -2
- data/lib/nitro/adapter/fastcgi.rb +6 -3
- data/lib/nitro/adapter/mongrel.rb +97 -58
- data/lib/nitro/adapter/script.rb +4 -6
- data/lib/nitro/adapter/webrick.rb +33 -87
- data/lib/nitro/adapter/webrick/vcr.rb +85 -0
- data/lib/nitro/caching.rb +0 -2
- data/lib/nitro/caching/actions.rb +0 -2
- data/lib/nitro/caching/fragments.rb +0 -2
- data/lib/nitro/caching/output.rb +45 -16
- data/lib/nitro/caching/proxy.rb +49 -0
- data/lib/nitro/cgi.rb +3 -6
- data/lib/nitro/cgi/cookie.rb +0 -3
- data/lib/nitro/cgi/request.rb +67 -24
- data/lib/nitro/cgi/response.rb +0 -2
- data/lib/nitro/cgi/{sendfile.rb → send_file.rb} +7 -6
- data/lib/nitro/compiler.rb +62 -55
- data/lib/nitro/compiler/cleanup.rb +0 -3
- data/lib/nitro/compiler/elements.rb +31 -28
- data/lib/nitro/compiler/errors.rb +2 -5
- data/lib/nitro/compiler/include.rb +10 -8
- data/lib/nitro/compiler/layout.rb +0 -2
- data/lib/nitro/compiler/localization.rb +0 -2
- data/lib/nitro/compiler/markup.rb +14 -6
- data/lib/nitro/compiler/morphing.rb +1 -5
- data/lib/nitro/compiler/script.rb +2 -4
- data/lib/nitro/compiler/squeeze.rb +0 -2
- data/lib/nitro/compiler/xslt.rb +0 -2
- data/lib/nitro/context.rb +10 -5
- data/lib/nitro/control.rb +18 -0
- data/lib/nitro/control/attribute.rb +88 -0
- data/lib/nitro/control/attribute/checkbox.rb +19 -0
- data/lib/nitro/control/attribute/datetime.rb +21 -0
- data/lib/nitro/control/attribute/file.rb +20 -0
- data/lib/nitro/control/attribute/fixnum.rb +26 -0
- data/lib/nitro/control/attribute/float.rb +26 -0
- data/lib/nitro/control/attribute/options.rb +38 -0
- data/lib/nitro/control/attribute/password.rb +16 -0
- data/lib/nitro/control/attribute/text.rb +16 -0
- data/lib/nitro/control/attribute/textarea.rb +16 -0
- data/lib/nitro/control/none.rb +16 -0
- data/lib/nitro/control/relation.rb +53 -0
- data/lib/nitro/control/relation/belongs_to.rb +0 -0
- data/lib/nitro/control/relation/has_many.rb +97 -0
- data/lib/nitro/control/relation/joins_many.rb +0 -0
- data/lib/nitro/control/relation/many_to_many.rb +0 -0
- data/lib/nitro/control/relation/refers_to.rb +29 -0
- data/lib/nitro/controller.rb +7 -296
- data/lib/nitro/dispatcher.rb +72 -34
- data/lib/nitro/element.rb +36 -10
- data/lib/nitro/element/javascript.rb +0 -2
- data/lib/nitro/flash.rb +23 -10
- data/lib/nitro/global.rb +36 -11
- data/lib/nitro/helper.rb +22 -8
- data/lib/nitro/helper/benchmark.rb +0 -2
- data/lib/nitro/helper/buffer.rb +0 -3
- data/lib/nitro/helper/css.rb +12 -0
- data/lib/nitro/helper/debug.rb +1 -3
- data/lib/nitro/helper/default.rb +1 -0
- data/lib/nitro/helper/feed.rb +400 -386
- data/lib/nitro/helper/form.rb +246 -116
- data/lib/nitro/helper/javascript.rb +28 -2
- data/lib/nitro/helper/javascript/morphing.rb +0 -2
- data/lib/nitro/helper/javascript/prototype.rb +0 -2
- data/lib/nitro/helper/javascript/scriptaculous.rb +0 -1
- data/lib/nitro/helper/layout.rb +0 -2
- data/lib/nitro/helper/navigation.rb +87 -0
- data/lib/nitro/helper/pager.rb +11 -22
- data/lib/nitro/helper/table.rb +9 -32
- data/lib/nitro/helper/url.rb +104 -0
- data/lib/nitro/helper/xhtml.rb +20 -4
- data/lib/nitro/helper/xml.rb +0 -2
- data/lib/nitro/markup.rb +131 -0
- data/lib/nitro/part.rb +52 -7
- data/lib/nitro/publishable.rb +328 -0
- data/lib/nitro/render.rb +30 -61
- data/lib/nitro/router.rb +12 -4
- data/lib/nitro/sanitize.rb +48 -0
- data/lib/nitro/scaffold.rb +9 -11
- data/lib/nitro/scaffold/controller.rb +25 -0
- data/lib/nitro/scaffold/model.rb +150 -0
- data/lib/nitro/scaffolding.rb +1 -3
- data/lib/nitro/server.rb +57 -32
- data/lib/nitro/server/drb.rb +16 -2
- data/lib/nitro/server/runner.rb +80 -102
- data/lib/nitro/service.rb +0 -1
- data/lib/nitro/service/xmlrpc.rb +0 -2
- data/lib/nitro/session.rb +26 -18
- data/lib/nitro/session/drb.rb +2 -16
- data/lib/nitro/session/memory.rb +0 -2
- data/lib/nitro/template.rb +219 -0
- data/lib/nitro/test/assertions.rb +1 -3
- data/lib/nitro/test/context.rb +0 -1
- data/lib/nitro/test/testcase.rb +0 -1
- data/lib/nitro/version.rb +6 -0
- data/lib/part/admin.rb +16 -0
- data/lib/part/admin/controller.rb +19 -0
- data/lib/part/admin/helper.rb +30 -0
- data/lib/part/admin/og/controller.rb +114 -0
- data/lib/part/admin/og/customize.rb +4 -0
- data/lib/part/admin/og/template/index.xhtml +27 -0
- data/lib/part/admin/og/template/list.xhtml +38 -0
- data/lib/part/admin/og/template/search.xhtml +20 -0
- data/lib/part/admin/og/template/update.xhtml +25 -0
- data/lib/part/admin/skin.rb +207 -0
- data/lib/part/admin/template/denied.xhtml +13 -0
- data/lib/part/admin/template/index.xhtml +12 -0
- data/lib/part/admin/todo.txt +2 -0
- data/proto/public/error.xhtml +4 -2
- data/proto/run.rb +0 -2
- data/test/glue/tc_webfile.rb +1 -0
- data/test/nitro/cgi/tc_request.rb +23 -0
- data/test/nitro/helper/tc_feed.rb +0 -3
- data/test/nitro/helper/tc_navbar.rb +74 -0
- data/test/nitro/helper/tc_table.rb +2 -0
- data/test/nitro/tc_cgi.rb +72 -19
- data/test/nitro/tc_controller.rb +35 -26
- data/test/nitro/tc_controller_aspect.rb +1 -0
- data/test/nitro/tc_controller_params.rb +864 -0
- data/test/nitro/tc_dispatcher.rb +2 -2
- data/test/nitro/tc_element.rb +16 -16
- data/test/nitro/tc_flash.rb +3 -3
- data/test/nitro/tc_markup.rb +31 -0
- data/test/nitro/tc_render.rb +12 -14
- data/test/nitro/tc_session.rb +9 -7
- data/test/nitro/tc_template.rb +34 -0
- metadata +217 -198
- data/INSTALL +0 -121
- data/ProjectInfo +0 -74
- data/README +0 -555
- data/doc/apache.txt +0 -9
- data/doc/config.txt +0 -28
- data/doc/faq.txt +0 -7
- data/doc/lhttpd.txt +0 -7
- data/lib/nitro/adapter/scgi.rb +0 -239
- data/lib/nitro/helper/form/builder.rb +0 -144
- data/lib/nitro/helper/form/controls.rb +0 -389
- data/lib/nitro/helper/rss.rb +0 -72
- data/proto/conf/apache.conf +0 -51
- data/proto/public/scaffold/advanced_search.xhtml +0 -30
- data/proto/public/scaffold/edit.xhtml +0 -11
- data/proto/public/scaffold/form.xhtml +0 -1
- data/proto/public/scaffold/index.xhtml +0 -20
- data/proto/public/scaffold/list.xhtml +0 -32
- data/proto/public/scaffold/new.xhtml +0 -11
- data/proto/public/scaffold/search.xhtml +0 -29
- data/proto/public/scaffold/view.xhtml +0 -8
- data/proto/script/scgi_ctl +0 -221
- data/proto/script/scgi_service +0 -128
- data/setup.rb +0 -1585
- data/src/part/admin.rb +0 -16
- data/src/part/admin/controller.rb +0 -81
- data/src/part/admin/skin.rb +0 -21
- data/src/part/admin/system.css +0 -135
- data/src/part/admin/template/denied.xhtml +0 -1
- data/src/part/admin/template/index.xhtml +0 -43
- data/test/nitro/helper/tc_rss.rb +0 -24
data/lib/nitro/helper/rss.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'cgi'
|
2
|
-
require 'rss/0.9'
|
3
|
-
|
4
|
-
require 'facet/string/first_char'
|
5
|
-
|
6
|
-
require 'glue/markup'
|
7
|
-
|
8
|
-
module Nitro
|
9
|
-
|
10
|
-
# Build RSS represenations of ruby object collections.
|
11
|
-
# Utilize duck typing to grab the attributes to render.
|
12
|
-
# Add this mixin to you classes to support RSS rendering.
|
13
|
-
#
|
14
|
-
#--
|
15
|
-
# TODO: add more options here, 1.0/2.0 support and more.
|
16
|
-
# use custom version to add headers like the following.
|
17
|
-
# <?xml version="1.0" encoding="UTF-8"?>
|
18
|
-
# <?xml-stylesheet href="rss.css" type="text/css"?>
|
19
|
-
#++
|
20
|
-
|
21
|
-
module RssHelper
|
22
|
-
include Glue::Markup
|
23
|
-
|
24
|
-
# === Options
|
25
|
-
#
|
26
|
-
# [+:description+]
|
27
|
-
# Description of the Feed
|
28
|
-
# [+:base+]
|
29
|
-
# Base url of the Feed.
|
30
|
-
# [+:link+]
|
31
|
-
# Link of the Feed.
|
32
|
-
|
33
|
-
def build_rss_09(objects, options = {})
|
34
|
-
c = {
|
35
|
-
:title => 'Syndication',
|
36
|
-
:description => 'Syndication'
|
37
|
-
}.update(options)
|
38
|
-
|
39
|
-
c[:base] ||= c[:link]
|
40
|
-
|
41
|
-
raise "Option ':base' cannot be infered!" unless c[:base]
|
42
|
-
|
43
|
-
channel = RSS::Rss::Channel.new
|
44
|
-
channel.title = c[:title]
|
45
|
-
channel.description = c[:description]
|
46
|
-
channel.link = c[:link] if c[:link]
|
47
|
-
|
48
|
-
for obj in objects
|
49
|
-
item = RSS::Rss::Channel::Item.new
|
50
|
-
item.title = obj.title if obj.respond_to?(:title)
|
51
|
-
if obj.respond_to? :body and body = obj.body
|
52
|
-
item.description = markup(body.first_char(256))
|
53
|
-
end
|
54
|
-
if obj.respond_to? :to_href
|
55
|
-
item.link = "#{c[:base]}/#{obj.to_href}"
|
56
|
-
end
|
57
|
-
channel.items << item
|
58
|
-
end
|
59
|
-
|
60
|
-
rss = RSS::Rss.new '0.9'
|
61
|
-
rss.channel = channel
|
62
|
-
|
63
|
-
return rss.to_s
|
64
|
-
end
|
65
|
-
alias_method :build_rss, :build_rss_09
|
66
|
-
alias_method :rss, :build_rss_09
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
# * George Moschovitis <gm@navel.gr>
|
data/proto/conf/apache.conf
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# Apache Configuration
|
2
|
-
# Change as needed for your system.
|
3
|
-
|
4
|
-
Listen 9999
|
5
|
-
|
6
|
-
PidFile /var/tmp/httpd.pid
|
7
|
-
TypesConfig /etc/mime.types
|
8
|
-
DocumentRoot /home/gmosx/navel/nitro/examples/blog/public
|
9
|
-
|
10
|
-
# The error log.
|
11
|
-
|
12
|
-
ErrorLog log/apache.error_log
|
13
|
-
CustomLog log/access_log combined
|
14
|
-
|
15
|
-
# Load dynamic modules.
|
16
|
-
|
17
|
-
LoadModule fastcgi_module /usr/local/apache2/modules/mod_fastcgi.so
|
18
|
-
# LoadModule rewrite_module /usr/local/apache2/modules/mod_rewrite.so
|
19
|
-
|
20
|
-
FastCgiIpcDir /var/tmp/fcgi
|
21
|
-
# gmosx: if you have installed the gems
|
22
|
-
# distribution the -I is not needed.
|
23
|
-
FastCgiConfig -initial-env 'RUBYOPT=-rubygems -I/home/gmosx/navel/nitro/lib -I/home/gmosx/navel/og/lib -I/home/gmosx/navel/glue/lib'
|
24
|
-
|
25
|
-
|
26
|
-
AddHandler fastcgi-script fcgi rb
|
27
|
-
AddHandler cgi-script cgi rb
|
28
|
-
Options +FollowSymLinks +ExecCGI
|
29
|
-
|
30
|
-
# Redirect all requests not available on the filesystem
|
31
|
-
# to Nitro. By default the cgi dispatcher is used which
|
32
|
-
# is very slow. For better performance replace the
|
33
|
-
# dispatcher with the fastcgi one
|
34
|
-
#
|
35
|
-
# Example:
|
36
|
-
# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
|
37
|
-
|
38
|
-
RewriteEngine On
|
39
|
-
RewriteRule ^$ index.html [QSA]
|
40
|
-
RewriteRule ^([^.]+)$ $1.html [QSA]
|
41
|
-
RewriteCond %{REQUEST_FILENAME} !-f
|
42
|
-
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
|
43
|
-
|
44
|
-
# In case Nitro experiences terminal errors.
|
45
|
-
# Instead of displaying this message you can supply a
|
46
|
-
# file here which will be rendered instead.
|
47
|
-
#
|
48
|
-
# Example:
|
49
|
-
# ErrorDocument 500 /500.html
|
50
|
-
|
51
|
-
ErrorDocument 500 "<h2>Application error</h2>Nitro failed to start properly"
|
@@ -1,30 +0,0 @@
|
|
1
|
-
<SystemPage>
|
2
|
-
<?r base = "#{@base}/%base%" ?>
|
3
|
-
<h1><a href="/"> Home</a> > <a href="#@base">System</a> > <a href="#{base}/list">#{"%plural%".humanize}</a> > Advanced Search</h1>
|
4
|
-
<p>
|
5
|
-
<form action="#{base}/search">
|
6
|
-
Search #{"%plural%".humanize}: <input type="text" name="q" /> <input type="submit" value="Search" />
|
7
|
-
<a href="#{base}/advanced_search">Advanced search</a>
|
8
|
-
</form>
|
9
|
-
</p>
|
10
|
-
<?r if @list.nil? ?>
|
11
|
-
<h3>Enter properties for advanced search:</h3>
|
12
|
-
#{form_for %klass%.new, :submit => 'Search', :action => :self, :no_relations => true}
|
13
|
-
<?r else ?>
|
14
|
-
<table>
|
15
|
-
<?r for obj in @list ?>
|
16
|
-
<tr>
|
17
|
-
<td width="100%"><a href="#{base}/edit/#{obj.oid}">#(obj.to_s)</a></td>
|
18
|
-
<?r if obj.respond_to?(:update_time) ?>
|
19
|
-
<td nowrap="1">#{obj.update_time.stamp(:db)}</td>
|
20
|
-
<?r end ?>
|
21
|
-
<td><a href="#{base}/edit/#{obj.oid}">edit</a></td>
|
22
|
-
<td><a href="#{base}/delete/#{obj.oid}">del</a></td>
|
23
|
-
</tr>
|
24
|
-
<?r end ?>
|
25
|
-
</table>
|
26
|
-
<div class="pager" if="@pager and @pager.navigation?">
|
27
|
-
#{@pager.navigation}
|
28
|
-
</div>
|
29
|
-
<?r end ?>
|
30
|
-
</SystemPage>
|
@@ -1,11 +0,0 @@
|
|
1
|
-
<SystemPage>
|
2
|
-
<?r base = "#{@base}/%base%" ?>
|
3
|
-
<h1><a href="/"> Home</a> > <a href="#@base">System</a> > <a href="#{base}/list">#{"%plural%".humanize}</a> > Edit #{"%name%".humanize} </h1>
|
4
|
-
<?r if @all ?>
|
5
|
-
<a href="#{request.uri.gsub(/\/all$/, '')}">Show editable</a>
|
6
|
-
#{form_for @obj, :action => "#{base}/save", :cancel => "#{base}/list", :all => true}
|
7
|
-
<?r else ?>
|
8
|
-
<a href="#{request.uri}/all">Show all</a>
|
9
|
-
#{form_for @obj, :action => "#{base}/save", :cancel => "#{base}/list"}
|
10
|
-
<?r end ?>
|
11
|
-
</SystemPage>
|
@@ -1 +0,0 @@
|
|
1
|
-
#{form_for(@%name%)}
|
@@ -1,20 +0,0 @@
|
|
1
|
-
<SystemPage>
|
2
|
-
<?r base = "#{@base}/%base%" ?>
|
3
|
-
<h1>#{"%plural%".humanize}</h1>
|
4
|
-
<h2><a href="#{base}/new">New #{"%name%".humanize}</a></h2>
|
5
|
-
<form action="search">
|
6
|
-
Search #{"%plural%".humanize}: <input type="text" name="q" /> <input type="submit" value="Search" />
|
7
|
-
</form>
|
8
|
-
<table>
|
9
|
-
<?r for obj in @list ?>
|
10
|
-
<tr>
|
11
|
-
<td width="100%"><a href="#{base}/edit/#{obj.oid}">#{obj.to_s}</a></td>
|
12
|
-
<?r if obj.respond_to?(:update_time) ?>
|
13
|
-
<td nowrap="1">#{obj.update_time.stamp(:db)}</td>
|
14
|
-
<?r end ?>
|
15
|
-
<td><a href="#{base}/edit/#{obj.oid}">edit</a></td>
|
16
|
-
<td><a href="#{base}/delete/#{obj.oid}">del</a></td>
|
17
|
-
</tr>
|
18
|
-
<?r end ?>
|
19
|
-
</table>
|
20
|
-
</SystemPage>
|
@@ -1,32 +0,0 @@
|
|
1
|
-
<SystemPage>
|
2
|
-
<?r base = "#{@base}/%base%" ?>
|
3
|
-
<h1><a href="/"> Home</a> > <a href="#@base">System</a> > #{"%plural%".humanize}</h1>
|
4
|
-
<a href="#{base}/new">New #{"%name%".humanize}</a>
|
5
|
-
<p>
|
6
|
-
<form action="#{base}/search">
|
7
|
-
Search #{"%plural%".humanize}: <input type="text" name="q" /> <input type="submit" value="Search" />
|
8
|
-
<a href="#{base}/advanced_search">Advanced search</a>
|
9
|
-
</form>
|
10
|
-
</p>
|
11
|
-
<table>
|
12
|
-
<?r for obj in @list ?>
|
13
|
-
<tr>
|
14
|
-
<td width="100%"><a href="#{base}/edit/#{obj.oid}">#(obj.to_s)</a></td>
|
15
|
-
<?r if obj.respond_to?(:update_time) ?>
|
16
|
-
<td nowrap="1">#{obj.update_time.stamp(:db)}</td>
|
17
|
-
<?r end ?>
|
18
|
-
<?r if Glue.const_defined?(:Orderable) and @klass.include?(Glue::Orderable) ?>
|
19
|
-
<td><a href="#">Top</a></td>
|
20
|
-
<td><a href="#">Up</a></td>
|
21
|
-
<td><a href="#">Down</a></td>
|
22
|
-
<td><a href="#">Bottom</a></td>
|
23
|
-
<?r end ?>
|
24
|
-
<td><a href="#{base}/edit/#{obj.oid}">edit</a></td>
|
25
|
-
<td><a href="#{base}/delete/#{obj.oid}" onclick="confirm('Are you sure?')">del</a></td>
|
26
|
-
</tr>
|
27
|
-
<?r end ?>
|
28
|
-
</table>
|
29
|
-
<div class="pager" if="@pager and @pager.navigation?">
|
30
|
-
#{@pager.navigation}
|
31
|
-
</div>
|
32
|
-
</SystemPage>
|
@@ -1,11 +0,0 @@
|
|
1
|
-
<SystemPage>
|
2
|
-
<?r base = "#{@base}/%base%" ?>
|
3
|
-
<h1><a href="/"> Home</a> > <a href="#@base">System</a> > <a href="#{base}/list">#{"%plural%".humanize}</a> > New #{"%name%".humanize}</h1>
|
4
|
-
<?r if @all ?>
|
5
|
-
<a href="#{request.uri.gsub(/\/all$/, '')}">Show editable</a>
|
6
|
-
#{form_for @obj, :action => "#{base}/save", :cancel => "#{base}/list", :all => true, :enctype => "multipart/form-data"}
|
7
|
-
<?r else ?>
|
8
|
-
<a href="#{request.uri}/all">Show all</a>
|
9
|
-
#{form_for @obj, :action => "#{base}/save", :cancel => "#{base}/list", :enctype => "multipart/form-data"}
|
10
|
-
<?r end ?>
|
11
|
-
</SystemPage>
|
@@ -1,29 +0,0 @@
|
|
1
|
-
<SystemPage>
|
2
|
-
<?r base = "#{@base}/%base%" ?>
|
3
|
-
<h1><a href="/"> Home</a> > <a href="#@base">System</a> > <a href="#{base}/list">#{"%plural%".humanize}</a> > Search for '#@query'</h1>
|
4
|
-
<p>
|
5
|
-
<form action="#{base}/search">
|
6
|
-
Search #{"%plural%".humanize}: <input type="text" name="q" /> <input type="submit" value="Search" />
|
7
|
-
<a href="#{base}/advanced_search">Advanced search</a>
|
8
|
-
</form>
|
9
|
-
</p>
|
10
|
-
<?r if @list.nil? ?>
|
11
|
-
<p>Search method is not implemented for this object</p>
|
12
|
-
<?r else ?>
|
13
|
-
<table>
|
14
|
-
<?r for obj in @list ?>
|
15
|
-
<tr>
|
16
|
-
<td width="100%"><a href="#{base}/edit/#{obj.oid}">#(obj.to_s)</a></td>
|
17
|
-
<?r if obj.respond_to?(:update_time) ?>
|
18
|
-
<td nowrap="1">#{obj.update_time.stamp(:db)}</td>
|
19
|
-
<?r end ?>
|
20
|
-
<td><a href="#{base}/edit/#{obj.oid}">edit</a></td>
|
21
|
-
<td><a href="#{base}/delete/#{obj.oid}">del</a></td>
|
22
|
-
</tr>
|
23
|
-
<?r end ?>
|
24
|
-
</table>
|
25
|
-
<div class="pager" if="@pager and @pager.navigation?">
|
26
|
-
#{@pager.navigation}
|
27
|
-
</div>
|
28
|
-
<?r end ?>
|
29
|
-
</SystemPage>
|
data/proto/script/scgi_ctl
DELETED
@@ -1,221 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'drb'
|
3
|
-
require 'rubygems'
|
4
|
-
require 'cmdparse'
|
5
|
-
require 'yaml'
|
6
|
-
require 'highline'
|
7
|
-
|
8
|
-
UI = HighLine.new
|
9
|
-
DEFAULT_CONFIG = "conf/scgi.yaml"
|
10
|
-
|
11
|
-
def safe(error)
|
12
|
-
begin
|
13
|
-
yield
|
14
|
-
rescue Object
|
15
|
-
STDERR.puts("ERROR: #{error}: #$!")
|
16
|
-
exit 1
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def load_config(file)
|
21
|
-
safe("Could not load config") do
|
22
|
-
return YAML.load_file(file)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def connect(url)
|
27
|
-
conn = nil
|
28
|
-
safe("Can't connect to #{url}") do
|
29
|
-
conn = DRbObject.new(nil, url)
|
30
|
-
end
|
31
|
-
|
32
|
-
safe("Failed communicating with #{url}") do
|
33
|
-
yield conn
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def deduce_url(settings)
|
38
|
-
settings[:control_url] || load_config(settings[:config] || DEFAULT_CONFIG)[:control_url]
|
39
|
-
end
|
40
|
-
|
41
|
-
def defaults(settings)
|
42
|
-
defaults = nil
|
43
|
-
if settings[:merge]
|
44
|
-
UI.say("Merging with previous settings.")
|
45
|
-
defaults = load_config(settings[:config] || DEFAULT_CONFIG)
|
46
|
-
else
|
47
|
-
defaults = {
|
48
|
-
:env => "production",
|
49
|
-
:host => "127.0.0.1",
|
50
|
-
:port => 9999,
|
51
|
-
:logfile => "log/scgi.log",
|
52
|
-
:config => DEFAULT_CONFIG }
|
53
|
-
end
|
54
|
-
|
55
|
-
settings = defaults.merge(settings)
|
56
|
-
# fix up the stuff that's not quite right yet
|
57
|
-
settings[:control_url] = "druby://127.0.0.1:#{settings[:port]-1000}"
|
58
|
-
settings[:port] = settings[:port].to_i
|
59
|
-
settings[:throttle] = settings[:throttle].to_i if settings[:throttle]
|
60
|
-
settings[:maxconns] = settings[:maxconns].to_i if settings[:maxconns]
|
61
|
-
|
62
|
-
return settings
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
def configure(settings)
|
67
|
-
settings = defaults(settings)
|
68
|
-
|
69
|
-
pass = settings[:password] || UI.ask("What password do you want? ")
|
70
|
-
salting = ('a' .. 'z').to_a + ('A' .. 'Z').to_a + ('0' .. '9').to_a
|
71
|
-
settings[:password] = pass.crypt(salting[rand(salting.length)] + salting[rand(salting.length)])
|
72
|
-
|
73
|
-
# great, they are not idiots. Well, they can read --help at least.
|
74
|
-
safe("Could not write config") do
|
75
|
-
open(settings[:config],"w") {|f| f.write(YAML.dump(settings)) }
|
76
|
-
UI.say("Configuration settings written to #{settings[:config]}")
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def password
|
81
|
-
if not $password
|
82
|
-
$password = UI.ask("Password: ")
|
83
|
-
end
|
84
|
-
$password
|
85
|
-
end
|
86
|
-
|
87
|
-
def start(cmd, config)
|
88
|
-
fork do
|
89
|
-
exec cmd, config
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def status(url)
|
94
|
-
connect(url) do |conn|
|
95
|
-
s = conn.status(password)
|
96
|
-
times = s[:systimes]
|
97
|
-
|
98
|
-
puts <<-END
|
99
|
-
#{UI.color("Status as of #{s[:time]}:",:green,:bold)}
|
100
|
-
PID: #{s[:pid]}\tStarted: #{s[:started]}\tEnvironment: #{s[:env]}
|
101
|
-
Connected Requests: #{s[:conns]}
|
102
|
-
Conns/Second: #{s[:conns_second] || "Not Set"}
|
103
|
-
Max Simultaneous Conns: #{s[:max_conns]}
|
104
|
-
Shutdown Started: #{s[:shutdown]}
|
105
|
-
Processing Time: #{times.utime} #{times.stime} #{times.cutime} #{times.cstime}
|
106
|
-
Current Settings:
|
107
|
-
#{s[:settings].to_yaml.gsub(/:([a-z])/, ' \1')}
|
108
|
-
END
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def reconfigure(url)
|
113
|
-
connect(url) do |conn|
|
114
|
-
conn.reconfigure(password)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def stop(url, force)
|
119
|
-
connect(url) do |conn|
|
120
|
-
conn.shutdown(password, force)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def restart(url, force)
|
125
|
-
connect(url) do |conn|
|
126
|
-
conn.restart(password, force)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def monitor(url)
|
131
|
-
connect(url) do |conn|
|
132
|
-
while true
|
133
|
-
sleep 3
|
134
|
-
puts "\e[2J"
|
135
|
-
status(url)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
|
141
|
-
def make_command(parent, name, desc, options)
|
142
|
-
cmd = CmdParse::Command.new(name, false )
|
143
|
-
cmd.short_desc = desc
|
144
|
-
settings = {}
|
145
|
-
cmd.options = CmdParse::OptionParserWrapper.new do |opt|
|
146
|
-
options.each do |short, long, info, symbol|
|
147
|
-
opt.on(short, long, info) {|val| settings[symbol] = val}
|
148
|
-
end
|
149
|
-
end
|
150
|
-
cmd.set_execution_block do |args|
|
151
|
-
yield(settings, args)
|
152
|
-
end
|
153
|
-
parent.add_command(cmd)
|
154
|
-
end
|
155
|
-
|
156
|
-
|
157
|
-
cmd = CmdParse::CommandParser.new( true )
|
158
|
-
cmd.program_name = "scgi_nitro"
|
159
|
-
cmd.program_version = [0, 4, 0]
|
160
|
-
cmd.options = CmdParse::OptionParserWrapper.new do |opt|
|
161
|
-
opt.separator "Global options:"
|
162
|
-
opt.on("--verbose", "Be verbose when outputting info") {|t| $verbose = true }
|
163
|
-
end
|
164
|
-
|
165
|
-
cmd.add_command( CmdParse::HelpCommand.new )
|
166
|
-
cmd.add_command( CmdParse::VersionCommand.new )
|
167
|
-
|
168
|
-
make_command(cmd, 'config', "Configure the SCGI servers",
|
169
|
-
[['-e','--env STRING','Nitro environment', :env],
|
170
|
-
['-h','--host STRING', 'IP address to bind as server', :host],
|
171
|
-
['-p','--port NUMBER', 'Port to bind to (starts at 9999)', :port],
|
172
|
-
['-u','--control-url URL', 'DRuby URL to run control on (same as SCGI -1000)', :control_url],
|
173
|
-
['-l','--log-file PATH', 'Use a different log from from log/scgi.log', :logfile],
|
174
|
-
['-t','--throttle NUMBER', 'Max conn/second to allow.', :conns_second],
|
175
|
-
['-m','--max-conns NUMBER', 'Max simultaneous connections before the busy message', :maxconns],
|
176
|
-
['-P','--moron-mode PASSWORD', 'You are an idiot and you want your password on the command line', :password],
|
177
|
-
['-M','--merge', 'Merge new settings with previous rather than defaults', :merge],
|
178
|
-
['-c','--config PATH', 'Config file to use (#{DEFAULT_CONFIG})', :config]]) do |settings, args|
|
179
|
-
configure(settings)
|
180
|
-
end
|
181
|
-
|
182
|
-
make_command(cmd, 'start', "Start the application",
|
183
|
-
[['-u','--control-url URL', 'DRuby URL to run control on (same as SCGI -1000)', :control_url],
|
184
|
-
['-c','--config PATH', 'Config file to use (#{DEFAULT_CONFIG})', :config]]) do |settings, args|
|
185
|
-
cmd = File.dirname(__FILE__) + "/scgi_service"
|
186
|
-
start(cmd, settings[:config] || DEFAULT_CONFIG)
|
187
|
-
end
|
188
|
-
|
189
|
-
make_command(cmd, 'reconfig', "Reconfigure the SCGI servers with a new config",
|
190
|
-
[['-u','--control-url URL', 'DRuby URL to run control on (same as SCGI -1000)', :control_url],
|
191
|
-
['-c','--config PATH', 'Config file to use (#{DEFAULT_CONFIG})', :config]]) do |settings, args|
|
192
|
-
reconfigure(deduce_url(settings))
|
193
|
-
end
|
194
|
-
|
195
|
-
make_command(cmd, 'status', "Get status",
|
196
|
-
[['-u','--control-url URL', 'DRuby URL to run control on (same as SCGI -1000)', :control_url],
|
197
|
-
['-c','--config PATH', 'Config file to use (#{DEFAULT_CONFIG})', :config]]) do |settings, args|
|
198
|
-
status(deduce_url(settings))
|
199
|
-
end
|
200
|
-
|
201
|
-
make_command(cmd, 'stop', "Stop the application",
|
202
|
-
[['-u','--control-url URL', 'DRuby URL to run control on (same as SCGI -1000)', :control_url],
|
203
|
-
['-c','--config PATH', 'Config file to use (#{DEFAULT_CONFIG})', :config],
|
204
|
-
['-f','--force', 'Forced shutdown rather than graceful (default graceful)', :force]]) do |settings, args|
|
205
|
-
stop(deduce_url(settings), settings[:force] || false)
|
206
|
-
end
|
207
|
-
|
208
|
-
make_command(cmd, 'restart', "Restart the application",
|
209
|
-
[['-u','--control-url URL', 'DRuby URL to run control on (same as SCGI -1000)', :control_url],
|
210
|
-
['-c','--config PATH', 'Config file to use (#{DEFAULT_CONFIG})', :config],
|
211
|
-
['-f','--force', 'Forced shutdown rather than graceful (default graceful)', :force]]) do |settings, args|
|
212
|
-
restart(deduce_url(settings), settings[:force] || false)
|
213
|
-
end
|
214
|
-
|
215
|
-
make_command(cmd, 'monitor', "Monitor the application",
|
216
|
-
[['-u','--control-url URL', 'DRuby URL to run control on (same as SCGI -1000)', :control_url],
|
217
|
-
['-c','--config PATH', 'Config file to use (#{DEFAULT_CONFIG})', :config]]) do |settings, args|
|
218
|
-
monitor(deduce_url(settings))
|
219
|
-
end
|
220
|
-
|
221
|
-
cmd.parse
|