Recent News
Take control of your server configuration with Capistrano
A typical Rails deployment involves configuring a number of services via configuration files. Common examples include httpd.conf, nginx.conf, memcached.conf, monitrc, my.cnf, haproxy.conf, et al. These little files are the laces that hold your app together; the tiniest mistake or misconfiguration will usually take your whole operation down. On top of this, if you’ve got multiple servers, you’ve got to make sure that every server is configured correctly.
So why don’t we put these under version control, and then use Capistrano to deploy configuration changes to one or more servers? Here’s one way to do it.
First, config files go in config/server.
In this example, the target servers are running Debian (Etch), and config/server/ corresponds to the root directory of the server—so we’ve got /var, /etc, and so on.
With this under version control along with the rest of the app, you can now roll back to earlier “known-good” configurations lickety-split.
As an added benefit, this increases transparency for your team, since developers can see how the deployment works without having to actually visit the servers.
And here’s where it gets even better—you can now use Capistrano to deploy configs!
Dig on this:
rake deploy:config
desc "Deploy server configurations"
task :config,:roles=>:app do
# Export to a temp directory, to avoid uploading .svn directories.
temp_dir = "/tmp/capistrano-#{Time.now.strftime("%Y%m%d%H%M%S")}"
system "svn export config/server #{temp_dir}"
system "scp -r #{temp_dir}/* #{user}@#{host}:/"
system "rm -rf #{temp_dir}"
sudo "chmod 700 /etc/monitrc"
sudo "chmod 600 /etc/mysql/my.cnf"
sudo "chmod -R a+wx /var/service/*"
sudo "chmod +x /home/deploy/backup_db"
deploy::reload_monit
deploy::restart_mysql
deploy::restart_mongrels
deploy::restart_apache
end
- This happens to be a subversion environment; if you’re on git you can probably just omit the exporting step.
- Make sure you completely understand how “scp” works—if this is new to you, bone up, because a mistake here can really ruin your day.
Please note that this code snippet will almost certainly not work for you as-is; you will have to adjust, rewrite, and optimize this for your unique situation.
One last tip: If you run into problems at first, make sure that permissions are reset correctly; these are idiosyncratic and tend to get wrecked in transition. It’s a simple/best practice to explicitly reset the permissions in your deployment.
You’ll thank yourself later—enjoy!
written by shinji kuwayama on July 23rd, 2008 @ 04:13 PM
Comments are closed
cementhorses.com
Recent
- Engineering happiness (August 15th)
- The future with gestures (August 14th)
- Debugging Kentico sites in vs.net 2008/05 improve compilation time (August 14th)
- Resistance ...is a good thing? (August 13th)
- Managing dashboard widgets on various external displays (August 1st)
- Counting in CSS (July 28th)
- Take control of your server configuration with Capistrano (July 23rd)
- Time Parseable (July 23rd)
- An SSH one-liner to authorize via public-key (June 23rd)
- MicroApps (or little ditties) with Sinatra (June 17th)
- RoR: Schedulable (May 29th)
- Less work, more be-ing with quick shell aliasing (May 8th)
- Interceptor Methods (May 7th)
Comments
- Lance Ribeiro on Engineering happiness
- Landon Moore on Engineering happiness
- Samuel Pires on Engineering happiness
- Brock on Engineering happiness
- Colton Sanches on Engineering happiness
- Caleb Mathews on Engineering happiness
- Collins on Engineering happiness
- Struye on Engineering happiness
- Jordan on Engineering happiness
- Aidan McDonough on Engineering happiness
- Tremonti on Engineering happiness
- Mathews on Engineering happiness
- Aiden Jones on Engineering happiness
- Rachman on Engineering happiness
- Perle on Engineering happiness
Categories
- Stuff You Already Know (6)
- Open Source (2)
Cement Horses Pics
Archives
- August 2008 (5)
- July 2008 (3)
- June 2008 (2)
- May 2008 (3)
