I can't see the value of the elastic_load_balancer function, if all it does
it call server.

You haven't included your module into the main scope, you have included it
into Capistrano::Configuration, where it should, if anywhere be in
Capistrano::DSL.

To programatically define servers, just call `server()` from anywhere which
has Capistrano::DSL included.

(I think that's right, anyway, I have't ever actually tried, but the
top-level stuff like release_path and on() and friends all come from the
DSL module being included in to the main scope)

Lee Hambley
--
http://lee.hambley.name/
+49 (0) 170 298 5667


On 13 January 2014 18:31, Michael <[email protected]> wrote:

> Versions:
>
>    - Ruby
>       - 2.0.0
>    - Capistrano
>       - 3.0.1
>
> Does any documentation exist for writing capistrano 3 gems for
> programmatically adding servers during deployment?
>
> I can only find Capistrano 2 gems for doing such tasks.  (
> https://github.com/srbartlett/elbow ,
> https://github.com/tverbiscer/capistrano-asgroup )
>
> I'm currently testing this:   (The below is a useless example, but should
> try to add '127.0.0.1' to the list of servers...)
>
> root@domU-example:/var/lib/gems/2.0.0/gems/capistrano-autoscale-0.0.1/lib/capistrano#
> cat autoscale.rb
> require 'aws-sdk'
> require 'net/dns'
>
> ####  The below is old Cap2 syntax...  What is the new equivalent? ####
> #Capistrano::Configuration.instance(:must_exist).load do
> ### end old syntax (I think) ####
>
> module Capistrano
> class Configuration
> module ELB
> def elastic_load_balancer(name, *args)
>
> hostname = "127.0.0.1"
> server(hostname, *args)
> end
>
> end
>
> include ELB
> end
> end
>
> This just fails with this:
>
> root@domU-example:~/webapp# cap production deploy --trace
> ** Invoke production (first_time)
> ** Execute production
> ** Invoke load:defaults (first_time)
> ** Execute load:defaults
> cap aborted!
> undefined method `elastic_load_balancer' for main:Object
> config/deploy/production.rb:14:in `<top (required)>'
> /var/lib/gems/2.0.0/gems/capistrano-3.0.1/lib/capistrano/setup.rb:13:in
> `load'
> /var/lib/gems/2.0.0/gems/capistrano-3.0.1/lib/capistrano/setup.rb:13:in
> `block (2 levels) in <top (required)>'
> /var/lib/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:236:in `call'
> /var/lib/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:236:in `block in
> execute'
> /var/lib/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:231:in `each'
> /var/lib/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:231:in `execute'
> /var/lib/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:175:in `block in
> invoke_with_call_chain'
> /usr/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
> /var/lib/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:168:in
> `invoke_with_call_chain'
> /var/lib/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:161:in `invoke'
> /var/lib/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:149:in
> `invoke_task'
> /var/lib/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `block
> (2 levels) in top_level'
> /var/lib/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `each'
> /var/lib/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `block
> in top_level'
> /var/lib/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:115:in
> `run_with_threads'
> /var/lib/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:100:in
> `top_level'
> /var/lib/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:78:in `block
> in run'
> /var/lib/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:165:in
> `standard_exception_handling'
> /var/lib/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:75:in `run'
> /var/lib/gems/2.0.0/gems/capistrano-3.0.1/lib/capistrano/application.rb:12:in
> `run'
> /var/lib/gems/2.0.0/gems/capistrano-3.0.1/bin/cap:3:in `<top (required)>'
> /usr/local/bin/cap:23:in `load'
> /usr/local/bin/cap:23:in `<main>'
> Tasks: TOP => production
>
> Files:
>
>    - Capfile
>
> root@domU-example:~/webapp# cat Capfile  | grep -v "^#"
> require 'capistrano/setup'
>
> require 'capistrano/deploy'
>
> require 'capistrano/bundler'
> require 'capistrano/rails/assets'
> require 'capistrano/rails/migrations'
>
> Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
>
>    - deploy.rb
>
> root@dom-example:~/webapp# cat config/deploy.rb  | grep -v "^#" | grep -v
> "^$"
> set :application, 'blog'
> set :ssh_options, {:forward_agent => false, keys:
> ['/home/deploy/.ssh/private_key'], :paranoid => false}
> set :deploy_via, :remote_cache
> set :use_sudo, true
> set :deploy_to, '/webapp'
> set :scm, :git
> set :scm_user, :git
> namespace :deploy do
>   desc 'Restart application'
>   task :restart do
>     on roles(:app), in: :sequence, wait: 5 do
>       # Your restart mechanism here, for example:
>       if test("[ ! -d " + release_path.join("tmp").to_s + " ]")
>         execute "mkdir ", release_path.join("tmp")
>       end
>       execute :touch, release_path.join('tmp/restart.txt')
>     end
>   end
>   after :restart, :clear_cache do
>     on roles(:web), in: :groups, limit: 3, wait: 10 do
>       # Here we can do anything such as:
>       # within release_path do
>       #   execute :rake, 'cache:clear'
>       # end
>     end
>   end
>   after :finishing, 'deploy:cleanup'
> end
>
>    - Stage files (production.rb, staging.rb)
>
> root@domU-example:~/webapp/config/deploy/# cat production.rb  | grep -v
> "^#"
> require 'capistrano/autoscale'
> set :rails_env, "production"
>
> set :stage, :production
> set :user, 'deploy'
>
> elastic_load_balancer "example-elb.example.com", :web
>
>
>
> Any pointers in the right direction would be greatly appreciated.  I've no
> issues reading as much documentation as you send me, but I haven't found
> this one yet....
>
> -- Michael
>
> --
> You received this message because you are subscribed to the Google Groups
> "Capistrano" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/capistrano/68f5e1b6-7b3b-4e97-a856-02e9614f341e%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/capistrano/CAN_%2BVLVvHZjmzujnoRFaA1TXwXCJ3zm5jdLE_6_Uy8_%3DmaBHUA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to