Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Deployment Recipe for Joyent Shared Accelerator (See related posts)

This is the deploy.rb I am using with a Shared Accelerator (with a few changes). It assumes you are using Mongrel and a proxy to serve the application. Joyent has good examples for those in the KB.

Not everything is *required* for a Shared Accelerator, but better to have some placeholders if you move your application later. The standard Capistrano :setup task worked for me, surprisingly. Haven't tried it since 2.0 or so.

The tasks for deploy:web:disable and deploy:web:enable are hacks. Ideas would be appreciated. Using the "pkill mongrel" trick hasn't always worked for me (sometimes SMF doesn't restart it), so I do it manually.

This isn't perfect, but hopefully it helps.

### deploy.rb
  set :application, "my_application"
  set :domain, "humboldt.joyent.us"

  set :user, "my_user"
  set :runner, user
  set :admin_runner, user # Does nothing on a Shared Accelerator
  set :scm_username, user
  set(:scm_password){Capistrano::CLI.password_prompt("Subversion Password: ")}
  
  set :scm, :subversion
  set :repository, "svn+ssh://#{scm_username}@#{domain}/users/home/#{user}/svn/#{application}/trunk/"
  set :checkout, "export"

  role :app, domain
  # These aren't required if you are just using one Shared Accelerator, but it's good practice
  role :web, domain
  role :db, domain, :primary => true
  
  set :deploy_to, "/users/home/#{user}/web/#{application}" # Or wherever you want the application root to be

  set :service_name, "smf-service_name" # Irrelevant because SMF doesn't work from the CLI on shared - left in as a reminder of a dream
  set :mongrel_config, "#{deploy_to}/shared/config/mongrel_cluster.yml" # Similarly irrelevant on Shared
  set :use_sudo, false # Don't need sudo on a shared accelerator
  default_run_options[:pty] = true # Much time was lost figuring this one out - see http://weblog.jamisbuck.org/2007/10/14/capistrano-2-1

# Shared Accelerators don't allow CLI access to SMF on Solaris
# Capistrano will throw warnings/errors if you don't overwrite these methods.
# It's a good opportunity to throw in a reminder about it.
namespace :deploy do
  desc "Restart the service"
  task :restart, :roles => :app  do
    puts "Remember to restart this from Webmin for changes to take effect."
    # Some svcadm stuff would go here if it worked
  end
  
  desc "Start the service" # The :spinner task went out of style when Mongrel and the gang came to town
  task :start, :roles => :app  do
    puts "Remember to start this from Webmin for changes to take effect."
  end
  
  desc "Stop the service"
  task :stop, :roles => :app do
    puts "This service must be stopped from Webmin."
  end
  
  # These tasks are used to enable/disable the application by replacing a .htaccess file
  # Surely someone has a better idea.
  namespace :web do
    desc "Present a maintenance page to visitors."
    task :disable, :roles => :web do
      run "cp /users/home/#{user}/web/public/down.txt /users/home/#{user}/web/public/.htaccess"
    end
    
    desc "Makes the application web-accessible again."
    task :enable, :roles => :web do
      run "cp /users/home/#{user}/web/public/up.txt /users/home/#{user}/web/public/.htaccess"
    end
  end
end

You need to create an account or log in to post comments to this site.