bunnicula 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. data/Rakefile +2 -2
  2. data/bunnicula.gemspec +180 -3
  3. data/lib/bunnicula/version.rb +1 -1
  4. data/vendor/daemon_kit/daemon-kit/Configuration.txt +110 -0
  5. data/vendor/daemon_kit/daemon-kit/Deployment.txt +113 -0
  6. data/vendor/daemon_kit/daemon-kit/History.txt +113 -0
  7. data/vendor/daemon_kit/daemon-kit/Logging.txt +96 -0
  8. data/vendor/daemon_kit/daemon-kit/Manifest.txt +172 -0
  9. data/vendor/daemon_kit/daemon-kit/PostInstall.txt +6 -0
  10. data/vendor/daemon_kit/daemon-kit/README.rdoc +126 -0
  11. data/vendor/daemon_kit/daemon-kit/Rakefile +29 -0
  12. data/vendor/daemon_kit/daemon-kit/RuoteParticipants.txt +113 -0
  13. data/vendor/daemon_kit/daemon-kit/TODO.txt +28 -0
  14. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/USAGE +7 -0
  15. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/daemon_kit_generator.rb +178 -0
  16. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/README +48 -0
  17. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/Rakefile +6 -0
  18. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/bin/daemon.erb +7 -0
  19. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/config/arguments.rb +12 -0
  20. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/config/boot.rb +59 -0
  21. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/config/environment.rb +23 -0
  22. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/config/environments/development.rb +2 -0
  23. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/config/environments/production.rb +5 -0
  24. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/config/environments/test.rb +2 -0
  25. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/config/post-daemonize/readme +5 -0
  26. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/config/pre-daemonize/readme +12 -0
  27. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/lib/daemon.rb +2 -0
  28. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/libexec/daemon.erb +18 -0
  29. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/script/console +3 -0
  30. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/script/destroy +14 -0
  31. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/script/generate +14 -0
  32. data/vendor/daemon_kit/daemon-kit/bin/daemon-kit +18 -0
  33. data/vendor/daemon_kit/daemon-kit/config/website.yml +2 -0
  34. data/vendor/daemon_kit/daemon-kit/daemon-kit.gemspec +264 -0
  35. data/vendor/daemon_kit/daemon-kit/daemon_generators/amqp/USAGE +5 -0
  36. data/vendor/daemon_kit/daemon-kit/daemon_generators/amqp/amqp_generator.rb +65 -0
  37. data/vendor/daemon_kit/daemon-kit/daemon_generators/amqp/templates/config/amqp.yml +28 -0
  38. data/vendor/daemon_kit/daemon-kit/daemon_generators/amqp/templates/config/initializers/amqp.rb +7 -0
  39. data/vendor/daemon_kit/daemon-kit/daemon_generators/amqp/templates/libexec/daemon.rb +37 -0
  40. data/vendor/daemon_kit/daemon-kit/daemon_generators/cron/USAGE +5 -0
  41. data/vendor/daemon_kit/daemon-kit/daemon_generators/cron/cron_generator.rb +64 -0
  42. data/vendor/daemon_kit/daemon-kit/daemon_generators/cron/templates/config/initializers/cron.rb +11 -0
  43. data/vendor/daemon_kit/daemon-kit/daemon_generators/cron/templates/libexec/daemon.rb +43 -0
  44. data/vendor/daemon_kit/daemon-kit/daemon_generators/cucumber/USAGE +11 -0
  45. data/vendor/daemon_kit/daemon-kit/daemon_generators/cucumber/cucumber_generator.rb +38 -0
  46. data/vendor/daemon_kit/daemon-kit/daemon_generators/cucumber/templates/cucumber +8 -0
  47. data/vendor/daemon_kit/daemon-kit/daemon_generators/cucumber/templates/cucumber.rake +13 -0
  48. data/vendor/daemon_kit/daemon-kit/daemon_generators/cucumber/templates/cucumber_environment.rb +2 -0
  49. data/vendor/daemon_kit/daemon-kit/daemon_generators/cucumber/templates/env.rb +7 -0
  50. data/vendor/daemon_kit/daemon-kit/daemon_generators/deploy_capistrano/deploy_capistrano_generator.rb +35 -0
  51. data/vendor/daemon_kit/daemon-kit/daemon_generators/deploy_capistrano/templates/Capfile +10 -0
  52. data/vendor/daemon_kit/daemon-kit/daemon_generators/deploy_capistrano/templates/USAGE +10 -0
  53. data/vendor/daemon_kit/daemon-kit/daemon_generators/deploy_capistrano/templates/config/deploy.rb +53 -0
  54. data/vendor/daemon_kit/daemon-kit/daemon_generators/deploy_capistrano/templates/config/deploy/production.rb +6 -0
  55. data/vendor/daemon_kit/daemon-kit/daemon_generators/deploy_capistrano/templates/config/deploy/staging.rb +6 -0
  56. data/vendor/daemon_kit/daemon-kit/daemon_generators/deploy_capistrano/templates/config/environments/staging.rb +0 -0
  57. data/vendor/daemon_kit/daemon-kit/daemon_generators/jabber/USAGE +5 -0
  58. data/vendor/daemon_kit/daemon-kit/daemon_generators/jabber/jabber_generator.rb +65 -0
  59. data/vendor/daemon_kit/daemon-kit/daemon_generators/jabber/templates/config/initializers/jabber.rb +7 -0
  60. data/vendor/daemon_kit/daemon-kit/daemon_generators/jabber/templates/config/jabber.yml +26 -0
  61. data/vendor/daemon_kit/daemon-kit/daemon_generators/jabber/templates/libexec/daemon.rb +27 -0
  62. data/vendor/daemon_kit/daemon-kit/daemon_generators/nanite_agent/USAGE +5 -0
  63. data/vendor/daemon_kit/daemon-kit/daemon_generators/nanite_agent/nanite_agent_generator.rb +68 -0
  64. data/vendor/daemon_kit/daemon-kit/daemon_generators/nanite_agent/templates/config/initializers/nanite_agent.rb +6 -0
  65. data/vendor/daemon_kit/daemon-kit/daemon_generators/nanite_agent/templates/config/nanite.yml +35 -0
  66. data/vendor/daemon_kit/daemon-kit/daemon_generators/nanite_agent/templates/lib/actors/sample.rb +11 -0
  67. data/vendor/daemon_kit/daemon-kit/daemon_generators/nanite_agent/templates/libexec/daemon.rb +31 -0
  68. data/vendor/daemon_kit/daemon-kit/daemon_generators/rspec/USAGE +5 -0
  69. data/vendor/daemon_kit/daemon-kit/daemon_generators/rspec/rspec_generator.rb +55 -0
  70. data/vendor/daemon_kit/daemon-kit/daemon_generators/rspec/templates/spec.rb +11 -0
  71. data/vendor/daemon_kit/daemon-kit/daemon_generators/rspec/templates/spec/spec.opts +1 -0
  72. data/vendor/daemon_kit/daemon-kit/daemon_generators/rspec/templates/spec/spec_helper.rb +23 -0
  73. data/vendor/daemon_kit/daemon-kit/daemon_generators/rspec/templates/tasks/rspec.rake +19 -0
  74. data/vendor/daemon_kit/daemon-kit/daemon_generators/ruote/USAGE +5 -0
  75. data/vendor/daemon_kit/daemon-kit/daemon_generators/ruote/ruote_generator.rb +67 -0
  76. data/vendor/daemon_kit/daemon-kit/daemon_generators/ruote/templates/config/amqp.yml +30 -0
  77. data/vendor/daemon_kit/daemon-kit/daemon_generators/ruote/templates/config/initializers/ruote.rb +13 -0
  78. data/vendor/daemon_kit/daemon-kit/daemon_generators/ruote/templates/config/ruote.yml +23 -0
  79. data/vendor/daemon_kit/daemon-kit/daemon_generators/ruote/templates/lib/daemon.rb +4 -0
  80. data/vendor/daemon_kit/daemon-kit/daemon_generators/ruote/templates/lib/sample.rb +26 -0
  81. data/vendor/daemon_kit/daemon-kit/daemon_generators/ruote/templates/libexec/daemon.rb +33 -0
  82. data/vendor/daemon_kit/daemon-kit/daemon_generators/test_unit/USAGE +5 -0
  83. data/vendor/daemon_kit/daemon-kit/daemon_generators/test_unit/templates/tasks/test_unit.rake +7 -0
  84. data/vendor/daemon_kit/daemon-kit/daemon_generators/test_unit/templates/test/test.rb +9 -0
  85. data/vendor/daemon_kit/daemon-kit/daemon_generators/test_unit/templates/test/test_helper.rb +6 -0
  86. data/vendor/daemon_kit/daemon-kit/daemon_generators/test_unit/test_unit_generator.rb +51 -0
  87. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit.rb +62 -0
  88. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/abstract_logger.rb +241 -0
  89. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/amqp.rb +38 -0
  90. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/application.rb +188 -0
  91. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/arguments.rb +170 -0
  92. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/commands/console.rb +38 -0
  93. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/config.rb +108 -0
  94. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/console_daemon.rb +2 -0
  95. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/core_ext.rb +1 -0
  96. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/core_ext/configurable.rb +96 -0
  97. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/core_ext/string.rb +22 -0
  98. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/cron.rb +48 -0
  99. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/cucumber/world.rb +38 -0
  100. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/deployment/capistrano.rb +482 -0
  101. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/em.rb +43 -0
  102. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/error_handlers/base.rb +32 -0
  103. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/error_handlers/hoptoad.rb +61 -0
  104. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/error_handlers/mail.rb +85 -0
  105. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/exceptions.rb +15 -0
  106. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/initializer.rb +453 -0
  107. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/jabber.rb +170 -0
  108. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/nanite.rb +7 -0
  109. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/nanite/agent.rb +77 -0
  110. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/pid_file.rb +61 -0
  111. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/ruote_participants.rb +119 -0
  112. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/ruote_pseudo_participant.rb +68 -0
  113. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/ruote_workitem.rb +177 -0
  114. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/safety.rb +85 -0
  115. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/tasks.rb +2 -0
  116. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/tasks/environment.rake +10 -0
  117. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/tasks/framework.rake +120 -0
  118. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/tasks/god.rake +62 -0
  119. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/tasks/log.rake +8 -0
  120. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/tasks/monit.rake +29 -0
  121. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/xmpp.rb +31 -0
  122. data/vendor/daemon_kit/daemon-kit/script/console +10 -0
  123. data/vendor/daemon_kit/daemon-kit/script/destroy +14 -0
  124. data/vendor/daemon_kit/daemon-kit/script/generate +14 -0
  125. data/vendor/daemon_kit/daemon-kit/script/txt2html +71 -0
  126. data/vendor/daemon_kit/daemon-kit/spec/abstract_logger_spec.rb +126 -0
  127. data/vendor/daemon_kit/daemon-kit/spec/argument_spec.rb +70 -0
  128. data/vendor/daemon_kit/daemon-kit/spec/config_spec.rb +79 -0
  129. data/vendor/daemon_kit/daemon-kit/spec/configurable_spec.rb +56 -0
  130. data/vendor/daemon_kit/daemon-kit/spec/daemon_kit_spec.rb +7 -0
  131. data/vendor/daemon_kit/daemon-kit/spec/error_handlers_spec.rb +23 -0
  132. data/vendor/daemon_kit/daemon-kit/spec/fixtures/env.yml +15 -0
  133. data/vendor/daemon_kit/daemon-kit/spec/fixtures/noenv.yml +4 -0
  134. data/vendor/daemon_kit/daemon-kit/spec/initializer_spec.rb +26 -0
  135. data/vendor/daemon_kit/daemon-kit/spec/spec.opts +1 -0
  136. data/vendor/daemon_kit/daemon-kit/spec/spec_helper.rb +27 -0
  137. data/vendor/daemon_kit/daemon-kit/tasks/cucumber.rake +13 -0
  138. data/vendor/daemon_kit/daemon-kit/tasks/rspec.rake +21 -0
  139. data/vendor/daemon_kit/daemon-kit/tasks/tests.rake +6 -0
  140. data/vendor/daemon_kit/daemon-kit/templates/god/god.erb +69 -0
  141. data/vendor/daemon_kit/daemon-kit/templates/monit/monit.erb +14 -0
  142. data/vendor/daemon_kit/daemon-kit/test/test_amqp_generator.rb +48 -0
  143. data/vendor/daemon_kit/daemon-kit/test/test_cron_generator.rb +45 -0
  144. data/vendor/daemon_kit/daemon-kit/test/test_daemon-kit_generator.rb +84 -0
  145. data/vendor/daemon_kit/daemon-kit/test/test_daemon_kit_config.rb +28 -0
  146. data/vendor/daemon_kit/daemon-kit/test/test_deploy_capistrano_generator.rb +48 -0
  147. data/vendor/daemon_kit/daemon-kit/test/test_generator_helper.rb +29 -0
  148. data/vendor/daemon_kit/daemon-kit/test/test_helper.rb +7 -0
  149. data/vendor/daemon_kit/daemon-kit/test/test_jabber_generator.rb +49 -0
  150. data/vendor/daemon_kit/daemon-kit/test/test_nanite_agent_generator.rb +49 -0
  151. data/vendor/daemon_kit/daemon-kit/test/test_ruote_generator.rb +51 -0
  152. data/vendor/daemon_kit/daemon-kit/test/test_test_unit_generator.rb +46 -0
  153. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail.rb +5 -0
  154. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/address.rb +426 -0
  155. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/attachments.rb +46 -0
  156. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/base64.rb +46 -0
  157. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/compat.rb +41 -0
  158. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/config.rb +67 -0
  159. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/core_extensions.rb +63 -0
  160. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/encode.rb +581 -0
  161. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/header.rb +960 -0
  162. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/index.rb +9 -0
  163. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/interface.rb +1130 -0
  164. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/loader.rb +3 -0
  165. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/mail.rb +578 -0
  166. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/mailbox.rb +495 -0
  167. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/main.rb +6 -0
  168. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/mbox.rb +3 -0
  169. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/net.rb +248 -0
  170. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/obsolete.rb +132 -0
  171. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/parser.rb +1476 -0
  172. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/port.rb +379 -0
  173. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/quoting.rb +118 -0
  174. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/require_arch.rb +58 -0
  175. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/scanner.rb +49 -0
  176. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/scanner_r.rb +261 -0
  177. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/stringio.rb +280 -0
  178. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/utils.rb +337 -0
  179. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/version.rb +39 -0
  180. data/vendor/daemon_kit/daemon-kit/vendor/tmail.rb +13 -0
  181. metadata +181 -4
@@ -0,0 +1,4 @@
1
+ # Your starting point for daemon specific classes. This directory is
2
+ # already included in your load path, so no need to specify it.
3
+
4
+ require 'sample'
@@ -0,0 +1,26 @@
1
+ require 'open-uri'
2
+
3
+ # Sample pseudo participant
4
+ #
5
+ # See http://gist.github.com/144861 for a test engine
6
+ class Sample < DaemonKit::RuotePseudoParticipant
7
+
8
+ on_exception :dammit
9
+
10
+ on_complete do |workitem|
11
+ workitem['success'] = true
12
+ end
13
+
14
+ def quote
15
+ workitem["quote"] = open("http://www.iheartquotes.com/api/v1/random").read
16
+ end
17
+
18
+ def err
19
+ raise ArgumentError, "Does not compute"
20
+ end
21
+
22
+ def dammit( exception )
23
+ workitem["error"] = exception.message
24
+ end
25
+
26
+ end
@@ -0,0 +1,33 @@
1
+ # Generated remote participant for the ruote workflow engine
2
+ # (http://openwferu.rubyforge.org)
3
+
4
+ # Do your post daemonization configuration here
5
+ # At minimum you need just the first line (without the block), or a lot
6
+ # of strange things might start happening...
7
+ DaemonKit::Application.running! do |config|
8
+ # Trap signals with blocks or procs
9
+ # config.trap( 'INT' ) do
10
+ # # do something clever
11
+ # end
12
+ # config.trap( 'TERM', Proc.new { puts 'Going down' } )
13
+ end
14
+
15
+ # IMPORTANT CONFIGURATION NOTE
16
+ #
17
+ # Please review and update 'config/amqp.yml' accordingly if you wish to use
18
+ # AMQP as a transport mechanism for workitems sent between ruote and this
19
+ # daemon.
20
+
21
+ # Configuration of the remote participant shell
22
+ DaemonKit::RuoteParticipants.configure do |config|
23
+ # Use AMQP as a workitem transport mechanism
24
+ config.use :amqp
25
+
26
+ # Register your classes as pseudo-participants, with work being delegated
27
+ # according to the 'command' parameter passed in the process definition
28
+ config.register Sample
29
+ end
30
+
31
+ DaemonKit::RuoteParticipants.run do
32
+ # Place any additional daemon-specific code in here...
33
+ end
@@ -0,0 +1,7 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << "test"
5
+ t.test_files = FileList['test/*_test.rb']
6
+ t.verbose = true
7
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class Test<%= module_name %> < Test::Unit::TestCase
4
+
5
+ def test_missing
6
+ assert false, "daemons should be tested"
7
+ end
8
+ end
9
+
@@ -0,0 +1,6 @@
1
+ DAEMON_ENV = 'test' unless defined?( DAEMON_ENV )
2
+
3
+ require 'test/unit'
4
+
5
+ require File.dirname(__FILE__) + '/../config/environment'
6
+ DaemonKit::Application.running!
@@ -0,0 +1,51 @@
1
+ class TestUnitGenerator < RubiGen::Base
2
+
3
+ attr_reader :gem_name, :module_name
4
+
5
+ def initialize(runtime_args, runtime_options = {})
6
+ super
7
+ @destination_root = File.expand_path(destination_root)
8
+ @gem_name = base_name
9
+ @module_name = @gem_name.camelcase
10
+ extract_options
11
+ end
12
+
13
+ def manifest
14
+ record do |m|
15
+ # Ensure appropriate folder(s) exists
16
+ m.directory 'test'
17
+ m.directory 'tasks'
18
+
19
+ m.template 'test/test.rb', "test/#{gem_name}_test.rb"
20
+ m.template_copy_each %w( test_helper.rb ), 'test'
21
+ m.file_copy_each %w( test_unit.rake ), 'tasks'
22
+ end
23
+ end
24
+
25
+ protected
26
+ def banner
27
+ <<-EOS
28
+ Creates a ...
29
+
30
+ USAGE: #{$0} #{spec.name} name
31
+ EOS
32
+ end
33
+
34
+ def add_options!(opts)
35
+ # opts.separator ''
36
+ # opts.separator 'Options:'
37
+ # For each option below, place the default
38
+ # at the top of the file next to "default_options"
39
+ # opts.on("-a", "--author=\"Your Name\"", String,
40
+ # "Some comment about this option",
41
+ # "Default: none") { |o| options[:author] = o }
42
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
43
+ end
44
+
45
+ def extract_options
46
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
47
+ # Templates can access these value via the attr_reader-generated methods, but not the
48
+ # raw instance variable value.
49
+ # @author = options[:author]
50
+ end
51
+ end
@@ -0,0 +1,62 @@
1
+ # TODO: Strip this out eventually so we can run without rubygems
2
+ require 'rubygems'
3
+
4
+ # Seems in 1.9 we need to load openssl before em or there is failures all around.
5
+ # But we need to consider that people might not have ssl in the first place.
6
+ if RUBY_VERSION >= "1.9"
7
+ begin
8
+ require 'openssl'
9
+ rescue LoadError
10
+ end
11
+ end
12
+ require 'eventmachine'
13
+
14
+ require File.dirname(__FILE__) + '/daemon_kit/core_ext'
15
+ require File.dirname(__FILE__) + '/daemon_kit/exceptions'
16
+
17
+ $:.unshift( File.dirname(__FILE__).to_absolute_path ) unless
18
+ $:.include?( File.dirname(__FILE__).to_absolute_path )
19
+
20
+ module DaemonKit
21
+ VERSION = '0.1.7.12'
22
+
23
+ autoload :Initializer, 'daemon_kit/initializer'
24
+ autoload :Application, 'daemon_kit/application'
25
+ autoload :Arguments, 'daemon_kit/arguments'
26
+ autoload :Config, 'daemon_kit/config'
27
+ autoload :Safety, 'daemon_kit/safety'
28
+ autoload :PidFile, 'daemon_kit/pid_file'
29
+ autoload :AbstractLogger, 'daemon_kit/abstract_logger'
30
+ autoload :EM, 'daemon_kit/em'
31
+ autoload :Configurable, 'daemon_kit/core_ext/configurable'
32
+
33
+ autoload :Cron, 'daemon_kit/cron'
34
+ autoload :Jabber, 'daemon_kit/jabber'
35
+ autoload :AMQP, 'daemon_kit/amqp'
36
+ autoload :Nanite, 'daemon_kit/nanite'
37
+ autoload :RuoteParticipants, 'daemon_kit/ruote_participants'
38
+ autoload :RuoteWorkitem, 'daemon_kit/ruote_workitem'
39
+ autoload :RuotePseudoParticipant, 'daemon_kit/ruote_pseudo_participant'
40
+
41
+ class << self
42
+ def logger
43
+ @logger
44
+ end
45
+
46
+ def logger=( logger )
47
+ @logger = logger
48
+ end
49
+
50
+ def root
51
+ DAEMON_ROOT
52
+ end
53
+
54
+ def env
55
+ DAEMON_ENV
56
+ end
57
+
58
+ def framework_root
59
+ @framework_root ||= File.join( File.dirname(__FILE__), '..' ).to_absolute_path
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,241 @@
1
+ require 'logger'
2
+
3
+ module DaemonKit
4
+ # One of the key parts of succesful background processes is adequate
5
+ # logging. The AbstractLogger aims to simplify logging from inside
6
+ # daemon processes by providing additional useful information with
7
+ # each log line, including calling file name and line number and
8
+ # support for cleanly logging exceptions.
9
+ #
10
+ # The logger can be accessed through #DaemonKit.logger.
11
+ #
12
+ # AbstractLogger provides an interface that is fully compatible with
13
+ # the Logger class provided by Ruby's Standard Library, and is
14
+ # extended with some additional conveniences.
15
+ #
16
+ # The AbstractLogger supports different backends, by default it uses
17
+ # a Logger instance, but can by swapped out for a SysLogLogger
18
+ # logger as well.
19
+ class AbstractLogger
20
+
21
+ attr_accessor :copy_to_stdout
22
+
23
+ @severities = {
24
+ :debug => Logger::DEBUG,
25
+ :info => Logger::INFO,
26
+ :warn => Logger::WARN,
27
+ :error => Logger::ERROR,
28
+ :fatal => Logger::FATAL,
29
+ :unknown => Logger::UNKNOWN
30
+ }
31
+
32
+ @silencer = true
33
+
34
+ class << self
35
+ attr_reader :severities
36
+ attr_accessor :silencer
37
+ end
38
+
39
+ # Optional log path, defaults to
40
+ # <em>DAEMON_ROOT/log/DAEMON_ENV.log</em>
41
+ def initialize( log_path = nil )
42
+ if log_path.to_s == "syslog"
43
+ @backend = :syslog
44
+ else
45
+ @logger_file = log_path || "#{DAEMON_ROOT}/log/#{DAEMON_ENV}.log"
46
+ @backend = :logger
47
+ end
48
+
49
+ @copy_to_stdout = false
50
+ end
51
+
52
+ # Silence the logger for the duration of the block.
53
+ def silence( temporary_level = :error )
54
+ if self.class.silencer
55
+ begin
56
+ old_level, self.level = self.level, temporary_level
57
+ yield self
58
+ ensure
59
+ self.level = old_level
60
+ end
61
+ else
62
+ yield self
63
+ end
64
+ end
65
+
66
+ # Write unformatted message to logging device, mostly useful for Logger interface
67
+ # compatibility and debugging soap4r (possibly others)
68
+ def <<( msg ) #:nodoc:
69
+ self.logger.write( msg ) if self.logger && self.logger.respond_to?( :write )
70
+ end
71
+
72
+ def debug( msg )
73
+ add( :debug, msg )
74
+ end
75
+
76
+ def debug?
77
+ self.level == :debug
78
+ end
79
+
80
+ def info( msg )
81
+ add( :info, msg )
82
+ end
83
+
84
+ def info?
85
+ self.level == :info
86
+ end
87
+
88
+ def warn( msg )
89
+ add( :warn, msg )
90
+ end
91
+
92
+ def warn?
93
+ self.level == :warn
94
+ end
95
+
96
+ def error( msg )
97
+ add( :error, msg )
98
+ end
99
+
100
+ def error?
101
+ self.level == :error
102
+ end
103
+
104
+ def fatal( msg )
105
+ add( :fatal, msg )
106
+ end
107
+
108
+ def fatal?
109
+ self.level == :fatal
110
+ end
111
+
112
+ def unknown( msg )
113
+ add( :unknown, msg )
114
+ end
115
+
116
+ def unknown?
117
+ self.level == :unknown
118
+ end
119
+
120
+ def exception( e )
121
+ message = "EXCEPTION: #{e.message}: #{clean_trace( e.backtrace )}"
122
+ self.add( :error, message, true )
123
+ end
124
+
125
+ def add( severity, message, skip_caller = false )
126
+ message = "#{called(caller)}: #{message}" unless skip_caller
127
+
128
+ self.logger.add( self.class.severities[ severity ] ) { message }
129
+
130
+ STDOUT.puts( message ) if self.copy_to_stdout
131
+ end
132
+
133
+ def level
134
+ self.class.severities.invert[ @logger.level ]
135
+ end
136
+
137
+ def level=( level )
138
+ level = ( Symbol === level ? self.class.severities[ level ] : level )
139
+ self.logger.level = level
140
+ end
141
+
142
+ def logger
143
+ @logger ||= create_logger
144
+ end
145
+
146
+ def logger=( logger )
147
+ if logger.is_a?( Symbol )
148
+ @backend = logger
149
+ @logger.close rescue nil
150
+ @logger = create_logger
151
+ else
152
+ @logger.close rescue nil
153
+ @logger = logger
154
+ end
155
+ end
156
+
157
+ def clean_trace( trace )
158
+ trace = trace.map { |l| l.gsub(DAEMON_ROOT, '') }
159
+ trace = trace.reject { |l| l =~ /gems\/daemon[\-_]kit/ }
160
+ trace = trace.reject { |l| l =~ /vendor\/daemon[\-_]kit/ }
161
+ trace
162
+ end
163
+
164
+ def close
165
+ case @backend
166
+ when :logger
167
+ self.logger.close
168
+ @logger = nil
169
+ end
170
+ end
171
+
172
+ private
173
+
174
+ def called( trace )
175
+ l = trace.detect('unknown:0') { |l| l.index('abstract_logger.rb').nil? }
176
+ file, num, _ = l.split(':')
177
+
178
+ [ File.basename(file), num ].join(':')
179
+ end
180
+
181
+ def create_logger
182
+ case @backend
183
+ when :logger
184
+ create_standard_logger
185
+ when :syslog
186
+ create_syslog_logger
187
+ end
188
+ end
189
+
190
+ def create_standard_logger
191
+ log_path = File.dirname( @logger_file )
192
+ unless File.directory?( log_path )
193
+ begin
194
+ FileUtils.mkdir_p( log_path )
195
+ rescue
196
+ STDERR.puts "#{log_path} not writable, using STDERR for logging"
197
+ @logger_file = STDERR
198
+ end
199
+ end
200
+
201
+ l = Logger.new( @logger_file )
202
+ l.formatter = Formatter.new
203
+ l.progname = if DaemonKit.configuration
204
+ DaemonKit.configuration.daemon_name
205
+ else
206
+ File.basename($0)
207
+ end
208
+ l
209
+ end
210
+
211
+ def create_syslog_logger
212
+ begin
213
+ require 'syslog_logger'
214
+ SyslogLogger.new( DaemonKit.configuration ? DaemonKit.configuration.daemon_name : File.basename($0) )
215
+ rescue LoadError
216
+ self.logger = :logger
217
+ self.error( "Couldn't load syslog_logger gem, reverting to standard logger" )
218
+ end
219
+ end
220
+
221
+ class Formatter
222
+
223
+ # YYYY:MM:DD HH:MM:SS.MS daemon_name(pid) level: message
224
+ @format = "%s %s(%d) [%s] %s\n"
225
+
226
+ class << self
227
+ attr_accessor :format
228
+ end
229
+
230
+ def call(severity, time, progname, msg)
231
+ self.class.format % [ format_time( time ), progname, $$, severity, msg.to_s ]
232
+ end
233
+
234
+ private
235
+
236
+ def format_time( time )
237
+ time.strftime( "%Y-%m-%d %H:%M:%S." ) + time.usec.to_s
238
+ end
239
+ end
240
+ end
241
+ end