by dontangg on April 4, 2012
Add unicorn to your Gemfile:
Add this file to your rails app. I pretty much copied this from Ariejan de Vroom and GitHub.
# Set environment to development unless something else is specified
env = ENV["RAILS_ENV"] || "development"
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete documentation.
worker_processes 2 # amount of unicorn workers to spin up
timeout 30 # restarts workers that hang for 30 seconds
if env == "production"
# Help ensure your application will always spawn in the symlinked
# "current" directory that Capistrano sets up.
# feel free to point this anywhere accessible on the filesystem
user 'app_user', 'app_user' # 'user', 'group'
shared_path = "/u/apps/my_app_name/shared"
before_fork do |server, worker|
# the following is highly recomended for Rails + "preload_app true"
# as there's no need for the master process to hold a connection
# When sent a USR2, Unicorn will suffix its pidfile with .oldbin and
# immediately start loading up a new version of itself (loaded with a new
# version of our app). When this new Unicorn is completely loaded
# it will begin spawning workers. The first worker spawned will check to
# see if an .oldbin pidfile exists. If so, this means we've just booted up
# a new Unicorn and need to tell the old one that it can now die. To do so
# we send it a QUIT.
# This enables 0 downtime deploys.
old_pid = "/tmp/unicorn.my_app_name.pid.oldbin"
if File.exists?(old_pid) && server.pid != old_pid
rescue Errno::ENOENT, Errno::ESRCH
# someone else did our job for us
after_fork do |server, worker|
# Unicorn master loads the app then forks off workers - because of the way
# Unix forking works, we need to make sure we aren't using any of the parent's
# sockets, e.g. db connection (since "preload_app true")
# if preload_app is true, then you may also want to check and
# restart any other shared sockets/descriptors such as Memcached,
# and Redis. TokyoCabinet file handles are safe to reuse
# between any number of forked children (assuming your kernel
# correctly implements pread()/pwrite() system calls)
A few comments/thoughts:
1. I still like RVM, and am used to it and see no reason to switch to rbenv. That said, I had trouble (and am still having trouble) with Ubuntu + OpenSSL + Ruby 1.9.2 + RVM. I’m not sure which aspect is to blame here, but all I know is I built this same server on Gentoo a year ago and didn’t have these OpenSSL issues.
2. I like thin over unicorn, as it allows for asynchronous IO. Although, to be fair, I’m not utilizing it much yet, so at this point I don’ think it matters too much what server I use for my Rails app.
I have been working hard on getting this dang Ubuntu box up and running. I think part of my frustration has actually stemmed from selecting the smallest (256mb) size server. It might be an interesting idea to choose a bigger instance at first, then after you’re done installing all the prerequisites, re-size it to a smaller instance and then save an image. I think that’s what I’ll do next time.
I also thing I’ll go back to Gentoo next time, or even (God help me), CentOS.
by Steve on May 7, 2012 at 1:34 am. Reply #
Thanks, I’m about to deploy to rackspace and plan to follow your instructions.
Does rackspace give you information regarding how much memory your instance is using?
by stephen murdoch on June 20, 2012 at 4:19 pm. Reply #
Yes, Rackspace tells you how much space you’re using. I haven’t look hard in the website to find it, but I know you can see it when you ssh into your server. As part of the welcome message, it gives you a bunch of stats like, number of running processes, hard disk usage, ram usage, etc.
I watched Ryan Bates’ Railscast after I posted this and found it very beneficial. I highly recommend it. You can find it here: http://railscasts.com/episodes/335-deploying-to-a-vps.
by dontangg on June 20, 2012 at 4:42 pm. Reply #
Thanks for the post, i absolutely will try this configuration later, while still on development.
Now i’m also on rackspace’s 256mb Debian 6, RVM + passenger + nginx + mysql.
by Adi Suryadi on July 26, 2012 at 5:59 pm. Reply #
I have a just a few questions. If I set my nginx, and unicorn files to the Rackspace provided IP instead of port 80 I can load the static pages from my rails app If I change it to port 80 and try to go to the rackspace provided IP is just see bad gateway message from nginx, would you be able to give me some guidance?
by nofx1717Jesse on September 19, 2012 at 10:56 am. Reply #
Sorry for the late reply. I just got back from a trip to Disneyland with my family. I don’t consider myself an expert in server setup/maintenance. At this point it would take me a while to remember everything. Part of the reason for this post was for me to be able to remind myself what I did. I don’t think that I can be much help with the time I have. I definitely recommend the Railscasts that I mentioned in the post on setting up a VPS. He does a great job of explaining the details. IMO, the one video itself is well worth the $9 it costs for a membership for a month.
by dontangg on September 28, 2012 at 10:33 pm. Reply #
Awesome post! What version of ubuntu are you running on RackSpace? Is it a 1st gen or next gen cloud server?
by James Stone on November 24, 2012 at 1:19 am. Reply #
I’m glad you liked it! It is a 1st gen cloud server. They hadn’t announced the next gen ones when I started. I’m running Ubuntu 11.10.
by dontangg on November 24, 2012 at 1:29 am. Reply #
Terrific post. Thank you! Got it up and running without issue.
by Bijan on February 19, 2013 at 6:12 pm. Reply #
Required. Not published.
If you have one.
Notify me of follow-up comments by email.
Notify me of new posts by email.
RSS - Posts
Proudly powered by WordPress and Modernist, a theme by Rodrigo Galindez. RSS Feed.