Chronicling the trials and tribulations of developing for the modern web.



Introducing: Capistrano Bells

Posted by Pat Nakajima on June 08, 2007 in Ruby or Rails.

Update: See this post for an update on Capistrano Bells.

Capistrano 2 is great. I’ve been using it since its first preview to deploy all of my projects, including devthatweb. Now, before I started using Capistrano 2, I would use the deprec gem to setup my Rails apps, since it had tasks to configure a Mongrel cluster and restart Apache. Unfortunately, the deprec gem isn’t compatible with Capistrano 2, and Capistrano 2 doesn’t have these features.

Rather than going back to doing these tasks on the remote server like a sucker, I decided to write some Capistrano 2 recipes to help myself out. With multiple projects though, copying the recipes and keeping them updated across the board became a nuisance.

I decided it was time to write a plugin. That way, I could keep everything updated across all my projects, as well as give back to the amazing Ruby and Rails community that have given so much to me.

So I did. I call it Capistrano Bells. I’ve been working on it for a few weeks now and I think it’s ready to see the light of day. Bells makes Capistrano 2’s task set look like this:
cap deploy                      # Deploys your project.
cap deploy:apache:reload_apache # Reload Apache webserver
cap deploy:apache:restart       # Restarts Apache webserver
cap deploy:apache:setup         # Setup an apache virtual server on remote se...
cap deploy:apache:start         # Starts Apache webserver
cap deploy:apache:stop          # Stops Apache webserver
cap deploy:check                # Test deployment dependencies.
cap deploy:cleanup              # Clean up old releases.
cap deploy:cold                 # Deploys and starts a `cold' application.
cap deploy:copy_config_files    # Copy config files to live app
cap deploy:migrate              # Run the migrate rake task.
cap deploy:migrations           # Deploy and run pending migrations.
cap deploy:mint                 # Deploy Mint stats tracking.
cap deploy:mint:copy_db_config  # Copy Mint DB config
cap deploy:mint:setup           # Configure Mint virtual server on remote app.
cap deploy:mongrel:configure    # Configure Mongrel processes on the app server.
cap deploy:mongrel:delete       # Deletes mongrel configuration file.
cap deploy:mongrel:restart      # Restart the Mongrel processes on the app se...
cap deploy:mongrel:start        # Start Mongrel processes on the app server.
cap deploy:mongrel:stop         # Stop the Mongrel processes on the app server.
cap deploy:pending              # Displays the commits since your last deploy.
cap deploy:pending:diff         # Displays the `diff' since your last deploy.
cap deploy:php                  # Deploy a PHP project.
cap deploy:php:setup            # Configure virtual server on remote app.
cap deploy:put_config_files     # Puts config files on remote server.
cap deploy:rollback             # Rolls back to a previous version and restarts.
cap deploy:rollback_code        # Rolls back to the previously deployed version.
cap deploy:setup                # Prepares one or more servers for deployment.
cap deploy:symlink              # Updates the symlink to the deployed version.
cap deploy:tail                 # Shows tail of production log
cap deploy:update               # Copies your project and updates the symlink.
cap deploy:update_code          # Copies your project to the remote servers.
cap deploy:upload               # Copy files to the currently deployed version.
cap deploy:web:disable          # Present a maintenance page to visitors.
cap deploy:web:enable           # Makes the application web-accessible again.
cap invoke                      # Invoke a single command on the remote servers.
cap local:apache:restart        # Restart apache on local machine
cap local:apache:start          # Start apache on local machine
cap local:apache:stop           # Stop apache on local machine
cap shell                       # Begin an interactive Capistrano session.
cap tools:aptitude:install      # Installs a package using the aptitude comma...
cap tools:aptitude:search       # Search for aptitude packages on remote server
cap tools:aptitude:update       # Runs aptitude update on remote server
cap tools:aptitude:upgrade      # Runs aptitude upgrade on remote server
cap tools:gems:install          # Install a gem on the remote server
cap tools:gems:list             # List gems on remote server
cap tools:gems:remove           # Uninstall a gem from the remote server
cap tools:gems:update           # Update gems on remote server
cap tools:look_for_commands     # Look for necessary commands for Rails deplo...
cap tools:ssh:setup             # Copies contents of ssh public keys into aut...
cap tools:svn:add               # Add new files to subversion
cap tools:svn:clean             # remove and ignore log files and tmp from su...
cap tools:svn:commit            # Commits changes to subversion repository
cap tools:uptime                # Displays server uptime

Installation

To get Capistrano Bells, run the following command:
script/plugin install http://svn.nakadev.com/plugins/bells
Then to install it, run the following rake task:
rake bells:install

In the Capfile, enter whatever settings you need. You can also comment out recipes that you don’t need.

Warning:

Capistrano Bells is still in its beta stage.
I make no guarantees regarding its stability nor suggest that it is fit for anything.

With that being said, I will tell you that I deployed my latest project, called Infotation, using nothing but this plugin.

Usage

While I plan to write much more in depth about the many uses of Capistrano Bells in future posts, the basic uses of the plugin should be self-explanatory to anybody familiar with Capistrano 2. To view available tasks, run:

cap -T

I tried to adhere to the principle that the ideal depth for task commands was 3 namespaces, as you can see here:
cap deploy:apache:restart

In that example, “deploy” is the task family, “apache” is the task type, and “restart” is the task itself. This system has proven itself to be intuitive enough for me to not have to constantly be running the cap -T command.

Help wanted

Feel free to sift through the recipes and code. If you see something that ought to be done differently, please let me know in the comments of this post. Again, I must warn you that this plugin is still in its beta stage. If you’d like to help me test it, I’d appreciate it.

peoplewhocommented

June 10, 2007

I highly recommend making this a gem instead of a plugin.

Dr. Nic’s newgem makes it really easy to do. Using a gem means you get the benefits of dependency management, version requirements, and distribution.

topfunky
June 18, 2007

deploy:apache:setup uploads the raw apache template. The tasks looks fine, but ERB isn’t working.

rbjce
June 23, 2007

rbjce,

That’s because I accidentally used #{this} instead of <%= this %>. The template has been fixed and should be working now.

Pat Nakajima

commentsareclosed

Sorry, but comments are closed on this blog after 30 days.