amqp-daemon-kit 0.1.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/.gitignore +5 -0
  2. data/Configuration.txt +110 -0
  3. data/Deployment.txt +113 -0
  4. data/History.txt +131 -0
  5. data/Logging.txt +96 -0
  6. data/PostInstall.txt +6 -0
  7. data/README.rdoc +132 -0
  8. data/Rakefile +29 -0
  9. data/RuoteParticipants.txt +113 -0
  10. data/TODO.txt +27 -0
  11. data/bin/daemon-kit +18 -0
  12. data/config/website.yml +2 -0
  13. data/daemon-kit.gemspec +265 -0
  14. data/lib/daemon_kit.rb +60 -0
  15. data/lib/daemon_kit/abstract_logger.rb +249 -0
  16. data/lib/daemon_kit/application.rb +230 -0
  17. data/lib/daemon_kit/arguments.rb +165 -0
  18. data/lib/daemon_kit/commands/console.rb +38 -0
  19. data/lib/daemon_kit/commands/destroy.rb +10 -0
  20. data/lib/daemon_kit/commands/generate.rb +10 -0
  21. data/lib/daemon_kit/config.rb +113 -0
  22. data/lib/daemon_kit/console_daemon.rb +2 -0
  23. data/lib/daemon_kit/core_ext.rb +1 -0
  24. data/lib/daemon_kit/core_ext/configurable.rb +96 -0
  25. data/lib/daemon_kit/core_ext/string.rb +22 -0
  26. data/lib/daemon_kit/cron.rb +67 -0
  27. data/lib/daemon_kit/cucumber/world.rb +38 -0
  28. data/lib/daemon_kit/deployment/capistrano.rb +516 -0
  29. data/lib/daemon_kit/dk_amqp.rb +39 -0
  30. data/lib/daemon_kit/em.rb +43 -0
  31. data/lib/daemon_kit/error_handlers/base.rb +32 -0
  32. data/lib/daemon_kit/error_handlers/hoptoad.rb +180 -0
  33. data/lib/daemon_kit/exceptions.rb +15 -0
  34. data/lib/daemon_kit/generators.rb +67 -0
  35. data/lib/daemon_kit/generators/base.rb +60 -0
  36. data/lib/daemon_kit/initializer.rb +449 -0
  37. data/lib/daemon_kit/jabber.rb +171 -0
  38. data/lib/daemon_kit/nanite.rb +7 -0
  39. data/lib/daemon_kit/nanite/agent.rb +77 -0
  40. data/lib/daemon_kit/pid_file.rb +61 -0
  41. data/lib/daemon_kit/ruote_participants.rb +125 -0
  42. data/lib/daemon_kit/ruote_pseudo_participant.rb +68 -0
  43. data/lib/daemon_kit/ruote_workitem.rb +187 -0
  44. data/lib/daemon_kit/safety.rb +84 -0
  45. data/lib/daemon_kit/tasks.rb +2 -0
  46. data/lib/daemon_kit/tasks/environment.rake +11 -0
  47. data/lib/daemon_kit/tasks/framework.rake +123 -0
  48. data/lib/daemon_kit/tasks/god.rake +62 -0
  49. data/lib/daemon_kit/tasks/log.rake +8 -0
  50. data/lib/daemon_kit/tasks/monit.rake +29 -0
  51. data/lib/daemon_kit/vendor/thor-0.13.6/CHANGELOG.rdoc +89 -0
  52. data/lib/daemon_kit/vendor/thor-0.13.6/LICENSE +20 -0
  53. data/lib/daemon_kit/vendor/thor-0.13.6/README.rdoc +297 -0
  54. data/lib/daemon_kit/vendor/thor-0.13.6/Thorfile +69 -0
  55. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor.rb +244 -0
  56. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions.rb +296 -0
  57. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/create_file.rb +103 -0
  58. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/directory.rb +91 -0
  59. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/empty_directory.rb +134 -0
  60. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/file_manipulation.rb +223 -0
  61. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/inject_into_file.rb +104 -0
  62. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/base.rb +540 -0
  63. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/file_binary_read.rb +9 -0
  64. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  65. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/ordered_hash.rb +100 -0
  66. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/error.rb +30 -0
  67. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/group.rb +271 -0
  68. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/invocation.rb +180 -0
  69. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser.rb +4 -0
  70. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/argument.rb +67 -0
  71. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/arguments.rb +150 -0
  72. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/option.rb +128 -0
  73. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/options.rb +169 -0
  74. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/rake_compat.rb +66 -0
  75. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/runner.rb +314 -0
  76. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell.rb +83 -0
  77. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell/basic.rb +239 -0
  78. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell/color.rb +108 -0
  79. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/task.rb +102 -0
  80. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/util.rb +224 -0
  81. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/version.rb +3 -0
  82. data/lib/daemon_kit/xmpp.rb +100 -0
  83. data/lib/generators/daemon_kit/amqp/USAGE +5 -0
  84. data/lib/generators/daemon_kit/amqp/amqp_generator.rb +24 -0
  85. data/lib/generators/daemon_kit/amqp/templates/config/amqp.yml +28 -0
  86. data/lib/generators/daemon_kit/amqp/templates/config/pre-daemonize/amqp.rb +7 -0
  87. data/lib/generators/daemon_kit/amqp/templates/libexec/%app_name%-daemon.rb +37 -0
  88. data/lib/generators/daemon_kit/app/USAGE +7 -0
  89. data/lib/generators/daemon_kit/app/app_generator.rb +140 -0
  90. data/lib/generators/daemon_kit/app/templates/Gemfile +12 -0
  91. data/lib/generators/daemon_kit/app/templates/README.tt +58 -0
  92. data/lib/generators/daemon_kit/app/templates/Rakefile +6 -0
  93. data/lib/generators/daemon_kit/app/templates/bin/daemon.tt +7 -0
  94. data/lib/generators/daemon_kit/app/templates/config/arguments.rb +12 -0
  95. data/lib/generators/daemon_kit/app/templates/config/boot.rb +70 -0
  96. data/lib/generators/daemon_kit/app/templates/config/environment.rb.tt +26 -0
  97. data/lib/generators/daemon_kit/app/templates/config/environments/development.rb +2 -0
  98. data/lib/generators/daemon_kit/app/templates/config/environments/production.rb +5 -0
  99. data/lib/generators/daemon_kit/app/templates/config/environments/test.rb +2 -0
  100. data/lib/generators/daemon_kit/app/templates/config/post-daemonize/readme +5 -0
  101. data/lib/generators/daemon_kit/app/templates/config/pre-daemonize/readme +12 -0
  102. data/lib/generators/daemon_kit/app/templates/lib/%app_name%.rb +2 -0
  103. data/lib/generators/daemon_kit/app/templates/libexec/%app_name%-daemon.rb +18 -0
  104. data/lib/generators/daemon_kit/app/templates/script/console +3 -0
  105. data/lib/generators/daemon_kit/app/templates/script/destroy +3 -0
  106. data/lib/generators/daemon_kit/app/templates/script/generate +3 -0
  107. data/lib/generators/daemon_kit/capistrano/capistrano_generator.rb +26 -0
  108. data/lib/generators/daemon_kit/capistrano/templates/Capfile +10 -0
  109. data/lib/generators/daemon_kit/capistrano/templates/USAGE +10 -0
  110. data/lib/generators/daemon_kit/capistrano/templates/config/deploy.rb.tt +67 -0
  111. data/lib/generators/daemon_kit/capistrano/templates/config/deploy/logrotate.erb +13 -0
  112. data/lib/generators/daemon_kit/capistrano/templates/config/deploy/production.rb.tt +6 -0
  113. data/lib/generators/daemon_kit/capistrano/templates/config/deploy/staging.rb.tt +6 -0
  114. data/lib/generators/daemon_kit/capistrano/templates/config/environments/staging.rb +0 -0
  115. data/lib/generators/daemon_kit/cron/USAGE +5 -0
  116. data/lib/generators/daemon_kit/cron/cron_generator.rb +24 -0
  117. data/lib/generators/daemon_kit/cron/templates/config/pre-daemonize/cron.rb +11 -0
  118. data/lib/generators/daemon_kit/cron/templates/libexec/%app_name%-daemon.rb +48 -0
  119. data/lib/generators/daemon_kit/cucumber/USAGE +11 -0
  120. data/lib/generators/daemon_kit/cucumber/cucumber_generator.rb +45 -0
  121. data/lib/generators/daemon_kit/cucumber/templates/config/environments/cucumber.rb +2 -0
  122. data/lib/generators/daemon_kit/cucumber/templates/features/step_definitions/.empty_directory +0 -0
  123. data/lib/generators/daemon_kit/cucumber/templates/features/support/env.rb +7 -0
  124. data/lib/generators/daemon_kit/cucumber/templates/script/cucumber +7 -0
  125. data/lib/generators/daemon_kit/cucumber/templates/tasks/cucumber.rake +13 -0
  126. data/lib/generators/daemon_kit/nanite_agent/USAGE +5 -0
  127. data/lib/generators/daemon_kit/nanite_agent/nanite_agent_generator.rb +29 -0
  128. data/lib/generators/daemon_kit/nanite_agent/templates/config/nanite.yml +35 -0
  129. data/lib/generators/daemon_kit/nanite_agent/templates/config/pre-daemonize/nanite_agent.rb +6 -0
  130. data/lib/generators/daemon_kit/nanite_agent/templates/lib/actors/sample.rb +11 -0
  131. data/lib/generators/daemon_kit/nanite_agent/templates/libexec/%app_name%-daemon.rb +31 -0
  132. data/lib/generators/daemon_kit/rspec/USAGE +5 -0
  133. data/lib/generators/daemon_kit/rspec/rspec_generator.rb +20 -0
  134. data/lib/generators/daemon_kit/rspec/templates/spec/%app_name%_spec.rb +11 -0
  135. data/lib/generators/daemon_kit/rspec/templates/spec/spec.opts +1 -0
  136. data/lib/generators/daemon_kit/rspec/templates/spec/spec_helper.rb +23 -0
  137. data/lib/generators/daemon_kit/rspec/templates/tasks/rspec.rake +21 -0
  138. data/lib/generators/daemon_kit/ruote/USAGE +5 -0
  139. data/lib/generators/daemon_kit/ruote/ruote_generator.rb +29 -0
  140. data/lib/generators/daemon_kit/ruote/templates/config/amqp.yml +30 -0
  141. data/lib/generators/daemon_kit/ruote/templates/config/pre-daemonize/ruote.rb +13 -0
  142. data/lib/generators/daemon_kit/ruote/templates/config/ruote.yml +23 -0
  143. data/lib/generators/daemon_kit/ruote/templates/lib/%app_name%.rb +4 -0
  144. data/lib/generators/daemon_kit/ruote/templates/lib/sample.rb +26 -0
  145. data/lib/generators/daemon_kit/ruote/templates/libexec/%app_name%-daemon.rb +33 -0
  146. data/lib/generators/daemon_kit/test_unit/USAGE +5 -0
  147. data/lib/generators/daemon_kit/test_unit/templates/tasks/test_unit.rake +7 -0
  148. data/lib/generators/daemon_kit/test_unit/templates/test/%app_name%_test.rb.tt +9 -0
  149. data/lib/generators/daemon_kit/test_unit/templates/test/test_helper.rb +6 -0
  150. data/lib/generators/daemon_kit/test_unit/test_unit_generator.rb +20 -0
  151. data/lib/generators/daemon_kit/xmpp/templates/config/pre-daemonize/xmpp.rb +6 -0
  152. data/lib/generators/daemon_kit/xmpp/templates/config/xmpp.yml +29 -0
  153. data/lib/generators/daemon_kit/xmpp/templates/libexec/%app_name%-daemon.rb +27 -0
  154. data/lib/generators/daemon_kit/xmpp/xmpp_generator.rb +24 -0
  155. data/script/console +10 -0
  156. data/script/destroy +14 -0
  157. data/script/generate +14 -0
  158. data/script/txt2html +71 -0
  159. data/spec/abstract_logger_spec.rb +126 -0
  160. data/spec/argument_spec.rb +70 -0
  161. data/spec/config_spec.rb +83 -0
  162. data/spec/configurable_spec.rb +56 -0
  163. data/spec/daemon_kit_spec.rb +7 -0
  164. data/spec/error_handlers_spec.rb +23 -0
  165. data/spec/fixtures/env.yml +15 -0
  166. data/spec/fixtures/noenv.yml +4 -0
  167. data/spec/initializer_spec.rb +26 -0
  168. data/spec/spec.opts +1 -0
  169. data/spec/spec_helper.rb +27 -0
  170. data/tasks/cucumber.rake +13 -0
  171. data/tasks/rspec.rake +20 -0
  172. data/tasks/tests.rake +6 -0
  173. data/templates/god/god.erb +69 -0
  174. data/templates/monit/monit.erb +14 -0
  175. data/test/test_amqp_generator.rb +48 -0
  176. data/test/test_cron_generator.rb +45 -0
  177. data/test/test_daemon-kit_generator.rb +84 -0
  178. data/test/test_daemon_kit_config.rb +28 -0
  179. data/test/test_deploy_capistrano_generator.rb +48 -0
  180. data/test/test_generator_helper.rb +29 -0
  181. data/test/test_helper.rb +7 -0
  182. data/test/test_nanite_agent_generator.rb +49 -0
  183. data/test/test_ruote_generator.rb +51 -0
  184. data/test/test_test_unit_generator.rb +46 -0
  185. metadata +302 -0
@@ -0,0 +1,12 @@
1
+ # If you need to 'vendor your gems' for deploying your daemons, bundler is a
2
+ # great option. Update this Gemfile with any additional dependencies and run
3
+ # 'bundle install' to get them all installed. Daemon-kit's capistrano
4
+ # deployment will ensure that the bundle required by your daemon is properly
5
+ # installed.
6
+
7
+ source :gemcutter
8
+
9
+ # daemon-kit
10
+ gem 'daemon-kit'
11
+
12
+ # For more information on bundler, please visit http://gembundler.com
@@ -0,0 +1,58 @@
1
+ daemon-kit README
2
+ ================
3
+
4
+ daemon-kit has generated a skeleton Ruby daemon for you to build on. Please read
5
+ through this file to ensure you get going quickly.
6
+
7
+ Directories
8
+ ===========
9
+
10
+ bin/
11
+ <%= app_name %> - Stub executable to control your daemon with
12
+
13
+ config/
14
+ Environment configuration files
15
+
16
+ lib/
17
+ Place for your libraries
18
+
19
+ libexec/
20
+ <%= app_name %>.rb - Your daemon code
21
+
22
+ log/
23
+ Log files based on the environment name
24
+
25
+ spec/
26
+ rspec's home
27
+
28
+ tasks/
29
+ Place for rake tasks
30
+
31
+ vendor/
32
+ Place for unpacked gems and DaemonKit
33
+
34
+ tmp/
35
+ Scratch folder
36
+
37
+
38
+ Logging
39
+ =======
40
+
41
+ One of the biggest issues with writing daemons are getting insight into what your
42
+ daemons are doing. Logging with daemon-kit is simplified as DaemonKit creates log
43
+ files per environment in log.
44
+
45
+ On all environments except production the log level is set to DEBUG, but you can
46
+ toggle the log level by sending the running daemon SIGUSR1 and SIGUSR2 signals.
47
+ SIGUSR1 will toggle between DEBUG and INFO levels, SIGUSR2 will blatantly set the
48
+ level to DEBUG.
49
+
50
+ Bundler
51
+ =======
52
+
53
+ daemon-kit uses bundler to ease the nightmare of dependency loading in Ruby
54
+ projects. daemon-kit and its generators all create/update the Gemfile in the
55
+ root of the daemon. You can satisfy the project's dependencies by running
56
+ `bundle install` from within the project root.
57
+
58
+ For more information on bundler, please see http://github.com/carlhuda/bundler
@@ -0,0 +1,6 @@
1
+ require File.expand_path('../config/boot', __FILE__)
2
+
3
+ require 'rake'
4
+ require 'daemon_kit/tasks'
5
+
6
+ Dir[File.join(File.dirname(__FILE__), 'tasks/*.rake')].each { |rake| load rake }
@@ -0,0 +1,7 @@
1
+ #
2
+ # Stub executable for <%= app_name %>
3
+ #
4
+
5
+ require File.expand_path('../../config/environment', __FILE__)
6
+
7
+ DaemonKit::Application.exec( DAEMON_ROOT + '/libexec/<%= app_name %>-daemon.rb' )
@@ -0,0 +1,12 @@
1
+ # Argument handling for your daemon is configured here.
2
+ #
3
+ # You have access to two variables when this file is
4
+ # parsed. The first is +opts+, which is the object yielded from
5
+ # +OptionParser.new+, the second is +@options+ which is a standard
6
+ # Ruby hash that is later accessible through
7
+ # DaemonKit.arguments.options and can be used in your daemon process.
8
+
9
+ # Here is an example:
10
+ # opts.on('-f', '--foo FOO', 'Set foo') do |foo|
11
+ # @options[:foo] = foo
12
+ # end
@@ -0,0 +1,70 @@
1
+ # Don't change this file!
2
+ # Configure your daemon in config/environment.rb
3
+
4
+ DAEMON_ROOT = "#{File.expand_path(File.dirname(__FILE__))}/.." unless defined?( DAEMON_ROOT )
5
+
6
+ # Use Bundler (preferred)
7
+ begin
8
+ require File.expand_path('../../.bundle/environment', __FILE__)
9
+ rescue LoadError
10
+ require 'rubygems'
11
+ require 'bundler'
12
+ Bundler.setup
13
+ end
14
+
15
+ module DaemonKit
16
+ class << self
17
+ def boot!
18
+ unless booted?
19
+ pick_boot.run
20
+ end
21
+ end
22
+
23
+ def booted?
24
+ defined? DaemonKit::Initializer
25
+ end
26
+
27
+ def pick_boot
28
+ (vendor_kit? ? VendorBoot : GemBoot).new
29
+ end
30
+
31
+ def vendor_kit?
32
+ File.exists?( "#{DAEMON_ROOT}/vendor/daemon-kit" )
33
+ end
34
+ end
35
+
36
+ class Boot
37
+ def run
38
+ load_initializer
39
+ DaemonKit::Initializer.run
40
+ end
41
+ end
42
+
43
+ class VendorBoot < Boot
44
+ def load_initializer
45
+ require "#{DAEMON_ROOT}/vendor/daemon-kit/lib/daemon_kit/initializer"
46
+ end
47
+ end
48
+
49
+ class GemBoot < Boot
50
+ def load_initializer
51
+ begin
52
+ require 'rubygems' unless defined?( ::Gem )
53
+ gem 'daemon-kit'
54
+ require 'daemon_kit/initializer'
55
+ rescue ::Gem::LoadError => e
56
+ msg = <<EOF
57
+
58
+ You are missing the daemon-kit gem. Please install the following gem:
59
+
60
+ sudo gem install daemon-kit
61
+
62
+ EOF
63
+ $stderr.puts msg
64
+ exit 1
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ DaemonKit.boot!
@@ -0,0 +1,26 @@
1
+ # Be sure to restart your daemon when you modify this file
2
+
3
+ # Uncomment below to force your daemon into production mode
4
+ #ENV['DAEMON_ENV'] ||= 'production'
5
+
6
+ # Boot up
7
+ require File.join(File.dirname(__FILE__), 'boot')
8
+
9
+ # Auto-require default libraries and those for the current Rails environment.
10
+ Bundler.require :default, DaemonKit.env
11
+
12
+ DaemonKit::Initializer.run do |config|
13
+
14
+ # The name of the daemon as reported by process monitoring tools
15
+ config.daemon_name = '<%= app_name %>'
16
+
17
+ # Force the daemon to be killed after X seconds from asking it to
18
+ # config.force_kill_wait = 30
19
+
20
+ # Log backraces when a thread/daemon dies (Recommended)
21
+ # config.backtraces = true
22
+
23
+ # Configure the safety net (see DaemonKit::Safety)
24
+ # config.safety_net.handler = :hoptoad
25
+ # config.safety_net.hoptoad.api_key = ''
26
+ end
@@ -0,0 +1,2 @@
1
+ # This is the same context as the environment.rb file, it is only
2
+ # loaded afterwards and only in the development environment
@@ -0,0 +1,5 @@
1
+ # This is the same context as the environment.rb file, it is only
2
+ # loaded afterwards and only in the production environment
3
+
4
+ # Change the production log level to debug
5
+ #config.log_level = :debug
@@ -0,0 +1,2 @@
1
+ # This is the same context as the environment.rb file, it is only
2
+ # loaded afterwards and only in the test environment
@@ -0,0 +1,5 @@
1
+ # You can place files in here to be loaded after the code is daemonized.
2
+ #
3
+ # All the files placed here will just be required into the running
4
+ # process. This is the correct place to open any IO objects, establish
5
+ # database connections, etc.
@@ -0,0 +1,12 @@
1
+ # You can place files in here to be loaded before the code is daemonized.
2
+ #
3
+ # DaemonKit looks for a file named '<config.daemon_name>.rb' and loads
4
+ # that file first, and inside a DaemonKit::Initializer block. The
5
+ # remaning files then simply required into the running process.
6
+ #
7
+ # These files are mostly useful for operations that should fail blatantly
8
+ # before daemonizing, like loading gems.
9
+ #
10
+ # Be careful not to open any form of IO in here and expecting it to be
11
+ # open inside the running daemon since all IO instances are closed when
12
+ # daemonizing (including STDIN, STDOUT & STDERR).
@@ -0,0 +1,2 @@
1
+ # Your starting point for daemon specific classes. This directory is
2
+ # already included in your load path, so no need to specify it.
@@ -0,0 +1,18 @@
1
+ # Change this file to be a wrapper around your daemon code.
2
+
3
+ # Do your post daemonization configuration here
4
+ # At minimum you need just the first line (without the block), or a lot
5
+ # of strange things might start happening...
6
+ DaemonKit::Application.running! do |config|
7
+ # Trap signals with blocks or procs
8
+ # config.trap( 'INT' ) do
9
+ # # do something clever
10
+ # end
11
+ # config.trap( 'TERM', Proc.new { puts 'Going down' } )
12
+ end
13
+
14
+ # Sample loop to show process
15
+ loop do
16
+ DaemonKit.logger.info "I'm running"
17
+ sleep 60
18
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'daemon_kit/commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path( '../../config/environment', __FILE__ )
3
+ require 'daemon_kit/commands/generate'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path( '../../config/environment', __FILE__ )
3
+ require 'daemon_kit/commands/generate'
@@ -0,0 +1,26 @@
1
+ module DaemonKit
2
+ module Generators
3
+ class CapistranoGenerator < Base
4
+
5
+ def update_gemfile
6
+ append_file 'Gemfile', "gem 'capistrano'\n"
7
+ append_file 'Gemfile', "gem 'capistrano-ext'\n"
8
+ end
9
+
10
+ def create_capfile
11
+ copy_file 'Capfile'
12
+ end
13
+
14
+ def create_config
15
+ directory 'config'
16
+ end
17
+
18
+ protected
19
+
20
+ def self.source_root
21
+ File.expand_path( File.join( File.dirname(__FILE__), 'templates') )
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,10 @@
1
+ unless respond_to?(:namespace) # cap2 differentiator
2
+ $stderr.puts "Requires capistrano version 2"
3
+ exit 1
4
+ end
5
+
6
+ require 'config/boot'
7
+ load DaemonKit.framework_root + '/lib/daemon_kit/deployment/capistrano.rb'
8
+
9
+ Dir['config/deploy/recipes/*.rb'].each { |plugin| load(plugin) }
10
+ load 'config/deploy.rb'
@@ -0,0 +1,10 @@
1
+
2
+ Capistrano deployment configuration generator completed
3
+
4
+ Usage:
5
+ Review the configuration files in config/deploy.rb and
6
+ config/deploy/*.rb
7
+
8
+ Once you're happy with the configurations, you can review
9
+ a list of available capistrano commands by running `cap -T'
10
+
@@ -0,0 +1,67 @@
1
+ # Modified capistrano recipe, based on the standard 'deploy' recipe
2
+ # provided by capistrano but without the Rails-specific dependencies
3
+
4
+ set :stages, %w(staging production)
5
+ set :default_stage, "staging"
6
+ require "capistrano/ext/multistage"
7
+
8
+ # Set some globals
9
+ default_run_options[:pty] = true
10
+ set :application, "<%= app_name %>"
11
+
12
+ # Deployment
13
+ set :deploy_to, "/svc/#{application}"
14
+ #set :user, 'someone'
15
+
16
+ # Get repo configuration
17
+ set :repository, "git@github.com:yourname/#{application}.git"
18
+ set :scm, "git"
19
+ set :branch, "master"
20
+ set :deploy_via, :remote_cache
21
+ set :git_enable_submodules, 1
22
+
23
+ # No sudo
24
+ set :use_sudo, false
25
+
26
+ # File list in the config_files setting will be copied from the
27
+ # 'deploy_to' directory into config, overwriting files from the repo
28
+ # with the same name
29
+ set :config_files, %w{}
30
+
31
+ # List any work directories here that you need persisted between
32
+ # deployments. They are created in 'deploy_to'/shared and symlinked
33
+ # into the root directory of the deployment.
34
+ set :shared_children, %w{log tmp}
35
+
36
+ # Record our dependencies
37
+ unless File.directory?( "#{DaemonKit.root}/vendor/daemon_kit" )
38
+ depend :remote, :gem, "daemon-kit", ">=#{DaemonKit::VERSION}"
39
+ end
40
+
41
+ # Hook into capistrano's events
42
+ before "deploy:update_code", "deploy:check"
43
+
44
+ # Setup log rotation support with every deploy (safe)
45
+ #after 'deploy:symlink', 'deploy:logrotate'
46
+
47
+ # Create some tasks related to deployment
48
+ namespace :deploy do
49
+
50
+ desc "Get the current revision of the deployed code"
51
+ task :get_current_version do
52
+ run "cat #{current_path}/REVISION" do |ch, stream, out|
53
+ puts "Current revision: " + out.chomp
54
+ end
55
+ end
56
+
57
+ desc "Install log rotation script on server"
58
+ task :logrotate do
59
+ require 'erb'
60
+ upload_path = "#{shared_path}/system/logrotate"
61
+ template = File.read("config/deploy/logrotate.erb")
62
+ file = ERB.new(template).result(binding)
63
+ put file, upload_path, :mode => 0644
64
+ run "if [ -e /etc/logrotate.d ]; then sudo cp #{shared_path}/system/logrotate /etc/logrotate.d/#{name}; fi"
65
+ end
66
+
67
+ end
@@ -0,0 +1,13 @@
1
+ <%= shared_path %>/log/*.log {
2
+ daily
3
+ missingok
4
+ compress
5
+ rotate 7
6
+ sharedscripts
7
+
8
+ postrotate
9
+ for i in <%= shared_path %>/pids/*.pid; do
10
+ kill -HUP `cat $i`
11
+ done
12
+ endscript
13
+ }
@@ -0,0 +1,6 @@
1
+ #set :deploy_to, "/svc/<%= app_name %>" # defaults to "/u/apps/#{application}"
2
+ #set :user, "<%= app_name %>" # defaults to the currently logged in user
3
+ set :daemon_env, 'production'
4
+
5
+ set :domain, 'example.com'
6
+ server domain
@@ -0,0 +1,6 @@
1
+ #set :deploy_to, "/svc/<%= app_name %>" # defaults to "/u/apps/#{application}"
2
+ #set :user, "<%= app_name %>" # defaults to the currently logged in user
3
+ set :daemon_env, 'staging'
4
+
5
+ set :domain, 'example.com'
6
+ server domain
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,24 @@
1
+ module DaemonKit
2
+ module Generators
3
+ class CronGenerator < Base
4
+
5
+ def update_gemfile
6
+ append_file 'Gemfile', "gem 'rufus-scheduler', '>= 2.0.3'\n"
7
+ end
8
+
9
+ def create_initializers
10
+ directory 'config'
11
+ end
12
+
13
+ def create_daemon
14
+ directory 'libexec'
15
+ end
16
+
17
+ protected
18
+
19
+ def self.source_root
20
+ File.expand_path( File.join( File.dirname(__FILE__), 'templates') )
21
+ end
22
+ end
23
+ end
24
+ end