apphunkd 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. data/.document +5 -0
  2. data/.gitignore +22 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +18 -0
  5. data/Rakefile +78 -0
  6. data/TODO +1 -0
  7. data/VERSION +1 -0
  8. data/apphunkd.gemspec +258 -0
  9. data/bin/apphunkd +4 -0
  10. data/config/arguments.rb +12 -0
  11. data/config/boot.rb +68 -0
  12. data/config/environment.rb +23 -0
  13. data/config/environments/development.rb +2 -0
  14. data/config/environments/production.rb +2 -0
  15. data/config/environments/test.rb +2 -0
  16. data/config/post-daemonize/readme +5 -0
  17. data/config/pre-daemonize/readme +12 -0
  18. data/config/pre-daemonize/requires.rb +2 -0
  19. data/lib/apphunkd.rb +25 -0
  20. data/lib/apphunkd/api.rb +5 -0
  21. data/lib/apphunkd/api/service.rb +27 -0
  22. data/lib/apphunkd/queue.rb +96 -0
  23. data/lib/apphunkd/remote.rb +29 -0
  24. data/lib/apphunkd/remote/result.rb +15 -0
  25. data/libexec/apphunkd-daemon.rb +13 -0
  26. data/script/console +3 -0
  27. data/script/destroy +14 -0
  28. data/script/generate +14 -0
  29. data/spec/lib/apphunkd/api/service_spec.rb +47 -0
  30. data/spec/lib/apphunkd/queue_spec.rb +129 -0
  31. data/spec/lib/apphunkd/remote_spec.rb +61 -0
  32. data/spec/lib/apphunkd_spec.rb +50 -0
  33. data/spec/spec.opts +1 -0
  34. data/spec/spec_helper.rb +13 -0
  35. data/support/apphunkd.initd +47 -0
  36. data/support/apphunkd.monitrc +3 -0
  37. data/tasks/rspec.rake +21 -0
  38. data/vendor/daemon-kit/Configuration.txt +102 -0
  39. data/vendor/daemon-kit/Deployment.txt +113 -0
  40. data/vendor/daemon-kit/History.txt +97 -0
  41. data/vendor/daemon-kit/Logging.txt +92 -0
  42. data/vendor/daemon-kit/Manifest.txt +166 -0
  43. data/vendor/daemon-kit/PostInstall.txt +6 -0
  44. data/vendor/daemon-kit/README.rdoc +130 -0
  45. data/vendor/daemon-kit/Rakefile +37 -0
  46. data/vendor/daemon-kit/RuoteParticipants.txt +113 -0
  47. data/vendor/daemon-kit/TODO.txt +37 -0
  48. data/vendor/daemon-kit/app_generators/daemon_kit/USAGE +7 -0
  49. data/vendor/daemon-kit/app_generators/daemon_kit/daemon_kit_generator.rb +161 -0
  50. data/vendor/daemon-kit/app_generators/daemon_kit/templates/README +48 -0
  51. data/vendor/daemon-kit/app_generators/daemon_kit/templates/Rakefile +6 -0
  52. data/vendor/daemon-kit/app_generators/daemon_kit/templates/bin/daemon.erb +7 -0
  53. data/vendor/daemon-kit/app_generators/daemon_kit/templates/config/arguments.rb +12 -0
  54. data/vendor/daemon-kit/app_generators/daemon_kit/templates/config/boot.rb +68 -0
  55. data/vendor/daemon-kit/app_generators/daemon_kit/templates/config/environment.rb +23 -0
  56. data/vendor/daemon-kit/app_generators/daemon_kit/templates/config/environments/development.rb +2 -0
  57. data/vendor/daemon-kit/app_generators/daemon_kit/templates/config/environments/production.rb +2 -0
  58. data/vendor/daemon-kit/app_generators/daemon_kit/templates/config/environments/test.rb +2 -0
  59. data/vendor/daemon-kit/app_generators/daemon_kit/templates/config/post-daemonize/readme +5 -0
  60. data/vendor/daemon-kit/app_generators/daemon_kit/templates/config/pre-daemonize/readme +12 -0
  61. data/vendor/daemon-kit/app_generators/daemon_kit/templates/lib/daemon.rb +2 -0
  62. data/vendor/daemon-kit/app_generators/daemon_kit/templates/libexec/daemon.erb +18 -0
  63. data/vendor/daemon-kit/app_generators/daemon_kit/templates/script/console +3 -0
  64. data/vendor/daemon-kit/app_generators/daemon_kit/templates/script/destroy +14 -0
  65. data/vendor/daemon-kit/app_generators/daemon_kit/templates/script/generate +14 -0
  66. data/vendor/daemon-kit/bin/daemon_kit +18 -0
  67. data/vendor/daemon-kit/daemon_generators/amqp/USAGE +5 -0
  68. data/vendor/daemon-kit/daemon_generators/amqp/amqp_generator.rb +65 -0
  69. data/vendor/daemon-kit/daemon_generators/amqp/templates/config/amqp.yml +28 -0
  70. data/vendor/daemon-kit/daemon_generators/amqp/templates/config/initializers/amqp.rb +7 -0
  71. data/vendor/daemon-kit/daemon_generators/amqp/templates/libexec/daemon.rb +37 -0
  72. data/vendor/daemon-kit/daemon_generators/cron/USAGE +5 -0
  73. data/vendor/daemon-kit/daemon_generators/cron/cron_generator.rb +64 -0
  74. data/vendor/daemon-kit/daemon_generators/cron/templates/config/initializers/cron.rb +11 -0
  75. data/vendor/daemon-kit/daemon_generators/cron/templates/libexec/daemon.rb +43 -0
  76. data/vendor/daemon-kit/daemon_generators/cucumber/USAGE +11 -0
  77. data/vendor/daemon-kit/daemon_generators/cucumber/cucumber_generator.rb +38 -0
  78. data/vendor/daemon-kit/daemon_generators/cucumber/templates/cucumber +8 -0
  79. data/vendor/daemon-kit/daemon_generators/cucumber/templates/cucumber.rake +13 -0
  80. data/vendor/daemon-kit/daemon_generators/cucumber/templates/cucumber_environment.rb +2 -0
  81. data/vendor/daemon-kit/daemon_generators/cucumber/templates/env.rb +7 -0
  82. data/vendor/daemon-kit/daemon_generators/deploy_capistrano/deploy_capistrano_generator.rb +35 -0
  83. data/vendor/daemon-kit/daemon_generators/deploy_capistrano/templates/Capfile +10 -0
  84. data/vendor/daemon-kit/daemon_generators/deploy_capistrano/templates/USAGE +10 -0
  85. data/vendor/daemon-kit/daemon_generators/deploy_capistrano/templates/config/deploy.rb +53 -0
  86. data/vendor/daemon-kit/daemon_generators/deploy_capistrano/templates/config/deploy/production.rb +6 -0
  87. data/vendor/daemon-kit/daemon_generators/deploy_capistrano/templates/config/deploy/staging.rb +6 -0
  88. data/vendor/daemon-kit/daemon_generators/deploy_capistrano/templates/config/environments/staging.rb +0 -0
  89. data/vendor/daemon-kit/daemon_generators/jabber/USAGE +5 -0
  90. data/vendor/daemon-kit/daemon_generators/jabber/jabber_generator.rb +65 -0
  91. data/vendor/daemon-kit/daemon_generators/jabber/templates/config/initializers/jabber.rb +7 -0
  92. data/vendor/daemon-kit/daemon_generators/jabber/templates/config/jabber.yml +26 -0
  93. data/vendor/daemon-kit/daemon_generators/jabber/templates/libexec/daemon.rb +27 -0
  94. data/vendor/daemon-kit/daemon_generators/nanite_agent/USAGE +5 -0
  95. data/vendor/daemon-kit/daemon_generators/nanite_agent/nanite_agent_generator.rb +68 -0
  96. data/vendor/daemon-kit/daemon_generators/nanite_agent/templates/config/initializers/nanite_agent.rb +6 -0
  97. data/vendor/daemon-kit/daemon_generators/nanite_agent/templates/config/nanite.yml +35 -0
  98. data/vendor/daemon-kit/daemon_generators/nanite_agent/templates/lib/actors/sample.rb +11 -0
  99. data/vendor/daemon-kit/daemon_generators/nanite_agent/templates/libexec/daemon.rb +31 -0
  100. data/vendor/daemon-kit/daemon_generators/rspec/USAGE +5 -0
  101. data/vendor/daemon-kit/daemon_generators/rspec/rspec_generator.rb +55 -0
  102. data/vendor/daemon-kit/daemon_generators/rspec/templates/spec.rb +11 -0
  103. data/vendor/daemon-kit/daemon_generators/rspec/templates/spec/spec.opts +1 -0
  104. data/vendor/daemon-kit/daemon_generators/rspec/templates/spec/spec_helper.rb +21 -0
  105. data/vendor/daemon-kit/daemon_generators/rspec/templates/tasks/rspec.rake +21 -0
  106. data/vendor/daemon-kit/daemon_generators/ruote/USAGE +5 -0
  107. data/vendor/daemon-kit/daemon_generators/ruote/ruote_generator.rb +67 -0
  108. data/vendor/daemon-kit/daemon_generators/ruote/templates/config/amqp.yml +30 -0
  109. data/vendor/daemon-kit/daemon_generators/ruote/templates/config/initializers/ruote.rb +13 -0
  110. data/vendor/daemon-kit/daemon_generators/ruote/templates/config/ruote.yml +23 -0
  111. data/vendor/daemon-kit/daemon_generators/ruote/templates/lib/daemon.rb +4 -0
  112. data/vendor/daemon-kit/daemon_generators/ruote/templates/lib/sample.rb +26 -0
  113. data/vendor/daemon-kit/daemon_generators/ruote/templates/libexec/daemon.rb +33 -0
  114. data/vendor/daemon-kit/lib/daemon_kit.rb +54 -0
  115. data/vendor/daemon-kit/lib/daemon_kit/abstract_logger.rb +235 -0
  116. data/vendor/daemon-kit/lib/daemon_kit/amqp.rb +38 -0
  117. data/vendor/daemon-kit/lib/daemon_kit/application.rb +187 -0
  118. data/vendor/daemon-kit/lib/daemon_kit/arguments.rb +165 -0
  119. data/vendor/daemon-kit/lib/daemon_kit/commands/console.rb +38 -0
  120. data/vendor/daemon-kit/lib/daemon_kit/config.rb +108 -0
  121. data/vendor/daemon-kit/lib/daemon_kit/console_daemon.rb +2 -0
  122. data/vendor/daemon-kit/lib/daemon_kit/core_ext.rb +1 -0
  123. data/vendor/daemon-kit/lib/daemon_kit/core_ext/configurable.rb +96 -0
  124. data/vendor/daemon-kit/lib/daemon_kit/core_ext/string.rb +22 -0
  125. data/vendor/daemon-kit/lib/daemon_kit/cron.rb +48 -0
  126. data/vendor/daemon-kit/lib/daemon_kit/cucumber/world.rb +38 -0
  127. data/vendor/daemon-kit/lib/daemon_kit/deployment/capistrano.rb +482 -0
  128. data/vendor/daemon-kit/lib/daemon_kit/em.rb +43 -0
  129. data/vendor/daemon-kit/lib/daemon_kit/error_handlers/base.rb +32 -0
  130. data/vendor/daemon-kit/lib/daemon_kit/error_handlers/hoptoad.rb +61 -0
  131. data/vendor/daemon-kit/lib/daemon_kit/error_handlers/mail.rb +85 -0
  132. data/vendor/daemon-kit/lib/daemon_kit/exceptions.rb +8 -0
  133. data/vendor/daemon-kit/lib/daemon_kit/initializer.rb +438 -0
  134. data/vendor/daemon-kit/lib/daemon_kit/jabber.rb +170 -0
  135. data/vendor/daemon-kit/lib/daemon_kit/nanite.rb +7 -0
  136. data/vendor/daemon-kit/lib/daemon_kit/nanite/agent.rb +56 -0
  137. data/vendor/daemon-kit/lib/daemon_kit/pid_file.rb +61 -0
  138. data/vendor/daemon-kit/lib/daemon_kit/ruote_participants.rb +119 -0
  139. data/vendor/daemon-kit/lib/daemon_kit/ruote_pseudo_participant.rb +68 -0
  140. data/vendor/daemon-kit/lib/daemon_kit/ruote_workitem.rb +169 -0
  141. data/vendor/daemon-kit/lib/daemon_kit/safety.rb +85 -0
  142. data/vendor/daemon-kit/lib/daemon_kit/tasks.rb +2 -0
  143. data/vendor/daemon-kit/lib/daemon_kit/tasks/environment.rake +10 -0
  144. data/vendor/daemon-kit/lib/daemon_kit/tasks/framework.rake +120 -0
  145. data/vendor/daemon-kit/lib/daemon_kit/tasks/god.rake +62 -0
  146. data/vendor/daemon-kit/lib/daemon_kit/tasks/log.rake +8 -0
  147. data/vendor/daemon-kit/lib/daemon_kit/tasks/monit.rake +29 -0
  148. data/vendor/daemon-kit/script/console +10 -0
  149. data/vendor/daemon-kit/script/destroy +14 -0
  150. data/vendor/daemon-kit/script/generate +14 -0
  151. data/vendor/daemon-kit/script/txt2html +71 -0
  152. data/vendor/daemon-kit/spec/abstract_logger_spec.rb +126 -0
  153. data/vendor/daemon-kit/spec/argument_spec.rb +70 -0
  154. data/vendor/daemon-kit/spec/config_spec.rb +79 -0
  155. data/vendor/daemon-kit/spec/configurable_spec.rb +56 -0
  156. data/vendor/daemon-kit/spec/daemon_kit_spec.rb +7 -0
  157. data/vendor/daemon-kit/spec/error_handlers_spec.rb +23 -0
  158. data/vendor/daemon-kit/spec/fixtures/env.yml +15 -0
  159. data/vendor/daemon-kit/spec/fixtures/noenv.yml +4 -0
  160. data/vendor/daemon-kit/spec/initializer_spec.rb +26 -0
  161. data/vendor/daemon-kit/spec/spec.opts +1 -0
  162. data/vendor/daemon-kit/spec/spec_helper.rb +27 -0
  163. data/vendor/daemon-kit/tasks/rspec.rake +21 -0
  164. data/vendor/daemon-kit/templates/god/god.erb +69 -0
  165. data/vendor/daemon-kit/templates/monit/monit.erb +14 -0
  166. data/vendor/daemon-kit/test/test_amqp_generator.rb +48 -0
  167. data/vendor/daemon-kit/test/test_cron_generator.rb +45 -0
  168. data/vendor/daemon-kit/test/test_daemon-kit_generator.rb +84 -0
  169. data/vendor/daemon-kit/test/test_daemon_kit_config.rb +28 -0
  170. data/vendor/daemon-kit/test/test_deploy_capistrano_generator.rb +48 -0
  171. data/vendor/daemon-kit/test/test_generator_helper.rb +29 -0
  172. data/vendor/daemon-kit/test/test_helper.rb +7 -0
  173. data/vendor/daemon-kit/test/test_jabber_generator.rb +49 -0
  174. data/vendor/daemon-kit/test/test_nanite_agent_generator.rb +49 -0
  175. data/vendor/daemon-kit/test/test_ruote_generator.rb +45 -0
  176. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail.rb +5 -0
  177. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/address.rb +426 -0
  178. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/attachments.rb +46 -0
  179. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/base64.rb +46 -0
  180. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/compat.rb +41 -0
  181. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/config.rb +67 -0
  182. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/core_extensions.rb +63 -0
  183. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/encode.rb +581 -0
  184. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/header.rb +960 -0
  185. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/index.rb +9 -0
  186. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/interface.rb +1130 -0
  187. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/loader.rb +3 -0
  188. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/mail.rb +578 -0
  189. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/mailbox.rb +495 -0
  190. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/main.rb +6 -0
  191. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/mbox.rb +3 -0
  192. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/net.rb +248 -0
  193. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/obsolete.rb +132 -0
  194. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/parser.rb +1476 -0
  195. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/port.rb +379 -0
  196. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/quoting.rb +118 -0
  197. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/require_arch.rb +58 -0
  198. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/scanner.rb +49 -0
  199. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/scanner_r.rb +261 -0
  200. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/stringio.rb +280 -0
  201. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/utils.rb +337 -0
  202. data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/version.rb +39 -0
  203. data/vendor/daemon-kit/vendor/tmail.rb +13 -0
  204. metadata +281 -0
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ # Time to add your specs!
4
+ # http://rspec.info/
5
+ describe "Place your specs here" do
6
+
7
+ it "find this spec in spec directory" do
8
+ violated "Be sure to write your specs"
9
+ end
10
+
11
+ end
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ require File.dirname(__FILE__) + '/../config/environment'
10
+ DaemonKit::Application.running!
11
+
12
+ Spec::Runner.configure do |config|
13
+ # == Mock Framework
14
+ #
15
+ # RSpec uses it's own mocking framework by default. If you prefer to
16
+ # use mocha, flexmock or RR, uncomment the appropriate line:
17
+ #
18
+ config.mock_with :mocha
19
+ # config.mock_with :flexmock
20
+ # config.mock_with :rr
21
+ end
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,67 @@
1
+ class RuoteGenerator < RubiGen::Base
2
+
3
+ default_options :author => nil
4
+
5
+ attr_reader :name
6
+
7
+ def initialize(runtime_args, runtime_options = {})
8
+ super
9
+ usage if args.empty?
10
+ @name = args.shift
11
+ extract_options
12
+ end
13
+
14
+ def manifest
15
+ record do |m|
16
+ # Ensure appropriate folder(s) exists
17
+ m.directory ''
18
+
19
+ # Create stubs
20
+ # m.template "template.rb.erb", "some_file_after_erb.rb"
21
+ # m.template_copy_each ["template.rb", "template2.rb"]
22
+ # m.template_copy_each ["template.rb", "template2.rb"], "some/path"
23
+ # m.file "file", "some_file_copied"
24
+ # m.file_copy_each ["path/to/file", "path/to/file2"]
25
+ # m.file_copy_each ["path/to/file", "path/to/file2"], "some/path"
26
+
27
+ m.directory 'config'
28
+ m.template 'config/amqp.yml', 'config/amqp.yml'
29
+ m.template 'config/ruote.yml', 'config/ruote.yml'
30
+ m.directory 'config/initializers'
31
+ m.template 'config/initializers/ruote.rb', "config/initializers/#{name}.rb"
32
+
33
+ m.directory 'lib'
34
+ m.template 'lib/daemon.rb', "lib/#{name}.rb"
35
+ m.template 'lib/sample.rb', 'lib/sample.rb'
36
+ m.directory 'libexec'
37
+ m.template 'libexec/daemon.rb', "libexec/#{name}-daemon.rb"
38
+ end
39
+ end
40
+
41
+ protected
42
+ def banner
43
+ <<-EOS
44
+ Creates a ...
45
+
46
+ USAGE: #{$0} #{spec.name} name
47
+ EOS
48
+ end
49
+
50
+ def add_options!(opts)
51
+ # opts.separator ''
52
+ # opts.separator 'Options:'
53
+ # For each option below, place the default
54
+ # at the top of the file next to "default_options"
55
+ # opts.on("-a", "--author=\"Your Name\"", String,
56
+ # "Some comment about this option",
57
+ # "Default: none") { |o| options[:author] = o }
58
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
59
+ end
60
+
61
+ def extract_options
62
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
63
+ # Templates can access these value via the attr_reader-generated methods, but not the
64
+ # raw instance variable value.
65
+ # @author = options[:author]
66
+ end
67
+ end
@@ -0,0 +1,30 @@
1
+ # AMQP client configuration file for ruote remote participants. If you are not
2
+ # planning to use the AMQP participant/listener pair in ruote, you can safely
3
+ # delete this file.
4
+
5
+ # These values will be used to configure the ampq gem, any values
6
+ # omitted will let the gem use it's own defaults.
7
+
8
+ # The configuration specifies the following keys:
9
+ # * user - Username for the broker
10
+ # * pass - Password for the broker
11
+ # * host - Hostname where the broker is running
12
+ # * vhost - Vhost to connect to
13
+ # * port - Port where the broker is running
14
+ # * ssl - Use ssl or not
15
+ # * timeout - Timeout
16
+
17
+ defaults: &defaults
18
+ user: guest
19
+ pass: guest
20
+ host: localhost
21
+ vhost: /
22
+
23
+ development:
24
+ <<: *defaults
25
+
26
+ test:
27
+ <<: *defaults
28
+
29
+ production:
30
+ <<: *defaults
@@ -0,0 +1,13 @@
1
+ begin
2
+ require 'json'
3
+ rescue LoadError
4
+ $stderr.puts "Missing json gem. Please run 'gem install json'"
5
+ exit 1
6
+ end
7
+
8
+ begin
9
+ require 'amqp'
10
+ require 'mq'
11
+ rescue LoadError
12
+ $stderr.puts "Missing amqp gem. Please run 'gem install amqp' if you wish to use the AMQP participant/listener pair in ruote"
13
+ end
@@ -0,0 +1,23 @@
1
+ # Sample configuration file for a remote participant daemon
2
+
3
+ # If your using the AMQP listener/participant pair in ruote, you only
4
+ # need to specify the names of the queues to subscribe to.
5
+
6
+ defaults: &defaults
7
+ amqp:
8
+ queues:
9
+ - work1
10
+ #- work2
11
+ #- work3
12
+
13
+ development:
14
+ <<: *defaults
15
+
16
+ test:
17
+ <<: *defaults
18
+
19
+ staging:
20
+ <<: *defaults
21
+
22
+ production:
23
+ <<: *defaults
@@ -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,54 @@
1
+ # TODO: Strip this out eventually so we can run without rubygems
2
+ require 'rubygems'
3
+
4
+ require 'eventmachine'
5
+
6
+ require File.dirname(__FILE__) + '/daemon_kit/core_ext'
7
+ require File.dirname(__FILE__) + '/daemon_kit/exceptions'
8
+
9
+ $:.unshift( File.dirname(__FILE__).to_absolute_path ) unless
10
+ $:.include?( File.dirname(__FILE__).to_absolute_path )
11
+
12
+ module DaemonKit
13
+ VERSION = '0.1.7.10'
14
+
15
+ autoload :Initializer, 'daemon_kit/initializer'
16
+ autoload :Application, 'daemon_kit/application'
17
+ autoload :Arguments, 'daemon_kit/arguments'
18
+ autoload :Config, 'daemon_kit/config'
19
+ autoload :Safety, 'daemon_kit/safety'
20
+ autoload :PidFile, 'daemon_kit/pid_file'
21
+ autoload :AbstractLogger, 'daemon_kit/abstract_logger'
22
+ autoload :EM, 'daemon_kit/em'
23
+ autoload :Configurable, 'daemon_kit/core_ext/configurable'
24
+
25
+ autoload :Cron, 'daemon_kit/cron'
26
+ autoload :Jabber, 'daemon_kit/jabber'
27
+ autoload :AMQP, 'daemon_kit/amqp'
28
+ autoload :Nanite, 'daemon_kit/nanite'
29
+ autoload :RuoteParticipants, 'daemon_kit/ruote_participants'
30
+ autoload :RuoteWorkitem, 'daemon_kit/ruote_workitem'
31
+ autoload :RuotePseudoParticipant, 'daemon_kit/ruote_pseudo_participant'
32
+
33
+ class << self
34
+ def logger
35
+ @logger
36
+ end
37
+
38
+ def logger=( logger )
39
+ @logger = logger
40
+ end
41
+
42
+ def root
43
+ DAEMON_ROOT
44
+ end
45
+
46
+ def env
47
+ DAEMON_ENV
48
+ end
49
+
50
+ def framework_root
51
+ @framework_root ||= File.join( File.dirname(__FILE__), '..' ).to_absolute_path
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,235 @@
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
+ def debug( msg )
67
+ add( :debug, msg )
68
+ end
69
+
70
+ def debug?
71
+ self.level == :debug
72
+ end
73
+
74
+ def info( msg )
75
+ add( :info, msg )
76
+ end
77
+
78
+ def info?
79
+ self.level == :info
80
+ end
81
+
82
+ def warn( msg )
83
+ add( :warn, msg )
84
+ end
85
+
86
+ def warn?
87
+ self.level == :warn
88
+ end
89
+
90
+ def error( msg )
91
+ add( :error, msg )
92
+ end
93
+
94
+ def error?
95
+ self.level == :error
96
+ end
97
+
98
+ def fatal( msg )
99
+ add( :fatal, msg )
100
+ end
101
+
102
+ def fatal?
103
+ self.level == :fatal
104
+ end
105
+
106
+ def unknown( msg )
107
+ add( :unknown, msg )
108
+ end
109
+
110
+ def unknown?
111
+ self.level == :unknown
112
+ end
113
+
114
+ def exception( e )
115
+ message = "EXCEPTION: #{e.message}: #{clean_trace( e.backtrace )}"
116
+ self.add( :error, message, true )
117
+ end
118
+
119
+ def add( severity, message, skip_caller = false )
120
+ message = "#{called(caller)}: #{message}" unless skip_caller
121
+
122
+ self.logger.add( self.class.severities[ severity ] ) { message }
123
+
124
+ STDOUT.puts( message ) if self.copy_to_stdout
125
+ end
126
+
127
+ def level
128
+ self.class.severities.invert[ @logger.level ]
129
+ end
130
+
131
+ def level=( level )
132
+ level = ( Symbol === level ? self.class.severities[ level ] : level )
133
+ self.logger.level = level
134
+ end
135
+
136
+ def logger
137
+ @logger ||= create_logger
138
+ end
139
+
140
+ def logger=( logger )
141
+ if logger.is_a?( Symbol )
142
+ @backend = logger
143
+ @logger.close rescue nil
144
+ @logger = create_logger
145
+ else
146
+ @logger.close rescue nil
147
+ @logger = logger
148
+ end
149
+ end
150
+
151
+ def clean_trace( trace )
152
+ trace = trace.map { |l| l.gsub(DAEMON_ROOT, '') }
153
+ trace = trace.reject { |l| l =~ /gems\/daemon[\-_]kit/ }
154
+ trace = trace.reject { |l| l =~ /vendor\/daemon[\-_]kit/ }
155
+ trace
156
+ end
157
+
158
+ def close
159
+ case @backend
160
+ when :logger
161
+ self.logger.close
162
+ @logger = nil
163
+ end
164
+ end
165
+
166
+ private
167
+
168
+ def called( trace )
169
+ l = trace.detect('unknown:0') { |l| l.index('abstract_logger.rb').nil? }
170
+ file, num, _ = l.split(':')
171
+
172
+ [ File.basename(file), num ].join(':')
173
+ end
174
+
175
+ def create_logger
176
+ case @backend
177
+ when :logger
178
+ create_standard_logger
179
+ when :syslog
180
+ create_syslog_logger
181
+ end
182
+ end
183
+
184
+ def create_standard_logger
185
+ log_path = File.dirname( @logger_file )
186
+ unless File.directory?( log_path )
187
+ begin
188
+ FileUtils.mkdir_p( log_path )
189
+ rescue
190
+ STDERR.puts "#{log_path} not writable, using STDERR for logging"
191
+ @logger_file = STDERR
192
+ end
193
+ end
194
+
195
+ l = Logger.new( @logger_file )
196
+ l.formatter = Formatter.new
197
+ l.progname = if DaemonKit.configuration
198
+ DaemonKit.configuration.daemon_name
199
+ else
200
+ File.basename($0)
201
+ end
202
+ l
203
+ end
204
+
205
+ def create_syslog_logger
206
+ begin
207
+ require 'syslog_logger'
208
+ SyslogLogger.new( DaemonKit.configuration ? DaemonKit.configuration.daemon_name : File.basename($0) )
209
+ rescue LoadError
210
+ self.logger = :logger
211
+ self.error( "Couldn't load syslog_logger gem, reverting to standard logger" )
212
+ end
213
+ end
214
+
215
+ class Formatter
216
+
217
+ # YYYY:MM:DD HH:MM:SS.MS daemon_name(pid) level: message
218
+ @format = "%s %s(%d) [%s] %s\n"
219
+
220
+ class << self
221
+ attr_accessor :format
222
+ end
223
+
224
+ def call(severity, time, progname, msg)
225
+ self.class.format % [ format_time( time ), progname, $$, severity, msg.to_s ]
226
+ end
227
+
228
+ private
229
+
230
+ def format_time( time )
231
+ time.strftime( "%Y-%m-%d %H:%M:%S." ) + time.usec.to_s
232
+ end
233
+ end
234
+ end
235
+ end