nitro 0.8.0 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. data/AUTHORS +3 -4
  2. data/ChangeLog +418 -0
  3. data/LICENSE +1 -1
  4. data/README +157 -89
  5. data/RELEASES +50 -0
  6. data/Rakefile +5 -7
  7. data/benchmark/nitro/bench.rb +5 -0
  8. data/benchmark/nitro/simple-webrick-n-200.txt +44 -0
  9. data/benchmark/nitro/static-webrick-n-200.txt +43 -0
  10. data/benchmark/nitro/tiny-lhttpd-n-200-c-5.txt +43 -0
  11. data/benchmark/nitro/tiny-webrick-n-200-c-5.txt +44 -0
  12. data/benchmark/nitro/tiny-webrick-n-200.txt +44 -0
  13. data/benchmark/nitro/tiny2-webrick-n-200.txt +44 -0
  14. data/{lib/nitro/server/cluster.rb → bin/cluster} +26 -30
  15. data/bin/proto/README +2 -2
  16. data/bin/proto/{apache.conf → conf/apache.conf} +0 -0
  17. data/bin/proto/conf/app.conf.rb +22 -0
  18. data/bin/proto/conf/lhttpd.conf +236 -0
  19. data/bin/proto/ctl +4 -0
  20. data/bin/proto/lib/README +5 -0
  21. data/bin/proto/log/README +3 -0
  22. data/bin/proto/root/fcgi.rb +6 -0
  23. data/bin/proto/root/index.xhtml +65 -7
  24. data/bin/proto/root/m/nitro.png +0 -0
  25. data/examples/blog/README +7 -5
  26. data/examples/blog/{apache.conf → conf/apache.conf} +0 -0
  27. data/examples/blog/conf/app.conf.rb +56 -0
  28. data/examples/blog/conf/lhttpd.conf +236 -0
  29. data/examples/blog/ctl +4 -0
  30. data/examples/blog/lib/blog.rb +11 -136
  31. data/examples/blog/lib/blog/controller.rb +99 -0
  32. data/examples/blog/lib/blog/model.rb +39 -0
  33. data/examples/blog/log/README +3 -0
  34. data/examples/blog/root/comments.xhtml +2 -2
  35. data/examples/blog/root/fcgi.rb +6 -0
  36. data/examples/blog/root/index.xhtml +4 -5
  37. data/examples/blog/root/login.xhtml +2 -2
  38. data/examples/blog/root/style.xsl +9 -9
  39. data/examples/blog/root/view_entry.xhtml +2 -2
  40. data/examples/flash/conf/app.conf.rb +23 -0
  41. data/examples/flash/ctl +4 -0
  42. data/examples/flash/log/README +3 -0
  43. data/examples/flash/root/index.xhtml +0 -9
  44. data/examples/flash/root/show_inline_text.xhtml +10 -5
  45. data/examples/no_xsl_blog/README +12 -0
  46. data/examples/no_xsl_blog/conf/apache.conf +0 -0
  47. data/examples/no_xsl_blog/conf/app.conf.rb +57 -0
  48. data/examples/no_xsl_blog/conf/lhttpd.conf +236 -0
  49. data/examples/no_xsl_blog/ctl +4 -0
  50. data/examples/no_xsl_blog/lib/blog.rb +20 -0
  51. data/examples/no_xsl_blog/lib/blog/controller.rb +102 -0
  52. data/examples/no_xsl_blog/lib/blog/model.rb +39 -0
  53. data/examples/no_xsl_blog/lib/blog/template.rb +134 -0
  54. data/examples/no_xsl_blog/log/README +3 -0
  55. data/examples/no_xsl_blog/root/comments.xhtml +41 -0
  56. data/examples/no_xsl_blog/root/entry_form.xhtml +22 -0
  57. data/examples/no_xsl_blog/root/fcgi.rb +6 -0
  58. data/examples/no_xsl_blog/root/index.xhtml +39 -0
  59. data/examples/no_xsl_blog/root/login.xhtml +21 -0
  60. data/examples/no_xsl_blog/root/m/bubbles.gif +0 -0
  61. data/examples/no_xsl_blog/root/m/comments_curve.gif +0 -0
  62. data/examples/no_xsl_blog/root/m/down.gif +0 -0
  63. data/examples/no_xsl_blog/root/m/footer_bg.gif +0 -0
  64. data/examples/no_xsl_blog/root/m/garrow.gif +0 -0
  65. data/examples/no_xsl_blog/root/m/gbull.gif +0 -0
  66. data/examples/no_xsl_blog/root/m/grbull.gif +0 -0
  67. data/examples/no_xsl_blog/root/m/h1_bg.gif +0 -0
  68. data/examples/no_xsl_blog/root/m/header_bg.gif +0 -0
  69. data/examples/no_xsl_blog/root/m/nitro.gif +0 -0
  70. data/examples/no_xsl_blog/root/m/obull.gif +0 -0
  71. data/examples/no_xsl_blog/root/m/page_bg.gif +0 -0
  72. data/examples/no_xsl_blog/root/m/rss.gif +0 -0
  73. data/examples/no_xsl_blog/root/m/side_title_bg.gif +0 -0
  74. data/examples/no_xsl_blog/root/m/sidebar_bg.gif +0 -0
  75. data/examples/no_xsl_blog/root/recent_posts.xhtml +14 -0
  76. data/examples/no_xsl_blog/root/style.css +301 -0
  77. data/examples/no_xsl_blog/root/view_entry.xhtml +25 -0
  78. data/examples/no_xsl_blog/root/view_entry.xml +12 -0
  79. data/examples/og/run.rb +2 -2
  80. data/examples/tiny/README +2 -2
  81. data/examples/tiny/conf/apache.conf +5 -0
  82. data/examples/tiny/conf/app.conf.rb +21 -0
  83. data/examples/tiny/conf/lhttpd.conf +236 -0
  84. data/examples/tiny/ctl +4 -0
  85. data/examples/tiny/log/README +3 -0
  86. data/examples/tiny/root/fcgi.rb +6 -0
  87. data/examples/tiny/root/index.xhtml +7 -4
  88. data/examples/tiny/root/nitro.png +0 -0
  89. data/lib/glue.rb +13 -9
  90. data/lib/glue/array.rb +1 -1
  91. data/lib/glue/cache.rb +1 -1
  92. data/lib/glue/flexob.rb +12 -0
  93. data/lib/glue/hash.rb +1 -1
  94. data/lib/glue/inflector.rb +2 -2
  95. data/lib/glue/logger.rb +4 -8
  96. data/lib/glue/misc.rb +14 -0
  97. data/lib/glue/number.rb +1 -1
  98. data/lib/glue/object.rb +26 -0
  99. data/lib/glue/pool.rb +1 -1
  100. data/lib/glue/property.rb +84 -91
  101. data/lib/glue/string.rb +1 -1
  102. data/lib/glue/time.rb +1 -1
  103. data/lib/glue/validation.rb +1 -1
  104. data/lib/nitro.rb +18 -6
  105. data/lib/nitro/adaptors/cgi.rb +291 -0
  106. data/lib/nitro/adaptors/fastcgi.rb +42 -0
  107. data/lib/nitro/adaptors/runner.rb +123 -0
  108. data/lib/nitro/adaptors/webrick.rb +110 -0
  109. data/lib/nitro/buffering.rb +43 -0
  110. data/lib/nitro/builders/form.rb +1 -1
  111. data/lib/nitro/builders/rss.rb +1 -1
  112. data/{bin → lib/nitro}/cluster.rb +26 -30
  113. data/lib/nitro/context.rb +82 -0
  114. data/lib/nitro/controller.rb +50 -0
  115. data/lib/nitro/cookie.rb +46 -0
  116. data/lib/nitro/dispatcher.rb +105 -0
  117. data/lib/nitro/filters.rb +9 -10
  118. data/lib/nitro/localization.rb +42 -0
  119. data/lib/nitro/mail.rb +11 -14
  120. data/lib/nitro/render.rb +275 -0
  121. data/lib/nitro/request.rb +128 -0
  122. data/lib/nitro/response.rb +38 -0
  123. data/lib/nitro/scaffold.rb +11 -11
  124. data/lib/nitro/session.rb +84 -0
  125. data/lib/nitro/{server/shaders.rb → shaders.rb} +56 -36
  126. data/lib/nitro/ui/pager.rb +23 -26
  127. data/lib/nitro/{sitemap.rb → ui/sitemap.rb} +4 -12
  128. data/lib/nitro/uri.rb +1 -1
  129. data/lib/nitro/version.rb +10 -8
  130. data/lib/og.rb +66 -65
  131. data/lib/og/backend.rb +1 -1
  132. data/lib/og/backends/mysql.rb +48 -52
  133. data/lib/og/backends/psql.rb +34 -37
  134. data/lib/og/connection.rb +15 -15
  135. data/lib/og/enchant.rb +16 -9
  136. data/lib/og/meta.rb +127 -54
  137. data/lib/og/mock.rb +18 -18
  138. data/lib/og/version.rb +6 -4
  139. data/lib/parts/content.rb +4 -8
  140. data/test/glue/tc_logger.rb +3 -0
  141. data/test/glue/tc_property.rb +19 -3
  142. data/test/nitro/adaptors/tc_cgi.rb +63 -0
  143. data/test/nitro/adaptors/tc_webrick.rb +15 -0
  144. data/test/nitro/builders/tc_xml.rb +2 -2
  145. data/test/nitro/tc_context.rb +13 -0
  146. data/test/nitro/tc_controller.rb +47 -0
  147. data/test/nitro/tc_dispatcher.rb +64 -0
  148. data/test/nitro/tc_session.rb +20 -0
  149. data/test/nitro/{tc_sitemap.rb → ui/tc_sitemap.rb} +1 -1
  150. data/test/root/blog/list.xhtml +6 -0
  151. data/test/tc_og.rb +41 -4
  152. metadata +115 -59
  153. data/bin/proto/app.rb +0 -20
  154. data/bin/proto/config.rb +0 -77
  155. data/examples/blog/app.rb +0 -21
  156. data/examples/blog/config.rb +0 -95
  157. data/examples/blog/env.rb +0 -22
  158. data/examples/flash/README +0 -34
  159. data/examples/flash/app.rb +0 -20
  160. data/examples/flash/config.rb +0 -38
  161. data/examples/flash/lib/flash.rb +0 -40
  162. data/examples/flash/tmp.swf +0 -0
  163. data/examples/tiny/app.rb +0 -19
  164. data/examples/tiny/config.rb +0 -29
  165. data/examples/tiny/root/nitro-small.png +0 -0
  166. data/lib/nitro/application.rb +0 -217
  167. data/lib/nitro/config.rb +0 -128
  168. data/lib/nitro/events.rb +0 -122
  169. data/lib/nitro/html.rb +0 -151
  170. data/lib/nitro/http.rb +0 -102
  171. data/lib/nitro/l10n.rb +0 -30
  172. data/lib/nitro/server.rb +0 -59
  173. data/lib/nitro/server/appserver.rb +0 -67
  174. data/lib/nitro/server/cookie.rb +0 -87
  175. data/lib/nitro/server/dispatcher.rb +0 -62
  176. data/lib/nitro/server/filters.rb +0 -75
  177. data/lib/nitro/server/filters/autologin.rb +0 -51
  178. data/lib/nitro/server/fragment.rb +0 -70
  179. data/lib/nitro/server/handlers.rb +0 -127
  180. data/lib/nitro/server/render.rb +0 -426
  181. data/lib/nitro/server/request.rb +0 -658
  182. data/lib/nitro/server/requestpart.rb +0 -54
  183. data/lib/nitro/server/script.rb +0 -387
  184. data/lib/nitro/server/server.rb +0 -57
  185. data/lib/nitro/server/session.rb +0 -220
  186. data/lib/nitro/server/user.rb +0 -46
  187. data/lib/nitro/server/webrick.rb +0 -180
  188. data/lib/nitro/service.rb +0 -26
  189. data/lib/xsl/ui.xsl +0 -51
  190. data/lib/xsl/xforms.xsl +0 -28
  191. data/test/nitro/server/tc_cookie.rb +0 -34
  192. data/test/nitro/server/tc_filters.rb +0 -38
  193. data/test/nitro/server/tc_request.rb +0 -70
  194. data/test/nitro/server/tc_requestpart.rb +0 -28
  195. data/test/nitro/server/tc_session.rb +0 -34
  196. data/test/nitro/tc_events.rb +0 -44
  197. data/test/nitro/tc_html.rb +0 -79
  198. data/test/nitro/tc_http.rb +0 -18
@@ -1,21 +0,0 @@
1
- #!/usr/local/bin/ruby
2
-
3
- # = Blog
4
- #
5
- # A simple Blog powered by Nitro.
6
- #
7
- # code:
8
- # * George Moschovitis <gm@navel.gr>
9
- #
10
- # (c) 2004 Navel, all rights reserved.
11
- # $Id: app.rb 197 2004-12-21 13:50:17Z gmosx $
12
-
13
- # set to true for DEBUG mode.
14
- $DBG = true
15
-
16
- $LOAD_PATH.unshift "../../lib"
17
- $LOAD_PATH.unshift "../../vendor"
18
-
19
- require "config"
20
-
21
- $app = N::WebrickServer.new.exec()
@@ -1,95 +0,0 @@
1
- # = Blog Configuration
2
- #
3
- # You can find additional configuration variables in
4
- # lib/n/config.rb. Just copy the variables you want to
5
- # change in this file
6
- #
7
- # WARNING: if you want to change the backend dont forget
8
- # to change it in the DEBUG and LIVE configurations.
9
- #--
10
- # George Moschovitis <gm@navel.gr>
11
- # (c) 2004 Navel, all rights reserved.
12
- # $Id: config.rb 197 2004-12-21 13:50:17Z gmosx $
13
- #++
14
-
15
- require 'nitro'
16
- require 'glue/logger'
17
- require 'glue/validation'
18
- require 'nitro/config'
19
-
20
- require 'og'
21
- require 'nitro/markup'
22
- require 'nitro/l10n'
23
- require 'nitro/events'
24
- require 'glue/mixins'
25
- require 'nitro/sitemap'
26
-
27
- require 'glue/number'
28
- require 'glue/string'
29
- require 'glue/array'
30
- require 'glue/hash'
31
- require 'nitro/html'
32
-
33
- require 'nitro/server/webrick'
34
- require 'nitro/server/shaders'
35
-
36
- require 'nitro/builders/form'
37
-
38
- require 'lib/blog'
39
-
40
- $name = 'Nitro Blog'
41
-
42
- $blog_username = 'George Moschovitis'
43
- $blog_password = 'navelrulez'
44
-
45
- $services = {
46
- :index => N::BlogService
47
- # 'users' => N::UsersService
48
- }
49
-
50
- $srv_address = $appsrv_address = "127.0.0.1"
51
- $srv_url = "http://#$srv_address:#$srv_port"
52
-
53
- if $DBG # DEBUG mode
54
-
55
- $og = Og::Database.new(
56
- :address => "localhost",
57
- # :backend => "mysql",
58
- :backend => "psql",
59
- :database => "blog",
60
- :user => "postgres",
61
- :password => "navelrulez",
62
- :connection_count => 3
63
- )
64
-
65
- # dont compress when debuging, more readable code.
66
- $shader = N::XSLTShader.new("#$root_dir/style.xsl",
67
- N::RubyShader.new
68
- )
69
- =begin
70
- # lets play with the ULTRA-COOL breakpointer library.
71
- require 'breakpoint'
72
- Breakpoint.activate_drb
73
- =end
74
-
75
- else # LIVE mode
76
-
77
- $appsrv_port = 8080
78
-
79
- $og = Og::Database.new(
80
- :address => "localhost",
81
- # :backend => "mysql",
82
- :backend => "psql",
83
- :database => "blog",
84
- :user => "postgres",
85
- :password => "navelrulez",
86
- :connection_count => 20
87
- )
88
-
89
- $shader = N::XSLTShader.new("#$root_dir/style.xsl",
90
- N::RubyShader.new(
91
- N::CompressShader.new
92
- )
93
- )
94
-
95
- end
@@ -1,22 +0,0 @@
1
- # = Environment injection.
2
- #
3
- # Require this file in your script to gain access to the full
4
- # AppServer environment. Typically used to attach an irb session to
5
- # a running application process:
6
- #
7
- # irb -r env
8
- #
9
- # code:
10
- # * George Moschovitis <gm@navel.gr>
11
- #
12
- # (c) 2004 Navel, all rights reserved.
13
- # $Id: env.rb 187 2004-12-10 13:34:28Z gmosx $
14
-
15
- $DBG = true
16
-
17
- $LOAD_PATH.unshift '../../lib'
18
-
19
- require 'config'
20
-
21
- $app = N::AppServer.new.exec()
22
-
@@ -1,34 +0,0 @@
1
- = Your application
2
-
3
- Here comes the README file for your application.
4
-
5
- == Configuration
6
-
7
- Edit the file conf/webapp.rb as needed.
8
-
9
- By default this skeleton app uses the PostgreSQL backend.
10
- If you want to use a different backend dont forget to
11
- change it for the DEBUG and LIVE configurations.
12
-
13
- == Run
14
-
15
- Exec the following command:
16
-
17
- ruby app.rb --start
18
-
19
- then point your browser to:
20
-
21
- http://127.0.0.1:8080
22
-
23
- (if you want to change the server address/port, edit the config.rb
24
- file)
25
-
26
- == Discussion
27
-
28
- If you want to modify the skeleton app it is a nice idea to switch
29
- to debug mode. Edit the following line in the file app.rb:
30
-
31
- $DBG = true
32
-
33
- In debug mode the view files (xhtml/xsl/etc) are automatically
34
- reloaded.
@@ -1,20 +0,0 @@
1
- #! /usr/bin/env ruby
2
-
3
- # = YourApp
4
- #
5
- # A skeleton application.
6
- #
7
- # code:
8
- # * George Moschovitis <gm@navel.gr>
9
- #
10
- # (c) 2004 Navel, all rights reserved.
11
- # $Id: app.rb 189 2004-12-13 21:38:05Z gmosx $
12
-
13
- # set to true for DEBUG mode.
14
- $DBG = true
15
-
16
- $LOAD_PATH.unshift '../../lib'
17
-
18
- require 'config'
19
-
20
- $app = N::WebrickServer.new.exec()
@@ -1,38 +0,0 @@
1
- # = Dynamic Flash
2
- #
3
- # A simple app that demonstrates
4
- #
5
- # code:
6
- # * George Moschovitis <gm@navel.gr>
7
- #
8
- # (c) 2004 Navel, all rights reserved.
9
- # $Id: config.rb 189 2004-12-13 21:38:05Z gmosx $
10
-
11
- require 'nitro'
12
- require 'glue/logger'
13
- require 'nitro/config'
14
-
15
- require 'nitro/l10n'
16
- require 'glue/mixins'
17
- require 'nitro/sitemap'
18
-
19
- require 'glue/number'
20
- require 'glue/string'
21
- require 'glue/array'
22
- require 'glue/hash'
23
- require 'nitro/html'
24
-
25
- require 'nitro/server/webrick'
26
- require 'nitro/server/shaders'
27
-
28
- require 'lib/flash'
29
-
30
- $name = 'Dynamic Flash Application'
31
-
32
- $services = {
33
- :index => N::FlashService
34
- }
35
-
36
- $srv_address = $appsrv_address = '127.0.0.1'
37
- $srv_url = "http://#$srv_address:#$srv_port"
38
-
@@ -1,40 +0,0 @@
1
- # code:
2
- # * George Moschovitis <gm@navel.gr>
3
- #
4
- # (c) 2004 Navel, all rights reserved.
5
- # $Id: flash.rb 189 2004-12-13 21:38:05Z gmosx $
6
-
7
- require 'nitro/service'
8
- require 'ming/ming'
9
-
10
- module N
11
-
12
-
13
- # = FlashService
14
- #
15
- class FlashService < N::Service
16
- include Ming
17
-
18
- SOURCE_FILE = __FILE__
19
-
20
- def show_text
21
- create_flash
22
- end
23
-
24
- private
25
-
26
- def create_flash
27
- m = SWFMovie.new
28
- f = SWFBrowserFont.new('_serif')
29
- t = SWFTextField.new
30
- t.set_font(f)
31
- t.add_string(@params['text'])
32
- m.add(t)
33
- @response.header['Content-Type'] = 'application/x-shockwave-flash'
34
- m.save('tmp.swf')
35
- @out = File.read('tmp.swf')
36
- end
37
-
38
- end
39
-
40
- end # module
Binary file
@@ -1,19 +0,0 @@
1
- #!/usr/local/bin/ruby
2
-
3
- # = Tiny Example
4
- #
5
- # A simple Web Application to demonstrate the Engine.
6
- #
7
- # code:
8
- # * George Moschovitis <gm@navel.gr>
9
- #
10
- # (c) 2004 Navel, all rights reserved.
11
- # $Id: app.rb 185 2004-12-10 13:29:09Z gmosx $
12
-
13
- $DBG = false
14
-
15
- $LOAD_PATH.unshift "../../lib"
16
-
17
- require "config"
18
-
19
- $app = N::WebrickServer.new.exec()
@@ -1,29 +0,0 @@
1
- # = Tiny Configuration
2
- #
3
- # You can find additional configuration variables in
4
- # lib/n/config.rb. Just copy the variables you want to
5
- # change in this file
6
- #
7
- # code:
8
- # * George Moschovitis <gm@navel.gr>
9
- #
10
- # (c) 2004 Navel, all rights reserved.
11
- # $Id: config.rb 167 2004-11-23 14:03:10Z gmosx $
12
-
13
- require "nitro"
14
- require "glue/logger"
15
- require "nitro/config"
16
-
17
- require "glue/number"
18
- require "glue/string"
19
- require "glue/array"
20
- require "glue/hash"
21
- require "nitro/html"
22
-
23
- require "nitro/server/webrick"
24
-
25
- $name = "Tiny Example"
26
-
27
- $srv_address = $appsrv_address = "127.0.0.1"
28
- $srv_port = 8080
29
- $srv_url = "http://#$srv_address:#$srv_port"
@@ -1,217 +0,0 @@
1
- # = Application
2
- #
3
- # The default Application object of the Framework.
4
- #
5
- # code:
6
- # George Moschovitis <gm@navel.gr>
7
- # Anastasios Koutoumanos <ak@navel.gr>
8
- # Elias Athanasopoulos <elathan@navel.gr>
9
- # Elias Karakoulakis <ekarak@ktismata.com>
10
- #
11
- # (c) 2004 Navel, all rights reserved.
12
- # $Id: application.rb 174 2004-11-26 16:00:21Z gmosx $
13
-
14
- require 'optparse'
15
- require 'ostruct'
16
-
17
- require "glue/logger"
18
- require "nitro"
19
-
20
- module N
21
-
22
- # == Application
23
- #
24
- # The default Application object of the Framework.
25
- #
26
- class Application
27
- # credentials of the application
28
- attr_accessor :name, :title, :description, :version
29
-
30
- # the status of the application
31
- # use symbols to denote status.
32
- # valid status symbols:
33
- # * :run = The server is running
34
- # * :stop = The server is stopped
35
- attr_accessor :status
36
-
37
- # startup time of the application
38
- attr_accessor :create_time
39
-
40
- # is the application daemonized?
41
- attr_reader :daemonized
42
-
43
- # the pid of the application
44
- attr_reader :pid, :pidfile
45
-
46
- # Intialize method
47
- #
48
- def initialize(name = "Unknown")
49
- @name = name
50
- @pidfile = "/tmp/#{@name}.pid"
51
- @create_time = Time.now()
52
- @status = :stop
53
- end
54
-
55
- # Parse the arguments passed to the application.
56
- # Some standard arguments are handled by default.
57
- #
58
- def parse_arguments(args = ARGV)
59
-
60
- opts = OptionParser.new { |opts|
61
- opts.banner = "Usage: application.rb [action]"
62
-
63
- opts.separator ""
64
- opts.separator "Specific options:"
65
-
66
- opts.on("-s", "--start",
67
- "Start '#$name'.") {
68
- start()
69
- }
70
-
71
- opts.on("-S", "--stop",
72
- "Stop '#$name'.") {
73
- stop()
74
- }
75
-
76
- opts.on("-r", "--restart",
77
- "Restart '#$name'.") {
78
- restart()
79
- }
80
-
81
- opts.on("-d", "--daemon",
82
- "Run '#$name' as a daemon.") {
83
- daemonize()
84
- start()
85
- }
86
-
87
- opts.on_tail("-?", "--help", "Show this message.") {
88
- puts opts
89
- exit
90
- }
91
-
92
- opts.on_tail("-v", "--version", "Show version.") {
93
- puts $srv_version
94
- exit
95
- }
96
-
97
- }
98
- begin
99
- opts.parse!(args)
100
- rescue => ex
101
- puts ex
102
- puts "Please, either specify a valid option or invoke the usage using -? or --help."
103
- end
104
- end
105
- alias_method :exec, :parse_arguments
106
-
107
- #
108
- #
109
- def start()
110
- raise "Application allready started!" unless :stop == @status
111
-
112
- begin
113
- run()
114
- rescue => ex
115
- puts ex
116
- end
117
-
118
- # to allow for chaining
119
- return self
120
- end
121
-
122
- # Override to properly restart the application
123
- #
124
- def restart()
125
- stop()
126
- start()
127
-
128
- # to allow for chaining
129
- return self
130
- end
131
-
132
- # Stop the application. Typically kills ths application daemon.
133
- #
134
- def stop
135
- if dpid = daemon_pid()
136
- begin
137
- File.delete(@pidfile)
138
- Process.kill("SIGKILL", dpid)
139
- Logger.info "Successfully killed #{@name} instance, pid=#{dpid}"
140
- rescue => ex
141
- Logger.error "Cannot kill #{@name} instance, pid=#{dpid}"
142
- Logger.error ex
143
- end
144
- else
145
- Logger.error "Cannot locate pid of running instance!"
146
- end
147
-
148
- # to allow for chaining
149
- return self
150
- end
151
-
152
- # Begin the application loop.
153
- # Override this method in your application.
154
- #
155
- def run
156
- # to allow for chaining
157
- return self
158
- end
159
-
160
- # Run the application as a daemon
161
- # FIXME: handle logging for daemons.
162
- # ???: How does this work !?!?
163
- #
164
- =begin
165
- def daemonize
166
- unless @daemonized
167
- trap "SIGCLD", "IGNORE"
168
-
169
- pid = fork()
170
-
171
- if pid # parent process
172
- @pid = pid
173
- File.open(@pidfile, 'w') {|f| f << "#{pid}\n" }
174
- exit!
175
- else # child
176
- Logger.info "Daemon for '#{@name}', process id: #{Process.pid}"
177
- end
178
-
179
- # change process group and lose control tty
180
- Process.setpgrp()
181
- end
182
-
183
- @daemonized = true
184
-
185
- return self
186
- end
187
- =end
188
- def daemonize
189
- unless @daemonized
190
- exit!(0) if fork
191
- Process::setsid
192
- exit!(0) if fork
193
- File::umask(0)
194
- [ STDIN, STDOUT, STDERR ].each do |io|
195
- io.reopen("/dev/null", "r+")
196
- end
197
- end
198
- @daemonized = true
199
-
200
- return self
201
- end
202
-
203
-
204
- # Returns the pid of the running daemon
205
- #
206
- def daemon_pid()
207
- begin
208
- return File.open(@pidfile).read.chomp.to_i
209
- rescue
210
- Logger.info "Could not read pid from #{@pidfile}"
211
- return nil
212
- end
213
- end
214
- end
215
-
216
- end # module
217
-