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.

410 CHAPTER 14 Deployment<br />

This means your web server is now working seamlessly with your application and<br />

everything’s almost ready. If the operating system of the server restarts, however, this<br />

nginx process will not. To fix this small problem, you need to create an init script.<br />

14.6.2 An init script<br />

An init script is a script that is run on startup (init) of the operating system and is usually<br />

used for launching applications or running commands. In Ubuntu, they reside in<br />

the /etc/init.d directory. Here, you’re going to use one to start nginx. This script has<br />

already been prepared for you, and you can download it using this command:<br />

sudo wget http://bit.ly/nginx-init-script -O /etc/init.d/nginx<br />

This command will download the nginx init script and place it at /etc/init.d/nginx.<br />

This file won’t automatically run on boot unless you tell Ubuntu it should, which you<br />

can do with these following commands:<br />

sudo chmod +x /etc/init.d/nginx<br />

sudo /usr/sbin/update-rc.d -f nginx defaults<br />

If you were to reboot your operating system right now, nginx would start automatically<br />

along with it. You don’t need to do it now, but it’s good to know that it’ll start nginx<br />

when the server boots.<br />

There you have it: the application is deployed onto your Ubuntu server using Capistrano<br />

and is running through the power of nginx and Passenger.<br />

14.7 Summary<br />

In this chapter we covered one of the many different permutations you can use to<br />

deploy a Rails application to a server. This chapter covered the most commonly used<br />

software packages such as RVM, Capistrano, PostgreSQL, nginx, and Passenger, and<br />

therefore it should be a great starting ground for anybody learning about deployment.<br />

There are plenty of other tools out there such as Puppet, 31 Chef, 32 Babushka, 33<br />

and Git Pusshuten. 34 Different people prefer different ways of doing similar things,<br />

and so there’s a wide variety of choice. To cover everything within one chapter is just<br />

not possible.<br />

You set up your server with Ruby 1.9.2 running your Rails 3.0.5 application. You<br />

began by installing the essential packages you needed, then installing RVM, followed<br />

by Ruby.<br />

Afterwards, you set up a user with the same name as your application. This was<br />

shortly followed by the locking down of SSH access on the machine: now nobody is<br />

able to access it with a password, because they need to have the private key instead.<br />

Disabling root access is just generally good practice. Nobody should ever need to use<br />

31 http://puppetlabs.com.<br />

32 http://opscode.com/chef/.<br />

33 http://babushka.me.<br />

34 http://gitpusshuten.com/.

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

Saved successfully!

Ooh no, something went wrong!