When I set up my latest application on DreamHost, I had a real pain of a time. Most of the references I found for help were written in 2006 and referred to outdated commands. Since top Google results for “dreamhost capistrano ruby on rails” are mostly no longer adequate, I hope to help out anyone else who finds themselves in my shoes!
I first got good help from this resource at Rubynoob which references the Dreamhost Capistrano Wiki article.
With those two links and a bit of help from me, you should be all set. To make things quick, let me summarize the key points:
- Set up your app with Fast-CGI enabled
- Set up your own RubyGems following this resource
- Also check out this resource for general Ruby on Rails + DreamHost concerns
- “cap –apply-to .” is now “capify”
- Download my deploy.rb file or read from it below for good explanation of what most of the items do.
- Set up your processes as shown below
- Make sure every file in your /script folder has the first line: #!/usr/bin/env ruby
- Make sure every file looking like /public/dispatch* has the first line: #!/usr/bin/env ruby
My deploy.rb file:
# The host where people will access my site set :application, "test.gamelizard.com" set :user, "my dreamhost username set to access this project" set :admin_login, "my admin login name" set :repository, "http://#{user}@svn.gamelizard.com/rgamelizard/trunk" # If you aren't deploying to /u/apps/#{application} on the target # servers (which is the default), you can specify the actual location # via the :deploy_to variable: set :deploy_to, "/home/#{admin_login}/#{application}" # My DreamHost-assigned server set :domain, "#{admin_login}@ajax.dreamhost.com" role :app, domain role :web, domain role :db, domain, :primary => true desc "Link shared files" task :before_symlink do run "rm -drf #{release_path}/public/bin" run "ln -s #{shared_path}/bin #{release_path}/public/bin" end set :use_sudo, false set :checkout, "export" # I used the handy quick tool to set up an SVN repository on DreamHost and this is where it lives set :svn, "/usr/bin/svn" set :svn_user, 'my svn username' set :svn_password, 'my svn password' set :repository, Proc.new { "--username #{svn_user} " + "--password #{svn_password} " + "http://svn.gamelizard.com/rgamelizard/trunk/" } desc "Restarting after deployment" task :after_deploy, :roles => [:app, :db, :web] do run "touch #{deploy_to}/current/public/dispatch.fcgi" run "sed 's/# ENV\\[/ENV\\[/g' #{deploy_to}/current/config/environment.rb > #{deploy_to}/current/config/environment.temp" run "mv #{deploy_to}/current/config/environment.temp #{deploy_to}/current/config/environment.rb" end desc "Restarting after rollback" task :after_rollback, :roles => [:app, :db, :web] do run "touch #{deploy_to}/current/public/dispatch.fcgi" end
My script/process/reaper file:
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
My script/process/spawner file:
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
The permissions in the script/process folder should look like:
-rwxr-xr-x 1 Malohkan staff 108 Jan 7 19:06 reaper -rwxr-xr-x 1 Malohkan staff 109 Jan 7 19:06 spawner
If they look like “-rwxr-xr-x@” as can happen on a Mac you’ll want to kill the file and re-create it with the same content. I think this happens due to copying files and is representative of the notion that only the current logged-in user can access that file. As a result, when Capistrano deploys the file, it will not have permission to run it.
If you have other issues or concerns that are not addressed here, please leave a comment and I’ll do my best to help further!
If you don’t like the trouble caused by dealing with Ruby on Rails on DreamHost, check out this article for some ideas of good alternatives!