Rails Deployments Tips
Very often when projects go into production there are a few tweaks needed to make sure the app works correctly in its production environment and stays working. Below are some tips I’ve come up with from my experience rolling rails apps. Most of them are no brainers and some probably apply only to the Rails development we’re doing at work.
Rotate Rails Log Files
Log files get big really quick on high traffic sites. Some server apps rely on the operating system or a log rotating script to archive or delete old logs. Rails has a built in feature thanks to Ruby’s Logger class. The following code will keep 50 archived logs each 1mb in size and automatically rotate the log out once it hits 1mb.
In conf/environments.rb
Rails::Initializer.run do |config|
# ...
config.logger = Logger.new(File.join(RAILS_ROOT, 'log', "#{RAILS_ENV}.log"), 50, 1.megabyte)
Ignore Sensitive Parameters in Logs
Sick of seeing your bank password showing up in your Rails based shiny new web 2.0 app? Yeah I know don’t use your bank password but hey if you’ve done it users of your shiny new web 2.0 app probably will too. Keep them safe by keeping their passwords out of your logs. The following hides the password and password_confirmation params from your logs.
In conf/environments.rb
# Include your application configuration below
ActionController::Base.filter_parameter_logging :password, :password_confirmation
Robots.txt
If you have a development site that isn’t password protected to the public for whatever reason you’ll want to make sure the development site isn’t getting indexed by search engines and cluttering up results for your production site.
Create a file called robots-development.txt and on your development site use mod_rewrite to point to the file.
User-agent: *
Disallow: /
Password Protect Mod Proxy
So this goes along with the last topic. If you’re using password protection along with mod proxy you’ll notice that your assets are password protected but page requests still make it to mongrel. Painful on your search results if msn, yahoo or googlebot come to visit.
<Proxy balancer://mongrel_cluster>
AuthName "Keep Out"
AuthType Basic
AuthUserFile htpasswd.users
Require valid-user
BalancerMember http://192.168.1.2:8000
#...
Turn on /etc/init.d scripts!
This seems like a no-brainer but if you installed apache from source and/or you are using mongrel cluster you’re doing this manually.
Copy the script from the mongrel_cluster resource directory to /etc/init.d
# cp /usr/local/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/resources/mongrel_cluster /etc/init.d/mongrel_cluster
# chmod +x /etc/init.d/mongrel_cluster
On Redhat
# chkconfig --level 345 httpd on
# chkconfig --level 345 mongrel_cluster on
On Debian
# update-rc.d httpd defaults
# update-rc.d mongrel_cluster defaults
More to come…
Trackbacks
Use the following link to trackback from your own site:
http://www.actsasflinn.com/trackbacks?article_id=rails-deployments-tips&day=16&month=01&year=2008


