Permalink
Browse files

Capistrano support, built for daemons

  • Loading branch information...
1 parent 1d76e21 commit 189936caa2f5064048f1aedcd891b14ee1fe9a2c @kennethkalmer committed May 26, 2009
View
@@ -28,6 +28,13 @@ daemon_generators/cron/USAGE
daemon_generators/cron/cron_generator.rb
daemon_generators/cron/templates/config/initializers/cron.rb
daemon_generators/cron/templates/libexec/daemon.rb
+daemon_generators/deploy_capistrano/USAGE
+daemon_generators/deploy_capistrano/deploy_capistrano_generator.rb
+daemon_generators/deploy_capistrano/templates/Capfile
+daemon_generators/deploy_capistrano/templates/config/deploy.rb
+daemon_generators/deploy_capistrano/templates/config/deploy/production.rb
+daemon_generators/deploy_capistrano/templates/config/deploy/staging.rb
+daemon_generators/deploy_capistrano/templates/config/environments/staging.rb
daemon_generators/jabber/USAGE
daemon_generators/jabber/jabber_generator.rb
daemon_generators/jabber/templates/config/initializers/jabber.rb
@@ -44,6 +51,7 @@ lib/daemon_kit/amqp.rb
lib/daemon_kit/application.rb
lib/daemon_kit/config.rb
lib/daemon_kit/cron.rb
+lib/daemon_kit/deployment/capistrano.rb
lib/daemon_kit/error_handlers/base.rb
lib/daemon_kit/error_handlers/hoptoad.rb
lib/daemon_kit/error_handlers/mail.rb
@@ -75,6 +83,7 @@ test/test_amqp_generator.rb
test/test_cron_generator.rb
test/test_daemon-kit_generator.rb
test/test_daemon_kit_config.rb
+test/test_deploy_capistrano_generator.rb
test/test_generator_helper.rb
test/test_helper.rb
test/test_jabber_generator.rb
@@ -5,10 +5,13 @@ class DaemonKitGenerator < RubiGen::Base
VALID_GENERATORS = ['default', 'jabber', 'cron', 'amqp', 'nanite_agent']
+ DEPLOYERS = ['none', 'capistrano']
+
default_options :shebang => DEFAULT_SHEBANG, :author => nil
attr_reader :daemon_name
attr_reader :installer
+ attr_reader :deployer
def initialize(runtime_args, runtime_options = {})
super
@@ -26,6 +29,12 @@ def manifest
exit 1
end
+ unless DEPLOYERS.include?( deployer )
+ $stderr.puts "Invalid deployment mechanism: '#{deployer}'."
+ $stderr.puts "Valid deployers are: #{DEPLOYERS.join(', ')}"
+ exit 1
+ end
+
script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
record do |m|
@@ -75,6 +84,11 @@ def manifest
# Tests
m.dependency "install_rspec", [daemon_name], :destination => destination_root, :collision => :force
+ # Deployers
+ unless deployer == 'none'
+ m.dependency "deploy_#{deployer}", [daemon_name], :destination => destination_root, :collision => :force
+ end
+
# Others
m.directory "log"
m.directory "tmp"
@@ -102,12 +116,21 @@ def add_options!(opts)
# opts.on("-a", "--author=\"Your Name\"", String,
# "Some comment about this option",
# "Default: none") { |o| options[:author] = o }
+
opts.on("-i", "--install=generator", String,
"Select a generator to use (other than the default).",
"Available generators: #{VALID_GENERATORS.join(', ')}",
"Defaults to: default") do |installer|
options[:installer] = installer
end
+
+ opts.on("-d", "--deploy-with=config", String,
+ "Select an optional deployment mechanism.",
+ "Available deployers: #{DEPLOYERS.join(', ')}",
+ "Defaults to: none") do |deploy|
+ options[:deployer] = deploy
+ end
+
opts.on("-r", "--ruby=path", String,
"Path to the Ruby binary of your choice (otherwise scripts use env, dispatchers current path).",
"Default: #{DEFAULT_SHEBANG}") { |x| options[:shebang] = x }
@@ -120,6 +143,7 @@ def extract_options
# raw instance variable value.
# @author = options[:author]
@installer = options[:installer] || 'default'
+ @deployer = (options[:deployer] || 'none').strip
end
end
View
@@ -2,17 +2,17 @@
Gem::Specification.new do |s|
s.name = %q{daemon-kit}
- s.version = "0.1.6"
+ s.version = "0.1.7"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Kenneth Kalmer"]
- s.date = %q{2009-05-25}
+ s.date = %q{2009-05-26}
s.default_executable = %q{daemon_kit}
s.description = %q{Daemon Kit aims to simplify creating Ruby daemons by providing a sound application skeleton (through a generator), task specific generators (jabber bot, etc) and robust environment management code. Using simple built-in generators it is easy to created evented and non-evented daemons that perform a multitude of different tasks. Supported generators: * Evented and non-evented Jabber Bot (coming next) * Evented and non-evented loops (coming soon) * Queue poller (SQS, AMQP, etc) (coming soon)}
s.email = ["kenneth.kalmer@gmail.com"]
s.executables = ["daemon_kit"]
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "TODO.txt"]
- s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "TODO.txt", "app_generators/daemon_kit/USAGE", "app_generators/daemon_kit/daemon_kit_generator.rb", "app_generators/daemon_kit/templates/README", "app_generators/daemon_kit/templates/Rakefile", "app_generators/daemon_kit/templates/bin/daemon.erb", "app_generators/daemon_kit/templates/config/boot.rb", "app_generators/daemon_kit/templates/config/environment.rb", "app_generators/daemon_kit/templates/config/environments/development.rb", "app_generators/daemon_kit/templates/config/environments/production.rb", "app_generators/daemon_kit/templates/config/environments/test.rb", "app_generators/daemon_kit/templates/config/post-daemonize/readme", "app_generators/daemon_kit/templates/config/pre-daemonize/readme", "app_generators/daemon_kit/templates/lib/daemon.rb", "app_generators/daemon_kit/templates/libexec/daemon.erb", "bin/daemon_kit", "daemon_generators/amqp/USAGE", "daemon_generators/amqp/amqp_generator.rb", "daemon_generators/amqp/templates/config/amqp.yml", "daemon_generators/amqp/templates/config/initializers/amqp.rb", "daemon_generators/amqp/templates/libexec/daemon.rb", "daemon_generators/cron/USAGE", "daemon_generators/cron/cron_generator.rb", "daemon_generators/cron/templates/config/initializers/cron.rb", "daemon_generators/cron/templates/libexec/daemon.rb", "daemon_generators/jabber/USAGE", "daemon_generators/jabber/jabber_generator.rb", "daemon_generators/jabber/templates/config/initializers/jabber.rb", "daemon_generators/jabber/templates/config/jabber.yml", "daemon_generators/jabber/templates/libexec/daemon.rb", "daemon_generators/nanite_agent/USAGE", "daemon_generators/nanite_agent/nanite_agent_generator.rb", "daemon_generators/nanite_agent/templates/config/initializers/nanite_agent.rb", "daemon_generators/nanite_agent/templates/config/nanite.yml", "daemon_generators/nanite_agent/templates/lib/actors/sample.rb", "daemon_generators/nanite_agent/templates/libexec/daemon.rb", "lib/daemon_kit.rb", "lib/daemon_kit/amqp.rb", "lib/daemon_kit/application.rb", "lib/daemon_kit/config.rb", "lib/daemon_kit/cron.rb", "lib/daemon_kit/error_handlers/base.rb", "lib/daemon_kit/error_handlers/hoptoad.rb", "lib/daemon_kit/error_handlers/mail.rb", "lib/daemon_kit/initializer.rb", "lib/daemon_kit/jabber.rb", "lib/daemon_kit/nanite.rb", "lib/daemon_kit/nanite/agent.rb", "lib/daemon_kit/patches/force_kill_wait.rb", "lib/daemon_kit/safety.rb", "lib/daemon_kit/tasks.rb", "lib/daemon_kit/tasks/environment.rake", "lib/daemon_kit/tasks/framework.rake", "rubygems_generators/install_rspec/USAGE", "rubygems_generators/install_rspec/install_rspec_generator.rb", "rubygems_generators/install_rspec/templates/spec.rb", "rubygems_generators/install_rspec/templates/spec/spec.opts", "rubygems_generators/install_rspec/templates/spec/spec_helper.rb", "rubygems_generators/install_rspec/templates/tasks/rspec.rake", "script/console", "script/destroy", "script/generate", "script/txt2html", "spec/daemon_kit_spec.rb", "spec/initializer_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake", "test/test_amqp_generator.rb", "test/test_cron_generator.rb", "test/test_daemon-kit_generator.rb", "test/test_daemon_kit_config.rb", "test/test_generator_helper.rb", "test/test_helper.rb", "test/test_jabber_generator.rb", "test/test_nanite_agent_generator.rb"]
+ s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "TODO.txt", "app_generators/daemon_kit/USAGE", "app_generators/daemon_kit/daemon_kit_generator.rb", "app_generators/daemon_kit/templates/README", "app_generators/daemon_kit/templates/Rakefile", "app_generators/daemon_kit/templates/bin/daemon.erb", "app_generators/daemon_kit/templates/config/boot.rb", "app_generators/daemon_kit/templates/config/environment.rb", "app_generators/daemon_kit/templates/config/environments/development.rb", "app_generators/daemon_kit/templates/config/environments/production.rb", "app_generators/daemon_kit/templates/config/environments/test.rb", "app_generators/daemon_kit/templates/config/post-daemonize/readme", "app_generators/daemon_kit/templates/config/pre-daemonize/readme", "app_generators/daemon_kit/templates/lib/daemon.rb", "app_generators/daemon_kit/templates/libexec/daemon.erb", "bin/daemon_kit", "daemon_generators/amqp/USAGE", "daemon_generators/amqp/amqp_generator.rb", "daemon_generators/amqp/templates/config/amqp.yml", "daemon_generators/amqp/templates/config/initializers/amqp.rb", "daemon_generators/amqp/templates/libexec/daemon.rb", "daemon_generators/cron/USAGE", "daemon_generators/cron/cron_generator.rb", "daemon_generators/cron/templates/config/initializers/cron.rb", "daemon_generators/cron/templates/libexec/daemon.rb", "daemon_generators/deploy_capistrano/USAGE", "daemon_generators/deploy_capistrano/deploy_capistrano_generator.rb", "daemon_generators/deploy_capistrano/templates/Capfile", "daemon_generators/deploy_capistrano/templates/config/deploy.rb", "daemon_generators/deploy_capistrano/templates/config/deploy/production.rb", "daemon_generators/deploy_capistrano/templates/config/deploy/staging.rb", "daemon_generators/deploy_capistrano/templates/config/environments/staging.rb", "daemon_generators/jabber/USAGE", "daemon_generators/jabber/jabber_generator.rb", "daemon_generators/jabber/templates/config/initializers/jabber.rb", "daemon_generators/jabber/templates/config/jabber.yml", "daemon_generators/jabber/templates/libexec/daemon.rb", "daemon_generators/nanite_agent/USAGE", "daemon_generators/nanite_agent/nanite_agent_generator.rb", "daemon_generators/nanite_agent/templates/config/initializers/nanite_agent.rb", "daemon_generators/nanite_agent/templates/config/nanite.yml", "daemon_generators/nanite_agent/templates/lib/actors/sample.rb", "daemon_generators/nanite_agent/templates/libexec/daemon.rb", "lib/daemon_kit.rb", "lib/daemon_kit/amqp.rb", "lib/daemon_kit/application.rb", "lib/daemon_kit/config.rb", "lib/daemon_kit/cron.rb", "lib/daemon_kit/deployment/capistrano.rb", "lib/daemon_kit/error_handlers/base.rb", "lib/daemon_kit/error_handlers/hoptoad.rb", "lib/daemon_kit/error_handlers/mail.rb", "lib/daemon_kit/initializer.rb", "lib/daemon_kit/jabber.rb", "lib/daemon_kit/nanite.rb", "lib/daemon_kit/nanite/agent.rb", "lib/daemon_kit/patches/force_kill_wait.rb", "lib/daemon_kit/safety.rb", "lib/daemon_kit/tasks.rb", "lib/daemon_kit/tasks/environment.rake", "lib/daemon_kit/tasks/framework.rake", "rubygems_generators/install_rspec/USAGE", "rubygems_generators/install_rspec/install_rspec_generator.rb", "rubygems_generators/install_rspec/templates/spec.rb", "rubygems_generators/install_rspec/templates/spec/spec.opts", "rubygems_generators/install_rspec/templates/spec/spec_helper.rb", "rubygems_generators/install_rspec/templates/tasks/rspec.rake", "script/console", "script/destroy", "script/generate", "script/txt2html", "spec/daemon_kit_spec.rb", "spec/initializer_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake", "test/test_amqp_generator.rb", "test/test_cron_generator.rb", "test/test_daemon-kit_generator.rb", "test/test_daemon_kit_config.rb", "test/test_deploy_capistrano_generator.rb", "test/test_generator_helper.rb", "test/test_helper.rb", "test/test_jabber_generator.rb", "test/test_nanite_agent_generator.rb"]
s.has_rdoc = true
s.homepage = %q{http://kit.rubyforge.org/daemon (coming soon)}
s.post_install_message = %q{
@@ -27,7 +27,7 @@ To get started quickly run 'daemon_kit' without any arguments
s.rubyforge_project = %q{daemon-kit}
s.rubygems_version = %q{1.3.1}
s.summary = %q{Daemon Kit aims to simplify creating Ruby daemons by providing a sound application skeleton (through a generator), task specific generators (jabber bot, etc) and robust environment management code.}
- s.test_files = ["test/test_generator_helper.rb", "test/test_jabber_generator.rb", "test/test_cron_generator.rb", "test/test_amqp_generator.rb", "test/test_nanite_agent_generator.rb", "test/test_daemon-kit_generator.rb", "test/test_daemon_kit_config.rb", "test/test_helper.rb"]
+ s.test_files = ["test/test_generator_helper.rb", "test/test_jabber_generator.rb", "test/test_cron_generator.rb", "test/test_amqp_generator.rb", "test/test_nanite_agent_generator.rb", "test/test_daemon-kit_generator.rb", "test/test_daemon_kit_config.rb", "test/test_helper.rb", "test/test_deploy_capistrano_generator.rb"]
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -0,0 +1,5 @@
+Description:
+
+
+Usage:
+
@@ -0,0 +1,54 @@
+class DeployCapistranoGenerator < RubiGen::Base
+
+ default_options :author => nil
+
+ attr_reader :name
+
+ def initialize(runtime_args, runtime_options = {})
+ super
+ usage if args.empty?
+ @name = args.shift
+ extract_options
+ end
+
+ def manifest
+ record do |m|
+
+ m.file "Capfile", "Capfile"
+ m.directory "config"
+ m.template "config/deploy.rb", "config/deploy.rb"
+ m.directory "config/deploy"
+ m.template "config/deploy/staging.rb", "config/deploy/staging.rb"
+ m.template "config/deploy/production.rb", "config/deploy/production.rb"
+ m.directory "config/environments"
+ m.file "config/environments/staging.rb", "config/environments/staging.rb", :collision => :skip
+ end
+ end
+
+ protected
+ def banner
+ <<-EOS
+Creates a ...
+
+USAGE: #{$0} #{spec.name} name
+EOS
+ end
+
+ def add_options!(opts)
+ # opts.separator ''
+ # opts.separator 'Options:'
+ # For each option below, place the default
+ # at the top of the file next to "default_options"
+ # opts.on("-a", "--author=\"Your Name\"", String,
+ # "Some comment about this option",
+ # "Default: none") { |o| options[:author] = o }
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
+ end
+
+ def extract_options
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
+ # Templates can access these value via the attr_reader-generated methods, but not the
+ # raw instance variable value.
+ # @author = options[:author]
+ end
+end
@@ -0,0 +1,10 @@
+unless respond_to?(:namespace) # cap2 differentiator
+ $stderr.puts "Requires capistrano version 2"
+ exit 1
+end
+
+require 'config/boot'
+load DaemonKit.framework_root + '/lib/daemon_kit/deployment/capistrano.rb'
+
+Dir['config/deploy/recipes/*.rb'].each { |plugin| load(plugin) }
+load 'config/deploy.rb'
@@ -0,0 +1,51 @@
+# Modified capistrano recipe, based on the standard 'deploy' recipe
+# provided by capistrano but without the Rails-specific dependencies
+
+set :stages, %w(staging production)
+set :default_stage, "staging"
+require "capistrano/ext/multistage"
+
+# Set some globals
+default_run_options[:pty] = true
+set :application, "<%= name %>"
+
+# Deployment
+set :deploy_to, "/svc/#{application}"
+#set :user, 'someone'
+
+# Get repo configuration
+set :repository, "git@github.com:yourname/#{application}.git"
+set :scm, "git"
+set :branch, "master"
+set :deploy_via, :remote_cache
+set :git_enable_submodules, 1
+
+# No sudo
+set :use_sudo, false
+
+# File list in the config_files setting will be copied from the
+# 'deploy_to' directory into config, overwriting files from the repo
+# with the same name
+set :config_files, %w{}
+
+# List any work directories here that you need persisted between
+# deployments. They are created in 'deploy_to'/shared and symlinked
+# into the root directory of the deployment.
+set :shared_children, %w{log tmp}
+
+# Record our dependencies
+depend :remote, :gem, "daemon-kit", ">=0.0.0"
+
+# Hook into capistrano's events
+before "deploy:update_code", "deploy:check"
+
+# Create some tasks related to deployment
+namespace :deploy do
+
+ desc "Get the current revision of the deployed code"
+ task :get_current_version do
+ run "cat #{current_path}/REVISION" do |ch, stream, out|
+ puts "Current revision: " + out.chomp
+ end
+ end
+end
@@ -0,0 +1,6 @@
+#set :deploy_to, "/svc/<%= name %>" # defaults to "/u/apps/#{application}"
+#set :user, "<% name %>" # defaults to the currently logged in user
+set :daemon_env, 'production'
+
+set :domain, 'example.com'
+server domain
@@ -0,0 +1,6 @@
+#set :deploy_to, "/svc/<%= name %>" # defaults to "/u/apps/#{application}"
+#set :user, "<% name %>" # defaults to the currently logged in user
+set :daemon_env, 'staging'
+
+set :domain, 'example.com'
+server domain
View
@@ -4,7 +4,7 @@
require 'rubygems'
module DaemonKit
- VERSION = '0.1.6'
+ VERSION = '0.1.7'
autoload :Initializer, 'daemon_kit/initializer'
autoload :Application, 'daemon_kit/application'
Oops, something went wrong. Retry.

0 comments on commit 189936c

Please sign in to comment.