27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Deploy away!<br />

Here you replace [your-server] with the address of the server, which is the same one<br />

that you’ve been SSH’ing to. If you’re using Vagrant, this address is simply localhost<br />

and you’ll need to add another line to specify the port:<br />

set :port, 2200<br />

Now that you’ve covered all the default options in config/deply.rb, you’ll add some<br />

others to provide more information to Capistrano so that it can set up your application<br />

correctly.<br />

The first two settings that you’ll need to set up are the user and the path to which<br />

you’ll deploy your application. Capistrano (unfortunately) can’t guess what these are,<br />

and so you have to be explicit. The user will be the ticketeeapp.com user and the path<br />

will be /home/ticketeeapp.com/apps. Use the application name as the name of a subfolder<br />

of that application so the application will be deployed into /home/ticketeeapp<br />

.com/apps/ticketee. Underneath the set :scm line, put these settings:<br />

set :user, "ticketeeapp.com"<br />

set :deploy_to, "/home/ticketeeapp.com/apps/#{application}"<br />

The ticketeeapp.com user doesn’t have sudo privileges, so tell Capistrano not to use<br />

the sudo command by using this line:<br />

set :use_sudo, false<br />

When you deploy your application, you don’t want to keep every single release that<br />

you’ve ever deployed on the server. To get rid of the old deploys (referred to as<br />

releases), put this in config/deploy.rb:<br />

set :keep_releases, 5<br />

This will keep the last five releases that you have deployed, deleting any releases that<br />

are older than that.<br />

Last, at the bottom of the file there are a couple of lines for defining<br />

deploy:start, deploy:stop, and deploy:restart tasks for Passenger, which are commented<br />

out. Remove the comment hash from the beginning of these lines, transforming<br />

them to this:<br />

namespace :deploy do<br />

task :start do ; end<br />

task :stop do ; end<br />

task :restart, :roles => :app, :except => { :no_release => true } do<br />

run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"<br />

end<br />

end<br />

This defines a blank start and stop task and a full restart task for your app role.<br />

This task will run the touch /home/ticketeapp.com/apps/ticketee/tmp/restart.txt<br />

command, which will tell your server (not yet set up) to restart the application, causing<br />

your newly deployed code to be started up upon the next request.<br />

399

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!