Got the Capistrano::CLI.parse().execute! command working in a process
forked from the rails app--which I needed to do anyway--but it's still
strange that it blows up when invoked twice from the same process.
The capfiles are reasonable staightforward--though I am using the
ec2onrails gem.
If anyone sees something obvious, let me know!
Here's the code to invoke the cap:
----------------
require 'capistrano/cli'
class DeployManager
def self.deploy_data
Capistrano::CLI.parse(['staging',
'deploy:db:update']).execute!
end
end
------------------
Capfile:
----------------
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
set :stages, %w(staging production)
require 'capistrano/ext/multistage'
---------------
config/deploy/staging.rb:
---------------
set :application, "myapp"
set :repository, "svn://myrepo/#{application}/trunk"
set :deploy_via, :copy
set :copy_stategy, :export
# NOTE: for some reason Capistrano requires you to have both the
public and
# the private key in the same folder, the public key should have the
# extension ".pub".
ssh_options[:keys] = ["#{ENV['HOME']}/.ssh/mykey.pem"]
role :web, "myserver"
role :app, "myserver"
role :db, "myserver", :primary => true
set :rails_env, "staging"
# EC2 on Rails config. Many of these can be omitted if not needed,
check
# the documentation.
set :ec2onrails_config, {
# S3 bucket and "subdir" used by the ec2onrails:db:restore task
:restore_from_bucket => "foo",
:restore_from_bucket_subdir => "bar",
# Set a root password for MySQL. Run "cap
ec2onrails:db:set_root_password"
# to enable this. This is optional, and after doing this the
# ec2onrails:db:drop task won't work, but be aware that MySQL
accepts
# connections on the public network interface (you should block the
MySQL
# port with the firewall anyway).
:mysql_root_password => "foobar",
# Any extra Ubuntu packages to install if desired
# :packages => ["logwatch", "imagemagick"],
# Any extra RubyGems to install if desired: can be "gemname" or if
a
# particular version is desired "gemname -v 1.0.1"
# :rubygems => ["rmagick", "rfacebook -v 0.9.7"],
# Set the server timezone. run "cap -e
ec2onrails:server:set_timezone" for
# details
:timezone => "US/Eastern",
# Files to deploy to the server (they'll be owned by root). It's
intended
# mainly for customized config files for new packages installed via
the
# ec2onrails:server:install_packages task. Subdirectories and files
inside
# here will be placed in the same structure relative to the root of
the
# server's filesystem.
#:server_config_files_root => "../server_config",
# If config files are deployed, some services might need to be
restarted
:services_to_restart => %w(apache2 postfix sysklogd),
# Set an email address to forward admin mail messages to
:admin_mail_forward_address => "
te...@example.com",
}
require 'ec2onrails/recipes'
namespace :deploy do
namespace :db do
# main update task -- run this to upload and then swap databases
task :update, :roles => :db do
# exec my task
end
end
end
--------------