Configure your Free Facebook Joyent Accelerator for Capistrano

December 7th, 2007 by Justin Ball

Right now Joyent is giving away free Accelerator accounts to Facebook developers. I love free stuff so this is so cool I could just cry. Free hosting with one of the premier Ruby on Rails hosts. I normally have to eat bags of M&Ms to be this happy.

Not all is roses. There is a dark side to this free hosting. Setting it up will make you want to cry. I am a developer, not a Solaris system administrator and so getting my application deployed was like having a vasectomy and being totally conscious the entire time. In hopes of saving time in the future for myself and others here is how to configure your Facebook Rails application for deployment via Capistrano on a Joyent Accelerator. The ideas aren't mine. I stole everything from all over the place. I added links at the bottom where I found some of the information. The rest of it I will just feel guilty about.

  1. Setup your shell for capistrano. Follow the link for the how and why.
    Note my $HOME/.ssh/environment file contains this:

    PATH=/usr/bin:/usr/sbin:/opt/local/bin:/usr/ucb:
    /usr/sfw/bin:/usr/ccs/bin:/opt/csw/bin:/opt/csw/sbin:
    /opt/csw/gnu:/opt/csw/gcc3/bin:/opt/csw/mysql5/bin:
    /opt/csw/postgresql/bin:/opt/csw/apache2/bin:
    /opt/csw/apache2/sbin

    Also be careful so that you don't edit ssh_config instead of sshd_config not that anyone would ever be so stupid and do that. :-)
  2. Make sure you have the Capistrano gem installed on your local machine:
    sudo gem install capistrano
  3. capify your application:
    In the root of your rails application run this:
    capify .
  4. You will now have a deploy.rb in your config directory. Replace it with this deploy.rb.
    Then be sure to replace the XXXXXXXX with the username provided to you in your welcome email from Joyent. Then look for the sections of deploy.rb that contain capital letters and enter in the relevant values. These will include your application name, your domain name, and the path to your repository.
  5. Now create a directory inside your config directory and name accelerator. Then add the following three files into it:
    accelerator_tasks.rb - contains Capistrano recipes specific to the Joyent Accelerator.
    apache_vhost.erb - configures apache to point to your rails application
    smf_template.erb - starts up mongrel automatically for you when you system starts
  6. Now we need a mongrel_cluster.yml file. Create a file called mongrel_cluster.yml inside of your config directory and put this in it:
    port: "8000"
    environment: production
    address: 127.0.0.1
    pid_file: /home/XXXXXXX/web/APP-NAME/shared/pids/mongrel.pid
    log_file: /home/XXXXXXX/web/APP-NAME/shared/log/mongrel.log
    servers: 3
    docroot: /home/XXXXXXX/web/APP-NAME/current/public
    cwd: /home/XXXXXXX/web/APP-NAME/current

    You will need to edit the paths to match the paths you setup in deploy.rb. This likely means that you will need to replace XXXXXXX with your joyent username and APP-NAME with the name of your application.

  7. Subversion needs to know how to talk to your repository if it is password protected. ssh into the server and do this inside your home directory:
    svn co PATH TO YOUR PROJECT
    You can delete the directory when it is done. You do this so that your svn username and password are cached on the server which means that Capistrano will be able to checkout files.
  8. While you are logged into the server be sure to create an empty database. The name should match the name in your database.yml file.
  9. Be sure to enter the proper username for root into your database.yml file.
  10. Now for the exciting part:
    Run cap deploy:setup inside of the root of your Rails project. It should run successfully. If not I am very sorry.
  11. Then do this:
    cap deploy:cold

You should be up and running at that point.

More helps and information:
Joyent's quickstart. Although I would bypass that and look at the main how to found here. How to use Capistrano on a new Joyent Accelerator.

Tags:   · · · · 3 Comments

Leave A Comment

3 responses so far ↓

  • 1 Ted Jan 13, 2008 at 2:16 pm

    Thanks for the great writeup!

    Would you mind commenting on how you did your DNS records? I parked my name at GoDaddy and then tried to set the A record and WWW CNAME at my Accelerator’s public IP and Accelerator’s domain name (respectively), but nothing seems to resolve.

    Did you find a way to have Joyent handle your DNS or are you handling it elsewhere?

    Thanks!
    ted

  • 2 Ted Jan 13, 2008 at 2:23 pm

    Re: the previous comment.

    It looks like the records just had to trickle through the net for a while — it appears to be working now.

    Strange how ping would pick up on the right IP while the browser wouldn’t..

  • 3 Sean Jan 21, 2008 at 3:45 pm

    Big thanks for this! Very valuable information that probably would’ve taken me all day to find and assemble on my own :)