Permalink
Browse files

Added missing gem dependencies.

  • Loading branch information...
1 parent 79fe09c commit 3fdbfe5e5c73dde8bba14709d877ea610cba6cae @leenookx committed Feb 25, 2011
Showing with 16,093 additions and 0 deletions.
  1. +97 −0 vendor/gems/daemons-1.0.10/.specification
  2. +29 −0 vendor/gems/daemons-1.0.10/LICENSE
  3. +223 −0 vendor/gems/daemons-1.0.10/README
  4. +84 −0 vendor/gems/daemons-1.0.10/Rakefile
  5. +126 −0 vendor/gems/daemons-1.0.10/Releases
  6. +6 −0 vendor/gems/daemons-1.0.10/TODO
  7. +56 −0 vendor/gems/daemons-1.0.10/examples/call/call.rb
  8. +55 −0 vendor/gems/daemons-1.0.10/examples/call/call_monitor.rb
  9. +20 −0 vendor/gems/daemons-1.0.10/examples/daemonize/daemonize.rb
  10. +17 −0 vendor/gems/daemons-1.0.10/examples/run/ctrl_crash.rb
  11. +16 −0 vendor/gems/daemons-1.0.10/examples/run/ctrl_exec.rb
  12. +15 −0 vendor/gems/daemons-1.0.10/examples/run/ctrl_exit.rb
  13. +17 −0 vendor/gems/daemons-1.0.10/examples/run/ctrl_keep_pid_files.rb
  14. +16 −0 vendor/gems/daemons-1.0.10/examples/run/ctrl_monitor.rb
  15. +16 −0 vendor/gems/daemons-1.0.10/examples/run/ctrl_multiple.rb
  16. +12 −0 vendor/gems/daemons-1.0.10/examples/run/ctrl_normal.rb
  17. +16 −0 vendor/gems/daemons-1.0.10/examples/run/ctrl_ontop.rb
  18. +43 −0 vendor/gems/daemons-1.0.10/examples/run/ctrl_optionparser.rb
  19. +25 −0 vendor/gems/daemons-1.0.10/examples/run/ctrl_proc.rb
  20. +101 −0 vendor/gems/daemons-1.0.10/examples/run/ctrl_proc.rb.output
  21. +22 −0 vendor/gems/daemons-1.0.10/examples/run/ctrl_proc_multiple.rb
  22. +2 −0 vendor/gems/daemons-1.0.10/examples/run/ctrl_proc_multiple.rb.output
  23. +17 −0 vendor/gems/daemons-1.0.10/examples/run/ctrl_proc_simple.rb
  24. +12 −0 vendor/gems/daemons-1.0.10/examples/run/myserver.rb
  25. +14 −0 vendor/gems/daemons-1.0.10/examples/run/myserver_crashing.rb
  26. +30 −0 vendor/gems/daemons-1.0.10/examples/run/myserver_crashing.rb.output
  27. +8 −0 vendor/gems/daemons-1.0.10/examples/run/myserver_exiting.rb
  28. +283 −0 vendor/gems/daemons-1.0.10/lib/daemons.rb
  29. +372 −0 vendor/gems/daemons-1.0.10/lib/daemons/application.rb
  30. +152 −0 vendor/gems/daemons-1.0.10/lib/daemons/application_group.rb
  31. +117 −0 vendor/gems/daemons-1.0.10/lib/daemons/cmdline.rb
  32. +134 −0 vendor/gems/daemons-1.0.10/lib/daemons/controller.rb
  33. +263 −0 vendor/gems/daemons-1.0.10/lib/daemons/daemonize.rb
  34. +28 −0 vendor/gems/daemons-1.0.10/lib/daemons/exceptions.rb
  35. +127 −0 vendor/gems/daemons-1.0.10/lib/daemons/monitor.rb
  36. +101 −0 vendor/gems/daemons-1.0.10/lib/daemons/pid.rb
  37. +111 −0 vendor/gems/daemons-1.0.10/lib/daemons/pidfile.rb
  38. +10 −0 vendor/gems/daemons-1.0.10/lib/daemons/pidmem.rb
  39. +1,360 −0 vendor/gems/daemons-1.0.10/setup.rb
  40. +278 −0 vendor/gems/rack-1.1.0/.specification
  41. +18 −0 vendor/gems/rack-1.1.0/COPYING
  42. +21 −0 vendor/gems/rack-1.1.0/KNOWN-ISSUES
  43. 0 vendor/gems/rack-1.1.0/RDOX
  44. +399 −0 vendor/gems/rack-1.1.0/README
  45. +171 −0 vendor/gems/rack-1.1.0/SPEC
  46. +4 −0 vendor/gems/rack-1.1.0/bin/rackup
  47. +111 −0 vendor/gems/rack-1.1.0/contrib/rack_logo.svg
  48. +4 −0 vendor/gems/rack-1.1.0/example/lobster.ru
  49. +14 −0 vendor/gems/rack-1.1.0/example/protectedlobster.rb
  50. +8 −0 vendor/gems/rack-1.1.0/example/protectedlobster.ru
  51. +92 −0 vendor/gems/rack-1.1.0/lib/rack.rb
  52. +22 −0 vendor/gems/rack-1.1.0/lib/rack/adapter/camping.rb
  53. +37 −0 vendor/gems/rack-1.1.0/lib/rack/auth/abstract/handler.rb
  54. +37 −0 vendor/gems/rack-1.1.0/lib/rack/auth/abstract/request.rb
  55. +58 −0 vendor/gems/rack-1.1.0/lib/rack/auth/basic.rb
  56. +124 −0 vendor/gems/rack-1.1.0/lib/rack/auth/digest/md5.rb
  57. +51 −0 vendor/gems/rack-1.1.0/lib/rack/auth/digest/nonce.rb
  58. +55 −0 vendor/gems/rack-1.1.0/lib/rack/auth/digest/params.rb
  59. +40 −0 vendor/gems/rack-1.1.0/lib/rack/auth/digest/request.rb
  60. +80 −0 vendor/gems/rack-1.1.0/lib/rack/builder.rb
  61. +41 −0 vendor/gems/rack-1.1.0/lib/rack/cascade.rb
  62. +49 −0 vendor/gems/rack-1.1.0/lib/rack/chunked.rb
  63. +49 −0 vendor/gems/rack-1.1.0/lib/rack/commonlogger.rb
  64. +47 −0 vendor/gems/rack-1.1.0/lib/rack/conditionalget.rb
  65. +15 −0 vendor/gems/rack-1.1.0/lib/rack/config.rb
  66. +29 −0 vendor/gems/rack-1.1.0/lib/rack/content_length.rb
  67. +23 −0 vendor/gems/rack-1.1.0/lib/rack/content_type.rb
  68. +96 −0 vendor/gems/rack-1.1.0/lib/rack/deflater.rb
  69. +157 −0 vendor/gems/rack-1.1.0/lib/rack/directory.rb
  70. +23 −0 vendor/gems/rack-1.1.0/lib/rack/etag.rb
  71. +90 −0 vendor/gems/rack-1.1.0/lib/rack/file.rb
  72. +88 −0 vendor/gems/rack-1.1.0/lib/rack/handler.rb
  73. +61 −0 vendor/gems/rack-1.1.0/lib/rack/handler/cgi.rb
  74. +8 −0 vendor/gems/rack-1.1.0/lib/rack/handler/evented_mongrel.rb
  75. +89 −0 vendor/gems/rack-1.1.0/lib/rack/handler/fastcgi.rb
  76. +63 −0 vendor/gems/rack-1.1.0/lib/rack/handler/lsws.rb
  77. +90 −0 vendor/gems/rack-1.1.0/lib/rack/handler/mongrel.rb
  78. +62 −0 vendor/gems/rack-1.1.0/lib/rack/handler/scgi.rb
  79. +8 −0 vendor/gems/rack-1.1.0/lib/rack/handler/swiftiplied_mongrel.rb
  80. +18 −0 vendor/gems/rack-1.1.0/lib/rack/handler/thin.rb
  81. +69 −0 vendor/gems/rack-1.1.0/lib/rack/handler/webrick.rb
  82. +19 −0 vendor/gems/rack-1.1.0/lib/rack/head.rb
  83. +575 −0 vendor/gems/rack-1.1.0/lib/rack/lint.rb
  84. +65 −0 vendor/gems/rack-1.1.0/lib/rack/lobster.rb
  85. +16 −0 vendor/gems/rack-1.1.0/lib/rack/lock.rb
  86. +20 −0 vendor/gems/rack-1.1.0/lib/rack/logger.rb
  87. +27 −0 vendor/gems/rack-1.1.0/lib/rack/methodoverride.rb
  88. +206 −0 vendor/gems/rack-1.1.0/lib/rack/mime.rb
  89. +189 −0 vendor/gems/rack-1.1.0/lib/rack/mock.rb
  90. +18 −0 vendor/gems/rack-1.1.0/lib/rack/nulllogger.rb
  91. +57 −0 vendor/gems/rack-1.1.0/lib/rack/recursive.rb
  92. +109 −0 vendor/gems/rack-1.1.0/lib/rack/reloader.rb
  93. +271 −0 vendor/gems/rack-1.1.0/lib/rack/request.rb
  94. +149 −0 vendor/gems/rack-1.1.0/lib/rack/response.rb
  95. +100 −0 vendor/gems/rack-1.1.0/lib/rack/rewindable_input.rb
  96. +27 −0 vendor/gems/rack-1.1.0/lib/rack/runtime.rb
  97. +142 −0 vendor/gems/rack-1.1.0/lib/rack/sendfile.rb
  98. +212 −0 vendor/gems/rack-1.1.0/lib/rack/server.rb
  99. +140 −0 vendor/gems/rack-1.1.0/lib/rack/session/abstract/id.rb
  100. +90 −0 vendor/gems/rack-1.1.0/lib/rack/session/cookie.rb
  101. +119 −0 vendor/gems/rack-1.1.0/lib/rack/session/memcache.rb
  102. +100 −0 vendor/gems/rack-1.1.0/lib/rack/session/pool.rb
  103. +349 −0 vendor/gems/rack-1.1.0/lib/rack/showexceptions.rb
  104. +106 −0 vendor/gems/rack-1.1.0/lib/rack/showstatus.rb
  105. +38 −0 vendor/gems/rack-1.1.0/lib/rack/static.rb
  106. +56 −0 vendor/gems/rack-1.1.0/lib/rack/urlmap.rb
  107. +620 −0 vendor/gems/rack-1.1.0/lib/rack/utils.rb
  108. +38 −0 vendor/gems/rack-1.1.0/rack.gemspec
  109. +73 −0 vendor/gems/rack-1.1.0/test/spec_rack_auth_basic.rb
  110. +226 −0 vendor/gems/rack-1.1.0/test/spec_rack_auth_digest.rb
  111. +84 −0 vendor/gems/rack-1.1.0/test/spec_rack_builder.rb
  112. +51 −0 vendor/gems/rack-1.1.0/test/spec_rack_camping.rb
  113. +48 −0 vendor/gems/rack-1.1.0/test/spec_rack_cascade.rb
  114. +89 −0 vendor/gems/rack-1.1.0/test/spec_rack_cgi.rb
  115. +62 −0 vendor/gems/rack-1.1.0/test/spec_rack_chunked.rb
  116. +61 −0 vendor/gems/rack-1.1.0/test/spec_rack_commonlogger.rb
  117. +41 −0 vendor/gems/rack-1.1.0/test/spec_rack_conditionalget.rb
  118. +24 −0 vendor/gems/rack-1.1.0/test/spec_rack_config.rb
  119. +43 −0 vendor/gems/rack-1.1.0/test/spec_rack_content_length.rb
  120. +30 −0 vendor/gems/rack-1.1.0/test/spec_rack_content_type.rb
  121. +127 −0 vendor/gems/rack-1.1.0/test/spec_rack_deflater.rb
  122. +61 −0 vendor/gems/rack-1.1.0/test/spec_rack_directory.rb
  123. +17 −0 vendor/gems/rack-1.1.0/test/spec_rack_etag.rb
  124. +89 −0 vendor/gems/rack-1.1.0/test/spec_rack_fastcgi.rb
  125. +75 −0 vendor/gems/rack-1.1.0/test/spec_rack_file.rb
  126. +43 −0 vendor/gems/rack-1.1.0/test/spec_rack_handler.rb
  127. +30 −0 vendor/gems/rack-1.1.0/test/spec_rack_head.rb
  128. +528 −0 vendor/gems/rack-1.1.0/test/spec_rack_lint.rb
  129. +45 −0 vendor/gems/rack-1.1.0/test/spec_rack_lobster.rb
  130. +38 −0 vendor/gems/rack-1.1.0/test/spec_rack_lock.rb
  131. +21 −0 vendor/gems/rack-1.1.0/test/spec_rack_logger.rb
  132. +60 −0 vendor/gems/rack-1.1.0/test/spec_rack_methodoverride.rb
  133. +243 −0 vendor/gems/rack-1.1.0/test/spec_rack_mock.rb
  134. +189 −0 vendor/gems/rack-1.1.0/test/spec_rack_mongrel.rb
  135. +13 −0 vendor/gems/rack-1.1.0/test/spec_rack_nulllogger.rb
  136. +77 −0 vendor/gems/rack-1.1.0/test/spec_rack_recursive.rb
  137. +545 −0 vendor/gems/rack-1.1.0/test/spec_rack_request.rb
  138. +221 −0 vendor/gems/rack-1.1.0/test/spec_rack_response.rb
  139. +118 −0 vendor/gems/rack-1.1.0/test/spec_rack_rewindable_input.rb
  140. +35 −0 vendor/gems/rack-1.1.0/test/spec_rack_runtime.rb
  141. +86 −0 vendor/gems/rack-1.1.0/test/spec_rack_sendfile.rb
  142. +73 −0 vendor/gems/rack-1.1.0/test/spec_rack_session_cookie.rb
  143. +273 −0 vendor/gems/rack-1.1.0/test/spec_rack_session_memcache.rb
  144. +172 −0 vendor/gems/rack-1.1.0/test/spec_rack_session_pool.rb
  145. +21 −0 vendor/gems/rack-1.1.0/test/spec_rack_showexceptions.rb
  146. +72 −0 vendor/gems/rack-1.1.0/test/spec_rack_showstatus.rb
  147. +37 −0 vendor/gems/rack-1.1.0/test/spec_rack_static.rb
  148. +91 −0 vendor/gems/rack-1.1.0/test/spec_rack_thin.rb
  149. +215 −0 vendor/gems/rack-1.1.0/test/spec_rack_urlmap.rb
  150. +552 −0 vendor/gems/rack-1.1.0/test/spec_rack_utils.rb
  151. +130 −0 vendor/gems/rack-1.1.0/test/spec_rack_webrick.rb
  152. +154 −0 vendor/gems/rack-1.1.0/test/spec_rackup.rb
View
97 vendor/gems/daemons-1.0.10/.specification
@@ -0,0 +1,97 @@
+--- !ruby/object:Gem::Specification
+name: daemons
+version: !ruby/object:Gem::Version
+ version: 1.0.10
+platform: ruby
+authors:
+- Thomas Uehlinger
+autorequire: daemons
+bindir: bin
+cert_chain: []
+
+date: 2008-03-20 00:00:00 +00:00
+default_executable:
+dependencies: []
+
+description: Daemons provides an easy way to wrap existing ruby scripts (for example a self-written server) to be run as a daemon and to be controlled by simple start/stop/restart commands. You can also call blocks as daemons and control them from the parent or just daemonize the current process. Besides this basic functionality, daemons offers many advanced features like exception backtracing and logging (in case your ruby script crashes) and monitoring and automatic restarting of your processes if they crash.
+email: th.uehlinger@gmx.ch
+executables: []
+
+extensions: []
+
+extra_rdoc_files:
+- README
+- Releases
+- TODO
+files:
+- Rakefile
+- Releases
+- TODO
+- README
+- LICENSE
+- setup.rb
+- lib/daemons/application.rb
+- lib/daemons/application_group.rb
+- lib/daemons/cmdline.rb
+- lib/daemons/controller.rb
+- lib/daemons/daemonize.rb
+- lib/daemons/exceptions.rb
+- lib/daemons/monitor.rb
+- lib/daemons/pid.rb
+- lib/daemons/pidfile.rb
+- lib/daemons/pidmem.rb
+- lib/daemons.rb
+- examples/call
+- examples/call/call.rb
+- examples/call/call_monitor.rb
+- examples/daemonize
+- examples/daemonize/daemonize.rb
+- examples/run
+- examples/run/ctrl_crash.rb
+- examples/run/ctrl_exec.rb
+- examples/run/ctrl_exit.rb
+- examples/run/ctrl_keep_pid_files.rb
+- examples/run/ctrl_monitor.rb
+- examples/run/ctrl_multiple.rb
+- examples/run/ctrl_normal.rb
+- examples/run/ctrl_ontop.rb
+- examples/run/ctrl_optionparser.rb
+- examples/run/ctrl_proc.rb
+- examples/run/ctrl_proc.rb.output
+- examples/run/ctrl_proc_multiple.rb
+- examples/run/ctrl_proc_multiple.rb.output
+- examples/run/ctrl_proc_simple.rb
+- examples/run/myserver.rb
+- examples/run/myserver_crashing.rb
+- examples/run/myserver_crashing.rb.output
+- examples/run/myserver_exiting.rb
+has_rdoc: true
+homepage: http://daemons.rubyforge.org
+licenses: []
+
+post_install_message:
+rdoc_options: []
+
+require_paths:
+- lib
+required_ruby_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: "0"
+ version:
+required_rubygems_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: "0"
+ version:
+requirements: []
+
+rubyforge_project: daemons
+rubygems_version: 1.3.5
+signing_key:
+specification_version: 2
+summary: A toolkit to create and control daemons in different ways
+test_files: []
+
View
29 vendor/gems/daemons-1.0.10/LICENSE
@@ -0,0 +1,29 @@
+Copyright (c) 2005-2007 Thomas Uehlinger
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+This license does not apply to daemonize.rb, which is was written by
+Travis Whitton und published under the following license:
+
+The Daemonize extension module is copywrited free software by Travis Whitton
+<whitton@atlantic.net>. You can redistribute it under the terms specified in
+the COPYING file of the Ruby distribution.
View
223 vendor/gems/daemons-1.0.10/README
@@ -0,0 +1,223 @@
+= Daemons Version 1.0.10
+
+(See Releases for release-specific information)
+
+== What is Daemons?
+
+Daemons provides an easy way to wrap existing ruby scripts (for example a self-written server)
+to be <i>run as a daemon</i> and to be <i>controlled by simple start/stop/restart commands</i>.
+
+If you want, you can also use daemons to <i>run blocks of ruby code in a daemon process</i> and to control
+these processes from the main application.
+
+Besides this basic functionality, daemons offers many advanced features like <i>exception backtracing</i>
+and logging (in case your ruby script crashes) and <i>monitoring</i> and automatic restarting of your processes
+if they crash.
+
+Daemons includes the <tt>daemonize.rb</tt> script written by <i>Travis Whitton</i> to do the daemonization
+process.
+
+== Basic Usage
+
+You can use Daemons in four differet ways:
+
+=== 1. Create wrapper scripts for your server scripts or applications
+
+Layout: suppose you have your self-written server <tt>myserver.rb</tt>:
+
+ # this is myserver.rb
+ # it does nothing really useful at the moment
+
+ loop do
+ sleep(5)
+ end
+
+To use <tt>myserver.rb</tt> in a production environment, you need to be able to
+run <tt>myserver.rb</tt> in the _background_ (this means detach it from the console, fork it
+in the background, release all directories and file descriptors).
+
+Just create <tt>myserver_control.rb</tt> like this:
+
+ # this is myserver_control.rb
+
+ require 'rubygems' # if you use RubyGems
+ require 'daemons'
+
+ Daemons.run('myserver.rb')
+
+And use it like this from the console:
+
+ $ ruby myserver_control.rb start
+ (myserver.rb is now running in the background)
+ $ ruby myserver_control.rb restart
+ (...)
+ $ ruby myserver_control.rb stop
+
+For testing purposes you can even run <tt>myserver.rb</tt> <i>without forking</i> in the background:
+
+ $ ruby myserver_control.rb run
+
+An additional nice feature of Daemons is that you can pass <i>additional arguments</i> to the script that
+should be daemonized by seperating them by two _hyphens_:
+
+ $ ruby myserver_control.rb start -- --file=anyfile --a_switch another_argument
+
+
+=== 2. Create wrapper scripts that include your server procs
+
+Layout: suppose you have some code you want to run in the background and control that background process
+from a script:
+
+ # this is your code
+ # it does nothing really useful at the moment
+
+ loop do
+ sleep(5)
+ end
+
+To run this code as a daemon create <tt>myproc_control.rb</tt> like this and include your code:
+
+ # this is myproc_control.rb
+
+ require 'rubygems' # if you use RubyGems
+ require 'daemons'
+
+ Daemons.run_proc('myproc.rb') do
+ loop do
+ sleep(5)
+ end
+ end
+
+And use it like this from the console:
+
+ $ ruby myproc_control.rb start
+ (myproc.rb is now running in the background)
+ $ ruby myproc_control.rb restart
+ (...)
+ $ ruby myproc_control.rb stop
+
+For testing purposes you can even run <tt>myproc.rb</tt> <i>without forking</i> in the background:
+
+ $ ruby myproc_control.rb run
+
+=== 3. Control a bunch of daemons from another application
+
+Layout: you have an application <tt>my_app.rb</tt> that wants to run a bunch of
+server tasks as daemon processes.
+
+ # this is my_app.rb
+
+ require 'rubygems' # if you use RubyGems
+ require 'daemons'
+
+ task1 = Daemons.call(:multiple => true) do
+ # first server task
+
+ loop {
+ conn = accept_conn()
+ serve(conn)
+ }
+ end
+
+ task2 = Daemons.call do
+ # second server task
+
+ loop {
+ something_different()
+ }
+ end
+
+ # the parent process continues to run
+
+ # we can even control our tasks, for example stop them
+ task1.stop
+ task2.stop
+
+ exit
+
+=== 4. Daemonize the currently running process
+
+Layout: you have an application <tt>my_daemon.rb</tt> that wants to run as a daemon
+(but without the ability to be controlled by daemons via start/stop commands)
+
+ # this is my_daemons.rb
+
+ require 'rubygems' # if you use RubyGems
+ require 'daemons'
+
+ # Initialize the app while we're not a daemon
+ init()
+
+ # Become a daemon
+ Daemons.daemonize
+
+ # The server loop
+ loop {
+ conn = accept_conn()
+ serve(conn)
+ }
+
+
+<b>For further documentation, refer to the module documentation of Daemons.</b>
+
+
+== Download and Installation
+
+*Download*: just go to http://rubyforge.org/projects/daemons/
+
+Installation *with* RubyGems:
+ $ su
+ # gem install daemons
+
+Installation *without* RubyGems:
+ $ tar xfz daemons-x.x.x.tar.gz
+ $ cd daemons-x.x.x
+ $ su
+ # ruby setup.rb
+
+== Documentation
+
+For further documentation, refer to the module documentation of Daemons (click on Daemons).
+
+The RDoc documentation is also online at http://daemons.rubyforge.org
+
+
+== Author
+
+Written in 2005-2008 by Thomas Uehlinger <mailto:th.uehlinger@gmx.ch>.
+
+== License
+
+Copyright (c) 2005-2008 Thomas Uehlinger
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+This license does not apply to daemonize.rb, which is was written by
+Travis Whitton und published under the following license:
+
+The Daemonize extension module is copywrited free software by Travis Whitton
+<whitton@atlantic.net>. You can redistribute it under the terms specified in
+the COPYING file of the Ruby distribution.
+
+== Feedback and other resources
+
+At http://rubyforge.org/projects/daemons.
View
84 vendor/gems/daemons-1.0.10/Rakefile
@@ -0,0 +1,84 @@
+require 'rubygems'
+Gem::manage_gems
+
+require 'rake/gempackagetask'
+#require 'rake/testtask'
+require 'rake/packagetask'
+require 'rake/rdoctask'
+
+$LOAD_PATH << './lib'
+require 'daemons'
+
+
+PKG_NAME = "daemons"
+
+PKG_FILES = FileList[
+ "Rakefile", "Releases", "TODO", "README", "LICENSE",
+ "setup.rb",
+ "lib/**/*.rb",
+ #"test/**/*",
+ "examples/**/*"
+]
+#PKG_FILES.exclude(%r(^test/tmp/.+))
+PKG_FILES.exclude(%r(\.pid$))
+PKG_FILES.exclude(%r(\.log$))
+
+spec = Gem::Specification.new do |s|
+ s.name = PKG_NAME
+ s.version = Daemons::VERSION
+ s.author = "Thomas Uehlinger"
+ s.email = "th.uehlinger@gmx.ch"
+ s.rubyforge_project = "daemons"
+ s.homepage = "http://daemons.rubyforge.org"
+ s.platform = Gem::Platform::RUBY
+ s.summary = "A toolkit to create and control daemons in different ways"
+ s.description = <<-EOF
+ Daemons provides an easy way to wrap existing ruby scripts (for example a self-written server)
+ to be run as a daemon and to be controlled by simple start/stop/restart commands.
+
+ You can also call blocks as daemons and control them from the parent or just daemonize the current
+ process.
+
+ Besides this basic functionality, daemons offers many advanced features like exception
+ backtracing and logging (in case your ruby script crashes) and monitoring and automatic
+ restarting of your processes if they crash.
+ EOF
+
+ #s.files = FileList["{test,lib}/**/*"].exclude("rdoc").to_a
+ s.files = PKG_FILES
+ s.require_path = "lib"
+ s.autorequire = "daemons"
+ s.has_rdoc = true
+ s.extra_rdoc_files = ["README", "Releases", "TODO"]
+end
+
+Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.need_tar = true
+end
+
+
+#Rake::PackageTask.new("package") do |p|
+# p.name = PKG_NAME
+# p.version = Daemons::VERSION
+# p.need_tar = true
+# p.need_zip = true
+# p.package_files = PKG_FILES
+#end
+
+
+task :default => [:package]
+
+
+task :upload do
+ sh "scp -r html/* uehli@rubyforge.org:/var/www/gforge-projects/daemons"
+end
+
+
+desc "Create the RDOC html files"
+rd = Rake::RDocTask.new("rdoc") { |rdoc|
+ rdoc.rdoc_dir = 'html'
+ rdoc.title = "Daemons"
+ rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README'
+ rdoc.rdoc_files.include('README', 'TODO', 'Releases')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+}
View
126 vendor/gems/daemons-1.0.10/Releases
@@ -0,0 +1,126 @@
+= Daemons Release History
+
+== Release 1.0.10: November 16, 2007
+
+* By default, we now delete stray pid-files (i.e. pid-files which result for
+ example from a killed daemon) automatically. This function can be deactivated by
+ passing :keep_pid_files => true as an option.
+* All pid files of :multiple daemons new get deleted correctly upon exit of the daemons (reported by Han Holl).
+* Use the signal 'KILL' instead of 'TERM' on Windows platforms.
+* Use exit! in trap('TERM') instead of exit when option :hard_exit is given (thanks to Han Holl).
+* Did some clarification on the exception log.
+
+== Release 1.0.9: October 29, 2007
+
+* fixed a severe bug in the new Pid.running? function: function returned true if the process did not exist (thanks to Jeremy Lawler).
+
+== Release 1.0.8: September 24, 2007
+
+* new Pid.running? function. Checking whether a process exists by sending signal '0' (thanks to Dru Nelson).
+
+== Release 1.0.7: July 7, 2007
+
+* Patch to fix wrong ARGV when using :exec (in def start_exec: Kernel.exec(script(), *(@app_argv || []))) (thanks to Alex McGuire).
+
+== Release 1.0.6: Mai 8, 2007
+
+* New option to pass an ARGV-style array to run and run_proc (thanks to Marc Evans).
+* Additional patches for '/var/log' (thanks to Marc Evans).
+
+== Release 1.0.5: February 24, 2007
+
+* Applied patch that makes daemons to use '/var/log' as logfile
+ directory if you use :dir_mode = :system (thanks to Han Holl).
+* Daemons should now work with Ruby 1.9 (at least the basic features).
+
+== Release 1.0.4: January 17, 2007
+
+* Document the :log_output option (thanks to Andrew Kuklewicz).
+* Set STDOUT.sync = true when redirecting to a logfile (thanks to Andrew Kuklewicz).
+* Should now run also correctly when there is no working 'ps ax' on the system (thanks to Daniel Kehoe).
+
+== Release 1.0.3: November 1, 2006
+
+* Set the app_name correctly also for the monitor process (thanks to Ilya Novoselov).
+
+== Release 1.0.2: September 26, 2006
+
+* Changed the 'ps -ax' call back to 'ps ax'.
+* Fixed the documentation for the :normal :dir_mode.
+* As a default for Daemons.run_proc, the pid file is now saved in the current directory.
+* In :ontop mode for running a proc (this is equal to calling something like 'ruby ctrl_proc.rb run'),
+ the proc now runs directly in the calling script, not in a forked process anymore (thanks to Paul Butcher).
+* Set $0 to app_name in the daemons (thanks to Ilya Novoselov).
+
+== Release 1.0.1: August 30, 2006
+
+* Fixed a regex for parsing the 'ps ax' system call. (thanks to Garance Alistair Drosehn)
+
+== Release 1.0.0: August 29, 2006
+
+* Fix the parsing of the 'ps ax' system call. (thanks to Garance Alistair Drosehn)
+
+== Release 0.4.4: February 14, 2006
+
+* Several fixes that allow us to use the Daemons::Controller
+ with a proc instead of wrapping a script file. This gives us all the
+ PID file management, monitoring, command line options, etc. without having
+ to specify a path to our script which can be tricky, especially when using
+ RubyGems. (thanks to John-Mason Shackelford)
+
+== Release 0.4.3: November 29, 2005
+
+* New Option: You can specify the name of the application with :app_name
+ on calling Daemons.run. This will be used to contruct the name of the pid files
+ and log files. Defaults to the basename of the script. (thanks to Stephen R. Veit)
+
+* Bugfix: Handle the case where no controller options are given when calling Daemons,
+ just options after "--". (thanks to Stephen R. Veit)
+
+
+== Release 0.4.2: November 15, 2005
+
+* Bugfix for problem with :normal pid-file directory mode (pid.rb), fixed (thanks to Stephen R. Veit)
+
+
+== Release 0.4.1: September 11, 2005
+
+* Bugfix for 'run' command line mode: didn't work anymore in 0.4.0, fixed
+
+
+== Release 0.4.0: July 30, 2005
+
+* Two completely new operation modes:
+ 1. Call a block as a daemon (<tt>Daemons.call { my_daemon_code }</tt>)
+ and control it from the parent process.
+ 2. Daemonize the currently running process (<tt>Daemons.daemonize</tt>)
+ plus the already existing mode to control your scripts (<tt>Daemons.run("script.rb")</tt>)
+* Improved documentation (for example "How does the daemonization process work?")
+* Improved "simulation mode" (<tt>:ontop</tt> option)
+* Some minor bugfixes
+
+
+== Release 0.3.0: April 21, 2005
+
+* New monitor functionality: automatic restarting of your applications if they crash
+* 'restart' command fixed
+* '--force' command modifier (please refer to the documentation)
+* Some more bugfixes and improvements
+
+
+== Release 0.2.1: Mar 21, 2005
+
+* Bugfix for a problem with the 'status' command
+
+
+== Release 0.2.0: Mar 21, 2005
+
+* Exception backtrace functionality added
+* Exec functionality added
+* More examples added
+* New commands: status, zap
+
+
+== Release 0.0.1: Feb 8, 2005
+
+* Initial release
View
6 vendor/gems/daemons-1.0.10/TODO
@@ -0,0 +1,6 @@
+* write the README (2005-02-07) *DONE*
+* write some real tests (2005-02-08)
+* document the new options (2005-03-14) *DONE*
+* start/stop with --force options (2005-04-05)
+* option to give some console output on start/stop commands (2005-04-05)
+
View
56 vendor/gems/daemons-1.0.10/examples/call/call.rb
@@ -0,0 +1,56 @@
+lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
+
+if File.exist?(File.join(lib_dir, 'daemons.rb'))
+ $LOAD_PATH.unshift lib_dir
+else
+ begin; require 'rubygems'; rescue ::Exception; end
+end
+
+
+require 'daemons'
+
+testfile = File.expand_path(__FILE__) + '.log'
+
+
+# On the first call to <tt<call</tt>, an application group (accessible by <tt>Daemons.group</tt>)
+# will be created an the options will be kept within, so you only have to specify
+# <tt>:multiple</tt> once.
+#
+
+options = {
+# :ontop => true,
+ :multiple => true
+}
+
+
+Daemons.call(options) do
+ File.open(testfile, 'w') {|f|
+ f.puts "test"
+ }
+
+ loop { puts "1"; sleep 5 }
+end
+puts "first task started"
+
+Daemons.call do
+ loop { puts "2"; sleep 4 }
+end
+puts "second task started"
+
+# NOTE: this process will exit after 5 seconds
+Daemons.call do
+ puts "3"
+ sleep 5
+end
+puts "third task started"
+
+puts "waiting 20 seconds..."
+sleep(20)
+
+# This call would result in an exception as it will try to kill the third process
+# which has already terminated by that time; but using the 'true' parameter forces the
+# stop_all procedure.
+puts "trying to stop all tasks..."
+Daemons.group.stop_all(true)
+
+puts "done"
View
55 vendor/gems/daemons-1.0.10/examples/call/call_monitor.rb
@@ -0,0 +1,55 @@
+lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
+
+if File.exist?(File.join(lib_dir, 'daemons.rb'))
+ $LOAD_PATH.unshift lib_dir
+else
+ begin; require 'rubygems'; rescue ::Exception; end
+end
+
+
+require 'daemons'
+
+testfile = File.expand_path(__FILE__) + '.log'
+
+
+# On the first call to <tt<call</tt>, an application group (accessible by <tt>Daemons.group</tt>)
+# will be created an the options will be kept within, so you only have to specify
+# <tt>:multiple</tt> once.
+#
+
+options = {
+# :ontop => true,
+ :multiple => true,
+ :monitor => true
+}
+
+
+Daemons.call(options) do
+ loop { puts "1"; sleep 20 }
+end
+puts "first task started"
+
+
+# NOTE: this process will exit after 5 seconds
+Daemons.call do
+ File.open(testfile, 'a') {|f|
+ f.puts "started..."
+ puts "2"
+
+ sleep 5
+
+ f.puts "...exit"
+ }
+end
+puts "second task started"
+
+puts "waiting 100 seconds..."
+sleep(100)
+
+# This call would result in an exception as it will try to kill the third process
+# which has already terminated by that time; but using the 'true' parameter forces the
+# stop_all procedure.
+puts "trying to stop all tasks..."
+Daemons.group.stop_all(true)
+
+puts "done"
View
20 vendor/gems/daemons-1.0.10/examples/daemonize/daemonize.rb
@@ -0,0 +1,20 @@
+lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
+
+if File.exist?(File.join(lib_dir, 'daemons.rb'))
+ $LOAD_PATH.unshift lib_dir
+else
+ begin; require 'rubygems'; rescue ::Exception; end
+end
+
+
+
+require 'daemons'
+
+
+testfile = File.expand_path(__FILE__) + '.log'
+
+Daemons.daemonize
+
+File.open(testfile, 'w') {|f|
+ f.write("test")
+}
View
17 vendor/gems/daemons-1.0.10/examples/run/ctrl_crash.rb
@@ -0,0 +1,17 @@
+lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
+
+if File.exist?(File.join(lib_dir, 'daemons.rb'))
+ $LOAD_PATH.unshift lib_dir
+else
+ begin; require 'rubygems'; rescue ::Exception; end
+end
+
+require 'daemons'
+
+
+options = {
+ :log_output => true,
+ :backtrace => true
+}
+
+Daemons.run(File.join(File.dirname(__FILE__), 'myserver_crashing.rb'), options)
View
16 vendor/gems/daemons-1.0.10/examples/run/ctrl_exec.rb
@@ -0,0 +1,16 @@
+lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
+
+if File.exist?(File.join(lib_dir, 'daemons.rb'))
+ $LOAD_PATH.unshift lib_dir
+else
+ begin; require 'rubygems'; rescue ::Exception; end
+end
+
+require 'daemons'
+
+
+options = {
+ :mode => :exec
+}
+
+Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options)
View
15 vendor/gems/daemons-1.0.10/examples/run/ctrl_exit.rb
@@ -0,0 +1,15 @@
+lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
+
+if File.exist?(File.join(lib_dir, 'daemons.rb'))
+ $LOAD_PATH.unshift lib_dir
+else
+ begin; require 'rubygems'; rescue ::Exception; end
+end
+
+require 'daemons'
+
+
+options = {
+}
+
+Daemons.run(File.join(File.dirname(__FILE__), 'myserver_exiting.rb'), options)
View
17 vendor/gems/daemons-1.0.10/examples/run/ctrl_keep_pid_files.rb
@@ -0,0 +1,17 @@
+lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
+
+if File.exist?(File.join(lib_dir, 'daemons.rb'))
+ $LOAD_PATH.unshift lib_dir
+else
+ begin; require 'rubygems'; rescue ::Exception; end
+end
+
+require 'daemons'
+
+
+options = {
+ :keep_pid_files => true
+}
+
+
+Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options)
View
16 vendor/gems/daemons-1.0.10/examples/run/ctrl_monitor.rb
@@ -0,0 +1,16 @@
+lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
+
+if File.exist?(File.join(lib_dir, 'daemons.rb'))
+ $LOAD_PATH.unshift lib_dir
+else
+ begin; require 'rubygems'; rescue ::Exception; end
+end
+
+require 'daemons'
+
+
+options = {
+ :monitor => true
+}
+
+Daemons.run(File.join(File.dirname(__FILE__), 'myserver_crashing.rb'), options)
View
16 vendor/gems/daemons-1.0.10/examples/run/ctrl_multiple.rb
@@ -0,0 +1,16 @@
+lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
+
+if File.exist?(File.join(lib_dir, 'daemons.rb'))
+ $LOAD_PATH.unshift lib_dir
+else
+ begin; require 'rubygems'; rescue ::Exception; end
+end
+
+require 'daemons'
+
+
+options = {
+ :multiple => true
+}
+
+Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options)
View
12 vendor/gems/daemons-1.0.10/examples/run/ctrl_normal.rb
@@ -0,0 +1,12 @@
+lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
+
+if File.exist?(File.join(lib_dir, 'daemons.rb'))
+ $LOAD_PATH.unshift lib_dir
+else
+ begin; require 'rubygems'; rescue ::Exception; end
+end
+
+require 'daemons'
+
+
+Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'))
View
16 vendor/gems/daemons-1.0.10/examples/run/ctrl_ontop.rb
@@ -0,0 +1,16 @@
+lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
+
+if File.exist?(File.join(lib_dir, 'daemons.rb'))
+ $LOAD_PATH.unshift lib_dir
+else
+ begin; require 'rubygems'; rescue ::Exception; end
+end
+
+require 'daemons'
+
+
+options = {
+ :ontop => true
+}
+
+Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options)
View
43 vendor/gems/daemons-1.0.10/examples/run/ctrl_optionparser.rb
@@ -0,0 +1,43 @@
+lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
+
+if File.exist?(File.join(lib_dir, 'daemons.rb'))
+ $LOAD_PATH.unshift lib_dir
+else
+ begin; require 'rubygems'; rescue ::Exception; end
+end
+
+require 'daemons'
+require 'optparse'
+require 'logger'
+require 'ostruct'
+
+
+class MyApp < Logger::Application
+ def initialize(args)
+ super(self.class)
+ @options = OpenStruct.new(:daemonize => true)
+ opts = OptionParser.new do |opts|
+ opts.banner = 'Usage: myapp [options]'
+ opts.separator ''
+ opts.on('-N','--no-daemonize',"Don't run as a daemon") do
+ @options.daemonize = false
+ end
+ end
+ @args = opts.parse!(args)
+ end
+
+ def run
+ Daemons.run_proc('myapp',{:ARGV => @args, :ontop => !@options.daemonize}) do
+ puts "@options.daemonize: #{@options.daemonize}"
+ STDOUT.sync = true
+ loop do
+ print '.'
+ sleep(2)
+ end
+ end
+ end
+end
+
+
+myapp = MyApp.new(ARGV)
+myapp.run
View
25 vendor/gems/daemons-1.0.10/examples/run/ctrl_proc.rb
@@ -0,0 +1,25 @@
+lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
+
+if File.exist?(File.join(lib_dir, 'daemons.rb'))
+ $LOAD_PATH.unshift lib_dir
+else
+ begin; require 'rubygems'; rescue ::Exception; end
+end
+
+require 'daemons'
+
+
+options = {
+ :multiple => false,
+ :ontop => false,
+ :backtrace => true,
+ :log_output => true,
+ :monitor => true
+ }
+
+Daemons.run_proc('ctrl_proc.rb', options) do
+ loop do
+ puts 'ping from proc!'
+ sleep(3)
+ end
+end
View
101 vendor/gems/daemons-1.0.10/examples/run/ctrl_proc.rb.output
@@ -0,0 +1,101 @@
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
+ping from proc!
View
22 vendor/gems/daemons-1.0.10/examples/run/ctrl_proc_multiple.rb
@@ -0,0 +1,22 @@
+lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
+
+if File.exist?(File.join(lib_dir, 'daemons.rb'))
+ $LOAD_PATH.unshift lib_dir
+else
+ begin; require 'rubygems'; rescue ::Exception; end
+end
+
+require 'daemons'
+
+
+options = {
+ :log_output => true,
+ :multiple => true,
+}
+
+
+Daemons.run_proc('ctrl_proc_multiple.rb', options) do
+ puts "hello"
+ sleep(5)
+ puts "done"
+end
View
2 vendor/gems/daemons-1.0.10/examples/run/ctrl_proc_multiple.rb.output
@@ -0,0 +1,2 @@
+
+hello
View
17 vendor/gems/daemons-1.0.10/examples/run/ctrl_proc_simple.rb
@@ -0,0 +1,17 @@
+lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
+
+if File.exist?(File.join(lib_dir, 'daemons.rb'))
+ $LOAD_PATH.unshift lib_dir
+else
+ begin; require 'rubygems'; rescue ::Exception; end
+end
+
+require 'daemons'
+
+
+Daemons.run_proc('ctrl_proc_simple.rb') do
+ loop do
+ puts 'ping from proc!'
+ sleep(3)
+ end
+end
View
12 vendor/gems/daemons-1.0.10/examples/run/myserver.rb
@@ -0,0 +1,12 @@
+#!/usr/bin/env ruby
+
+
+# This is myserver.rb, an example server that is to be controlled by daemons
+# and that does nothing really useful at the moment.
+#
+# Don't run this script by yourself, it can be controlled by the ctrl*.rb scripts.
+
+loop do
+ puts 'ping from myserver.rb!'
+ sleep(3)
+end
View
14 vendor/gems/daemons-1.0.10/examples/run/myserver_crashing.rb
@@ -0,0 +1,14 @@
+# This is myserver.rb, an example server that is to be controlled by daemons
+# and that does nothing really useful at the moment.
+#
+# Don't run this script by yourself, it can be controlled by the ctrl*.rb scripts.
+
+loop do
+ puts 'ping from myserver.rb!'
+ puts 'this example server will crash in 3 seconds...'
+
+ sleep(3)
+
+ puts 'CRASH!'
+ raise 'CRASH!'
+end
View
30 vendor/gems/daemons-1.0.10/examples/run/myserver_crashing.rb.output
@@ -0,0 +1,30 @@
+/home/uehli/Desktop/daemons-current/examples/myserver_crashing.rb:13: CRASH! (RuntimeError)
+ from /home/uehli/Desktop/daemons-current/examples/myserver_crashing.rb:6:in `loop'
+ from /home/uehli/Desktop/daemons-current/examples/myserver_crashing.rb:6
+ from /home/uehli/Desktop/daemons-current/lib/daemons.rb:116:in `load'
+ from /home/uehli/Desktop/daemons-current/lib/daemons.rb:116:in `run_via_load'
+ from /home/uehli/Desktop/daemons-current/lib/daemons.rb:90:in `start'
+ from /home/uehli/Desktop/daemons-current/lib/daemons.rb:359:in `run'
+ from /home/uehli/Desktop/daemons-current/lib/daemons.rb:469:in `run'
+ from /home/uehli/Desktop/daemons-current/lib/daemons.rb:468:in `call'
+ from /home/uehli/Desktop/daemons-current/lib/daemons/cmdline.rb:94:in `catch_exceptions'
+ from /home/uehli/Desktop/daemons-current/lib/daemons.rb:468:in `run'
+ from ctrl_crash.rb:17
+ping from myserver.rb!
+this example server will crash in 3 seconds...
+CRASH!
+ping from myserver.rb!
+this example server will crash in 3 seconds...
+CRASH!
+/Users/uehli/Projects/daemons-proj/examples/run/myserver_crashing.rb:13: CRASH! (RuntimeError)
+ from /Users/uehli/Projects/daemons-proj/examples/run/myserver_crashing.rb:6:in `loop'
+ from /Users/uehli/Projects/daemons-proj/examples/run/myserver_crashing.rb:6
+ from /Users/uehli/Projects/daemons-proj/lib/daemons/application.rb:176:in `load'
+ from /Users/uehli/Projects/daemons-proj/lib/daemons/application.rb:176:in `start_load'
+ from /Users/uehli/Projects/daemons-proj/lib/daemons/application.rb:257:in `start'
+ from /Users/uehli/Projects/daemons-proj/lib/daemons/controller.rb:69:in `run'
+ from /Users/uehli/Projects/daemons-proj/lib/daemons.rb:139:in `run'
+ from /Users/uehli/Projects/daemons-proj/lib/daemons/cmdline.rb:105:in `call'
+ from /Users/uehli/Projects/daemons-proj/lib/daemons/cmdline.rb:105:in `catch_exceptions'
+ from /Users/uehli/Projects/daemons-proj/lib/daemons.rb:138:in `run'
+ from ctrl_crash.rb:17
View
8 vendor/gems/daemons-1.0.10/examples/run/myserver_exiting.rb
@@ -0,0 +1,8 @@
+loop do
+ puts 'ping from myserver.rb!'
+ puts 'this example server will exit in 3 seconds...'
+
+ sleep(3)
+
+ Process.exit
+end
View
283 vendor/gems/daemons-1.0.10/lib/daemons.rb
@@ -0,0 +1,283 @@
+require 'optparse'
+require 'optparse/time'
+
+
+require 'daemons/pidfile'
+require 'daemons/cmdline'
+require 'daemons/exceptions'
+require 'daemons/monitor'
+
+
+require 'daemons/application'
+require 'daemons/application_group'
+require 'daemons/controller'
+
+
+# All functions and classes that Daemons provides reside in this module.
+#
+# Daemons is normally invoked by one of the following four ways:
+#
+# 1. <tt>Daemons.run(script, options)</tt>:
+# This is used in wrapper-scripts that are supposed to control other ruby scripts or
+# external applications. Control is completely passed to the daemons library.
+# Such wrapper script need to be invoked with command line options like 'start' or 'stop'
+# to do anything useful.
+#
+# 2. <tt>Daemons.run_proc(app_name, options) { (...) }</tt>:
+# This is used in wrapper-scripts that are supposed to control a proc.
+# Control is completely passed to the daemons library.
+# Such wrapper script need to be invoked with command line options like 'start' or 'stop'
+# to do anything useful.
+#
+# 3. <tt>Daemons.call(options) { block }</tt>:
+# Execute the block in a new daemon. <tt>Daemons.call</tt> will return immediately
+# after spawning the daemon with the new Application object as a return value.
+#
+# 4. <tt>Daemons.daemonize(options)</tt>:
+# Daemonize the currently runnig process, i.e. the calling process will become a daemon.
+#
+# == What does daemons internally do with my daemons?
+# *or*:: why do my daemons crash when they try to open a file?
+# *or*:: why can I not see any output from the daemon on the console (when using for example +puts+)?
+#
+# From a technical aspect of view, daemons does the following when creating a daemon:
+#
+# 1. Forks a child (and exits the parent process, if needed)
+# 2. Becomes a session leader (which detaches the program from
+# the controlling terminal).
+# 3. Forks another child process and exits first child. This prevents
+# the potential of acquiring a controlling terminal.
+# 4. Changes the current working directory to "/".
+# 5. Clears the file creation mask (sets +umask+ to 0000).
+# 6. Closes file descriptors (reopens +STDOUT+ and +STDERR+ to point to a logfile if
+# possible).
+#
+# So what does this mean for your daemons:
+# - the current directory is '/'
+# - you cannot receive any input from the console (for example no +gets+)
+# - you cannot output anything from the daemons with +puts+/+print+ unless a logfile is used
+#
+# == How do PidFiles work? Where are they stored?
+#
+# Also, you are maybe interested in reading the documentation for the class PidFile.
+# There you can find out about how Daemons works internally and how and where the so
+# called <i>PidFiles</i> are stored.
+#
+module Daemons
+
+ VERSION = "1.0.10"
+
+ require 'daemons/daemonize'
+
+
+ # Passes control to Daemons.
+ # This is used in wrapper-scripts that are supposed to control other ruby scripts or
+ # external applications. Control is completely passed to the daemons library.
+ # Such wrapper script should be invoked with command line options like 'start' or 'stop'
+ # to do anything useful.
+ #
+ # +script+:: This is the path to the script that should be run as a daemon.
+ # Please note that Daemons runs this script with <tt>load <script></tt>.
+ # Also note that Daemons cannot detect the directory in which the controlling
+ # script resides, so this has to be either an absolute path or you have to run
+ # the controlling script from the appropriate directory.
+ #
+ # +options+:: A hash that may contain one or more of the options listed below
+ #
+ # === Options:
+ # <tt>:app_name</tt>:: The name of the application. This will be
+ # used to contruct the name of the pid files
+ # and log files. Defaults to the basename of
+ # the script.
+ # <tt>:ARGV</tt>:: An array of strings containing parameters and switches for Daemons.
+ # This includes both parameters for Daemons itself and the controlled scripted.
+ # These are assumed to be separated by an array element '--', .e.g.
+ # ['start', 'f', '--', 'param1_for_script', 'param2_for_script'].
+ # If not given, ARGV (the parameters given to the Ruby process) will be used.
+ # <tt>:dir_mode</tt>:: Either <tt>:script</tt> (the directory for writing the pid files to
+ # given by <tt>:dir</tt> is interpreted relative
+ # to the script location given by +script+) or <tt>:normal</tt> (the directory given by
+ # <tt>:dir</tt> is interpreted as a (absolute or relative) path) or <tt>:system</tt>
+ # (<tt>/var/run</tt> is used as the pid file directory)
+ #
+ # <tt>:dir</tt>:: Used in combination with <tt>:dir_mode</tt> (description above)
+ # <tt>:multiple</tt>:: Specifies whether multiple instances of the same script are allowed to run at the
+ # same time
+ # <tt>:ontop</tt>:: When given (i.e. set to true), stay on top, i.e. do not daemonize the application
+ # (but the pid-file and other things are written as usual)
+ # <tt>:mode</tt>:: <tt>:load</tt> Load the script with <tt>Kernel.load</tt>;
+ # <tt>:exec</tt> Execute the script file with <tt>Kernel.exec</tt>
+ # <tt>:backtrace</tt>:: Write a backtrace of the last exceptions to the file '[app_name].log' in the
+ # pid-file directory if the application exits due to an uncaught exception
+ # <tt>:monitor</tt>:: Monitor the programs and restart crashed instances
+ # <tt>:log_output</tt>:: When given (i.e. set to true), redirect both STDOUT and STDERR to a logfile named '[app_name].output' in the pid-file directory
+ # <tt>:keep_pid_files</tt>:: When given do not delete lingering pid-files (files for which the process is no longer running).
+ # <tt>:hard_exit</tt>:: When given use exit! to end a daemons instead of exit (this will for example
+ # not call at_exit handlers).
+ # -----
+ #
+ # === Example:
+ # options = {
+ # :app_name => "my_app",
+ # :ARGV => ['start', '-f', '--', 'param_for_myscript']
+ # :dir_mode => :script,
+ # :dir => 'pids',
+ # :multiple => true,
+ # :ontop => true,
+ # :mode => :exec,
+ # :backtrace => true,
+ # :monitor => true
+ # }
+ #
+ # Daemons.run(File.join(File.dirname(__FILE__), 'myscript.rb'), options)
+ #
+ def run(script, options = {})
+ options[:script] = script
+ @controller = Controller.new(options, options[:ARGV] || ARGV)
+
+ @controller.catch_exceptions {
+ @controller.run
+ }
+
+ # I don't think anybody will ever use @group, as this location should not be reached under non-error conditions
+ @group = @controller.group
+ end
+ module_function :run
+
+
+ # Passes control to Daemons.
+ # This function does the same as Daemons.run except that not a script but a proc
+ # will be run as a daemon while this script provides command line options like 'start' or 'stop'
+ # and the whole pid-file management to control the proc.
+ #
+ # +app_name+:: The name of the application. This will be
+ # used to contruct the name of the pid files
+ # and log files. Defaults to the basename of
+ # the script.
+ #
+ # +options+:: A hash that may contain one or more of the options listed in the documentation for Daemons.run
+ #
+ # A block must be given to this function. The block will be used as the :proc entry in the options hash.
+ # -----
+ #
+ # === Example:
+ #
+ # Daemons.run_proc('myproc.rb') do
+ # loop do
+ # accept_connection()
+ # read_request()
+ # send_response()
+ # close_connection()
+ # end
+ # end
+ #
+ def run_proc(app_name, options = {}, &block)
+ options[:app_name] = app_name
+ options[:mode] = :proc
+ options[:proc] = block
+
+ # we do not have a script location so the the :script :dir_mode cannot be used, change it to :normal
+ if [nil, :script].include? options[:dir_mode]
+ options[:dir_mode] = :normal
+ options[:dir] = File.expand_path('.')
+ end
+
+ @controller = Controller.new(options, options[:ARGV] || ARGV)
+
+ @controller.catch_exceptions {
+ @controller.run
+ }
+
+ # I don't think anybody will ever use @group, as this location should not be reached under non-error conditions
+ @group = @controller.group
+ end
+ module_function :run_proc
+
+
+ # Execute the block in a new daemon. <tt>Daemons.call</tt> will return immediately
+ # after spawning the daemon with the new Application object as a return value.
+ #
+ # +options+:: A hash that may contain one or more of the options listed below
+ #
+ # +block+:: The block to call in the daemon.
+ #
+ # === Options:
+ # <tt>:multiple</tt>:: Specifies whether multiple instances of the same script are allowed to run at the
+ # same time
+ # <tt>:ontop</tt>:: When given, stay on top, i.e. do not daemonize the application
+ # <tt>:backtrace</tt>:: Write a backtrace of the last exceptions to the file '[app_name].log' in the
+ # pid-file directory if the application exits due to an uncaught exception
+ # -----
+ #
+ # === Example:
+ # options = {
+ # :backtrace => true,
+ # :monitor => true,
+ # :ontop => true
+ # }
+ #
+ # Daemons.call(options) begin
+ # # Server loop:
+ # loop {
+ # conn = accept_conn()
+ # serve(conn)
+ # }
+ # end
+ #
+ def call(options = {}, &block)
+ unless block_given?
+ raise "Daemons.call: no block given"
+ end
+
+ options[:proc] = block
+ options[:mode] = :proc
+
+ @group ||= ApplicationGroup.new('proc', options)
+
+ new_app = @group.new_application(options)
+ new_app.start
+
+ return new_app
+ end
+ module_function :call
+
+
+ # Daemonize the currently runnig process, i.e. the calling process will become a daemon.
+ #
+ # +options+:: A hash that may contain one or more of the options listed below
+ #
+ # === Options:
+ # <tt>:ontop</tt>:: When given, stay on top, i.e. do not daemonize the application
+ # <tt>:backtrace</tt>:: Write a backtrace of the last exceptions to the file '[app_name].log' in the
+ # pid-file directory if the application exits due to an uncaught exception
+ # -----
+ #
+ # === Example:
+ # options = {
+ # :backtrace => true,
+ # :ontop => true
+ # }
+ #
+ # Daemons.daemonize(options)
+ #
+ # # Server loop:
+ # loop {
+ # conn = accept_conn()
+ # serve(conn)
+ # }
+ #
+ def daemonize(options = {})
+ @group ||= ApplicationGroup.new('self', options)
+
+ @group.new_application(:mode => :none).start
+ end
+ module_function :daemonize
+
+ # Return the internal ApplicationGroup instance.
+ def group; @group; end
+ module_function :group
+
+ # Return the internal Controller instance.
+ def controller; @controller; end
+ module_function :controller
+end
View
372 vendor/gems/daemons-1.0.10/lib/daemons/application.rb
@@ -0,0 +1,372 @@
+require 'daemons/pidfile'
+require 'daemons/pidmem'
+
+
+module Daemons
+
+ class Application
+
+ attr_accessor :app_argv
+ attr_accessor :controller_argv
+
+ # the Pid instance belonging to this application
+ attr_reader :pid
+
+ # the ApplicationGroup the application belongs to
+ attr_reader :group
+
+ # my private options
+ attr_reader :options
+
+
+ SIGNAL = (RUBY_PLATFORM =~ /win32/ ? 'KILL' : 'TERM')
+
+
+ def initialize(group, add_options = {}, pid = nil)
+ @group = group
+ @options = group.options.dup
+ @options.update(add_options)
+
+ @dir_mode = @dir = @script = nil
+
+ unless @pid = pid
+ if dir = pidfile_dir
+ @pid = PidFile.new(dir, @group.app_name, @group.multiple)
+ else
+ @pid = PidMem.new
+ end
+ end
+ end
+
+ def script
+ @script || @group.script
+ end
+
+ def pidfile_dir
+ Pid.dir(@dir_mode || @group.dir_mode, @dir || @group.dir, @script || @group.script)
+ end
+
+ def output_logfile
+ logdir = options[:dir_mode] == :system ? '/var/log' : pidfile_dir
+ (options[:log_output] && logdir) ? File.join(logdir, @group.app_name + '.output') : nil
+ end
+
+ def logfile
+ logdir = options[:dir_mode] == :system ? '/var/log' : pidfile_dir
+ logdir ? File.join(logdir, @group.app_name + '.log') : nil
+ end
+
+ # this function is only used to daemonize the currently running process (Daemons.daemonize)
+ def start_none
+ unless options[:ontop]
+ Daemonize.daemonize(nil, @group.app_name) #(logfile)
+ else
+ Daemonize.simulate
+ end
+
+ @pid.pid = Process.pid
+
+
+ # We need this to remove the pid-file if the applications exits by itself.
+ # Note that <tt>at_text</tt> will only be run if the applications exits by calling
+ # <tt>exit</tt>, and not if it calls <tt>exit!</tt> (so please don't call <tt>exit!</tt>
+ # in your application!
+ #
+ at_exit {
+ begin; @pid.cleanup; rescue ::Exception; end
+
+ # If the option <tt>:backtrace</tt> is used and the application did exit by itself
+ # create a exception log.
+ if options[:backtrace] and not options[:ontop] and not $daemons_sigterm
+ begin; exception_log(); rescue ::Exception; end
+ end
+
+ }
+
+ # This part is needed to remove the pid-file if the application is killed by
+ # daemons or manually by the user.
+ # Note that the applications is not supposed to overwrite the signal handler for
+ # 'TERM'.
+ #
+ trap(SIGNAL) {
+ begin; @pid.cleanup; rescue ::Exception; end
+ $daemons_sigterm = true
+
+ if options[:hard_exit]
+ exit!
+ else
+ exit
+ end
+ }
+ end
+
+ def start_exec
+ if options[:backtrace]
+ puts "option :backtrace is not supported with :mode => :exec, ignoring"
+ end
+
+ unless options[:ontop]
+ Daemonize.daemonize(output_logfile, @group.app_name)
+ else
+ Daemonize.simulate(output_logfile)
+ end
+
+ # note that we cannot remove the pid file if we run in :ontop mode (i.e. 'ruby ctrl_exec.rb run')
+ @pid.pid = Process.pid
+
+ ENV['DAEMONS_ARGV'] = @controller_argv.join(' ')
+ # haven't tested yet if this is really passed to the exec'd process...
+
+
+
+ Kernel.exec(script(), *(@app_argv || []))
+ #Kernel.exec(script(), *ARGV)
+ end
+
+ def start_load
+ unless options[:ontop]
+ Daemonize.daemonize(output_logfile, @group.app_name)
+ else
+ Daemonize.simulate(output_logfile)
+ end
+
+ @pid.pid = Process.pid
+
+
+ # We need this to remove the pid-file if the applications exits by itself.
+ # Note that <tt>at_text</tt> will only be run if the applications exits by calling
+ # <tt>exit</tt>, and not if it calls <tt>exit!</tt> (so please don't call <tt>exit!</tt>
+ # in your application!
+ #
+ at_exit {
+ begin; @pid.cleanup; rescue ::Exception; end
+
+ # If the option <tt>:backtrace</tt> is used and the application did exit by itself
+ # create a exception log.
+ if options[:backtrace] and not options[:ontop] and not $daemons_sigterm
+ begin; exception_log(); rescue ::Exception; end
+ end
+
+ }
+
+ # This part is needed to remove the pid-file if the application is killed by
+ # daemons or manually by the user.
+ # Note that the applications is not supposed to overwrite the signal handler for
+ # 'TERM'.
+ #
+ trap(SIGNAL) {
+ begin; @pid.cleanup; rescue ::Exception; end
+ $daemons_sigterm = true
+
+ if options[:hard_exit]
+ exit!
+ else
+ exit
+ end
+ }
+
+ # Now we really start the script...
+ $DAEMONS_ARGV = @controller_argv
+ ENV['DAEMONS_ARGV'] = @controller_argv.join(' ')
+
+ ARGV.clear
+ ARGV.concat @app_argv if @app_argv
+
+ # TODO: begin - rescue - end around this and exception logging
+ load script()
+ end
+
+ def start_proc
+ return unless p = options[:proc]
+
+ myproc = proc do
+ # We need this to remove the pid-file if the applications exits by itself.
+ # Note that <tt>at_text</tt> will only be run if the applications exits by calling
+ # <tt>exit</tt>, and not if it calls <tt>exit!</tt> (so please don't call <tt>exit!</tt>
+ # in your application!
+ #
+ at_exit {
+ begin; @pid.cleanup; rescue ::Exception; end
+
+ # If the option <tt>:backtrace</tt> is used and the application did exit by itself
+ # create a exception log.
+ if options[:backtrace] and not options[:ontop] and not $daemons_sigterm
+ begin; exception_log(); rescue ::Exception; end
+ end
+
+ }
+
+ # This part is needed to remove the pid-file if the application is killed by
+ # daemons or manually by the user.
+ # Note that the applications is not supposed to overwrite the signal handler for
+ # 'TERM'.
+ #
+ trap(SIGNAL) {
+ begin; @pid.cleanup; rescue ::Exception; end
+ $daemons_sigterm = true
+
+ if options[:hard_exit]
+ exit!
+ else
+ exit
+ end
+ }
+
+ p.call()
+ end
+
+ unless options[:ontop]
+ @pid.pid = Daemonize.call_as_daemon(myproc, output_logfile, @group.app_name)
+ else
+ Daemonize.simulate(output_logfile)
+
+ @pid.pid = Process.pid
+
+ myproc.call
+
+# why did we use this??
+# Thread.new(&options[:proc])
+
+# why did we use the code below??
+ # unless pid = Process.fork
+ # @pid.pid = pid
+ # Daemonize.simulate(logfile)
+ # options[:proc].call
+ # exit
+ # else
+ # Process.detach(@pid.pid)
+ # end
+ end
+ end
+
+
+ def start
+ @group.create_monitor(@group.applications[0] || self) unless options[:ontop] # we don't monitor applications in the foreground
+
+ case options[:mode]
+ when :none
+ # this is only used to daemonize the currently running process
+ start_none
+ when :exec
+ start_exec
+ when :load
+ start_load
+ when :proc
+ start_proc
+ else
+ start_load
+ end
+ end
+
+# def run
+# if @group.controller.options[:exec]
+# run_via_exec()
+# else
+# run_via_load()
+# end
+# end
+#
+# def run_via_exec
+#
+# end
+#
+# def run_via_load
+#
+# end
+
+
+ # This is a nice little function for debugging purposes:
+ # In case a multi-threaded ruby script exits due to an uncaught exception
+ # it may be difficult to find out where the exception came from because
+ # one cannot catch exceptions that are thrown in threads other than the main
+ # thread.
+ #
+ # This function searches for all exceptions in memory and outputs them to STDERR
+ # (if it is connected) and to a log file in the pid-file directory.
+ #
+ def exception_log
+ return unless logfile
+
+ require 'logger'
+
+ l_file = Logger.new(logfile)
+
+ # the code below finds the last exception
+ e = nil
+
+ ObjectSpace.each_object {|o|
+ if ::Exception === o
+ e = o
+ end
+ }
+
+ l_file.info "*** below you find the most recent exception thrown, this will be likely (but not certainly) the exception that made the application exit abnormally ***"
+ l_file.error e
+
+ l_file.info "*** below you find all exception objects found in memory, some of them may have been thrown in your application, others may just be in memory because they are standard exceptions ***"
+
+ # this code logs every exception found in memory
+ ObjectSpace.each_object {|o|
+ if ::Exception === o
+ l_file.error o
+ end
+ }
+
+ l_file.close
+ end
+
+
+ def stop
+ if options[:force] and not running?
+ self.zap
+ return
+ end
+
+ # Catch errors when trying to kill a process that doesn't
+ # exist. This happens when the process quits and hasn't been
+ # restarted by the monitor yet. By catching the error, we allow the
+ # pid file clean-up to occur.
+ begin
+ Process.kill(SIGNAL, @pid.pid)
+ rescue Errno::ESRCH => e
+ puts "#{e} #{@pid.pid}"
+ puts "deleting pid-file."
+ end
+
+ # We try to remove the pid-files by ourselves, in case the application
+ # didn't clean it up.
+ begin; @pid.cleanup; rescue ::Exception; end
+
+ end
+
+ def zap
+ @pid.cleanup
+ end
+
+ def zap!
+ begin; @pid.cleanup; rescue ::Exception; end
+ end
+
+ def show_status
+ running = self.running?
+
+ puts "#{self.group.app_name}: #{running ? '' : 'not '}running#{(running and @pid.exist?) ? ' [pid ' + @pid.pid.to_s + ']' : ''}#{(@pid.exist? and not running) ? ' (but pid-file exists: ' + @pid.pid.to_s + ')' : ''}"
+ end
+
+ # This function implements a (probably too simle) method to detect
+ # whether the program with the pid found in the pid-file is still running.
+ # It just searches for the pid in the output of <tt>ps ax</tt>, which
+ # is probably not a good idea in some cases.
+ # Alternatives would be to use a direct access method the unix process control
+ # system.
+ #
+ def running?
+ if @pid.exist?
+ return Pid.running?(@pid.pid)
+ end
+
+ return false
+ end
+ end
+
+end
View
152 vendor/gems/daemons-1.0.10/lib/daemons/application_group.rb
@@ -0,0 +1,152 @@
+
+module Daemons
+ class ApplicationGroup
+
+ attr_reader :app_name
+ attr_reader :script
+
+ attr_reader :monitor
+
+ #attr_reader :controller
+
+ attr_reader :options
+
+ attr_reader :applications
+
+ attr_accessor :controller_argv
+ attr_accessor :app_argv
+
+ attr_accessor :dir_mode
+ attr_accessor :dir
+
+ # true if the application is supposed to run in multiple instances
+ attr_reader :multiple
+
+
+ def initialize(app_name, options = {})
+ @app_name = app_name
+ @options = options
+
+ if options[:script]
+ @script = File.expand_path(options[:script])
+ end
+
+ #@controller = controller
+ @monitor = nil
+
+ #options = controller.options
+
+ @multiple = options[:multiple] || false
+
+ @dir_mode = options[:dir_mode] || :script
+ @dir = options[:dir] || ''
+
+ @keep_pid_files = options[:keep_pid_files] || false
+
+ #@applications = find_applications(pidfile_dir())
+ @applications = []
+ end
+
+ # Setup the application group.
+ # Currently this functions calls <tt>find_applications</tt> which finds
+ # all running instances of the application and populates the application array.
+ #
+ def setup
+ @applications = find_applications(pidfile_dir())
+ end
+
+ def pidfile_dir
+ PidFile.dir(@dir_mode, @dir, script)
+ end
+
+ def find_applications(dir)
+ pid_files = PidFile.find_files(dir, app_name, ! @keep_pid_files)
+
+ #pp pid_files
+
+ @monitor = Monitor.find(dir, app_name + '_monitor')
+
+ pid_files.reject! {|f| f =~ /_monitor.pid$/}
+
+ return pid_files.map {|f|
+ app = Application.new(self, {}, PidFile.existing(f))
+ setup_app(app)
+ app
+ }
+ end
+
+ def new_application(add_options = {})
+ if @applications.size > 0 and not @multiple
+ if options[:force]
+ @applications.delete_if {|a|
+ unless a.running?
+ a.zap
+ true
+ end
+ }
+ end
+
+ raise RuntimeException.new('there is already one or more instance(s) of the program running') unless @applications.empty?
+ end
+
+ app = Application.new(self, add_options)
+
+ setup_app(app)
+
+ @applications << app
+
+ return app
+ end
+
+ def setup_app(app)
+ app.controller_argv = @controller_argv
+ app.app_argv = @app_argv
+ end
+ private :setup_app
+
+ def create_monitor(an_app)
+ return if @monitor
+
+ if options[:monitor]
+ @monitor = Monitor.new(an_app)
+
+ @monitor.start(@applications)
+ end
+ end
+
+ def start_all
+ @monitor.stop if @monitor
+ @monitor = nil
+
+ @applications.each {|a|
+ fork {
+ a.start
+ }
+ }
+ end
+
+ def stop_all(force = false)
+ @monitor.stop if @monitor
+
+ @applications.each {|a|
+ if force
+ begin; a.stop; rescue ::Exception; end
+ else
+ a.stop
+ end
+ }
+ end
+
+ def zap_all
+ @monitor.stop if @monitor
+
+ @applications.each {|a| a.zap}
+ end
+
+ def show_status
+ @applications.each {|a| a.show_status}
+ end
+
+ end
+
+end
View
117 vendor/gems/daemons-1.0.10/lib/daemons/cmdline.rb
@@ -0,0 +1,117 @@
+
+module Daemons
+
+ class Optparse
+
+ attr_reader :usage
+
+ def initialize(controller)
+ @controller = controller
+ @options = {}
+
+ @opts = OptionParser.new do |opts|
+ #opts.banner = "Usage: example.rb [options]"
+ opts.banner = ""
+
+ # Boolean switch.
+# opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
+# @options[:verbose] = v
+# end
+
+ opts.on("-t", "--ontop", "Stay on top (does not daemonize)") do |t|
+ @options[:ontop] = t
+ end
+
+ opts.on("-f", "--force", "Force operation") do |t|
+ @options[:force] = t
+ end
+
+ #opts.separator ""
+ #opts.separator "Specific options:"
+
+
+ opts.separator ""
+ opts.separator "Common options:"
+
+ # No argument, shows at tail. This will print an options summary.
+ # Try it and see!
+ opts.on_tail("-h", "--help", "Show this message") do
+ #puts opts
+ #@usage =
+ controller.print_usage()
+
+ exit
+ end
+
+ # Another typical switch to print the version.
+ opts.on_tail("--version", "Show version") do
+ puts "daemons version #{Daemons::VERSION}"
+ exit
+ end
+ end
+
+ begin
+ @usage = @opts.to_s
+ rescue ::Exception # work around a bug in ruby 1.9
+ @usage = <<END
+ -t, --ontop Stay on top (does not daemonize)
+ -f, --force Force operation
+
+ Common options:
+ -h, --help Show this message
+ --version Show version
+END
+ end
+ end
+
+
+ #
+ # Return a hash describing the options.
+ #
+ def parse(args)
+ # The options specified on the command line will be collected in *options*.
+ # We set default values here.
+ #options = {}
+
+
+ ##pp args
+ @opts.parse(args)
+
+ return @options
+ end
+
+ end
+
+
+ class Controller
+
+ def print_usage
+ puts "Usage: #{@app_name} <command> <options> -- <application options>"
+ puts
+ puts "* where <command> is one of:"
+ puts " start start an instance of the application"
+ puts " stop stop all instances of the application"
+ puts " restart stop all instances and restart them afterwards"
+ puts " run start the application and stay on top"
+ puts " zap set the application to a stopped state"
+ puts
+ puts "* and where <options> may contain several of the following:"
+
+ puts @optparse.usage
+ end
+
+ def catch_exceptions(&block)
+ begin
+ block.call
+ rescue CmdException, OptionParser::ParseError => e
+ puts "ERROR: #{e.to_s}"
+ puts
+ print_usage()
+ rescue RuntimeException => e
+ puts "ERROR: #{e.to_s}"
+ end
+ end
+
+ end
+
+end
View
134 vendor/gems/daemons-1.0.10/lib/daemons/controller.rb
@@ -0,0 +1,134 @@
+
+module Daemons
+ class Controller
+
+ attr_reader :app_name
+
+ attr_reader :group
+
+ attr_reader :options
+
+
+ COMMANDS = [
+ 'start',
+ 'stop',
+ 'restart',
+ 'run',
+ 'zap',
+ 'status'
+ ]
+
+ def initialize(options = {}, argv = [])
+ @options = options
+ @argv = argv
+
+ # Allow an app_name to be specified. If not specified use the
+ # basename of the script.
+ @app_name = options[:app_name]
+
+ if options[:script]
+ @script = File.expand_path(options[:script])
+
+ @app_name ||= File.split(@script)[1]
+ end
+
+ @app_name ||= 'unknown_application'
+
+ @command, @controller_part, @app_part = Controller.split_argv(argv)
+
+ #@options[:dir_mode] ||= :script
+
+ @optparse = Optparse.new(self)
+ end
+
+
+ # This function is used to do a final update of the options passed to the application
+ # before they are really used.
+ #
+ # Note that this function should only update <tt>@options</tt> and no other variables.
+ #
+ def setup_options
+ #@options[:ontop] ||= true
+ end
+
+ def run
+ @options.update @optparse.parse(@controller_part).delete_if {|k,v| !v}
+
+ setup_options()
+
+ #pp @options
+
+ @group = ApplicationGroup.new(@app_name, @options)
+ @group.controller_argv = @controller_part
+ @group.app_argv = @app_part
+
+ @group.setup
+
+ case @command
+ when 'start'
+ @group.new_application.start
+ when 'run'
+ @options[:ontop] ||= true