Ruby On Rails Example #1: Deploying the Tracks Application

In this example, we are going to deploy the Tracks Rails application. Tracks is a web-based application to help you implement David Allen's Getting Things Doneª methodology.

Steps Involved

  1. Log in to your JumpBox

    All of the following shell commands will be executed directly on the JumpBox for Ruby on Rails. If you've already gone through the process of configuring and registering your JumpBox, then you're ready to begin. Use SSH to login to your JumpBox. The IP address is displayed on the JumpBox's console screen, the user name will be 'admin', and your password is what you set during the initial JumpBox setup.

    Once you're logged in, you can begin deploying your first Rails application by typing the following commands at the bash prompt. Note that you don't have to type the commented lines (they begin with a #).

    # Stop the Apache Webserver and Phusion Passenger
    sudo /etc/init.d/apache2 stop
  2. Download and Install Tracks

    Tracks is available at www.rousette.org.uk/projects/ and can be downloaded by clicking on the "Get Tracks" button on the right side of the page. Our example will download it using 'wget' to spare you the trouble.

    # Move the Skeletal Rails application out of the way
    mv /var/data/app/current /var/data/app/orig
    
    # Retrieve the latest version of Tracks
    wget http://www.rousette.org.uk/projects/files/tracks-current.zip -P /var/data/app/
    
    # Unzip Tracks
    unzip /var/data/app/tracks-current.zip -d /var/data/app
    
    # Remove the ZIP file
    rm /var/data/app/tracks-current.zip
    
    # Rename the Tracks directory to current
    mv /var/data/app/tracks* /var/data/app/current
    
    # Recursively change ownership of current so that it uses the www-data group
    sudo chown -R admin:www-data /var/data/app/current
  3. Install the Tracks Database

    By default, Tracks points to a non-existent MySQL database. We'd like it to use the database that the JumpBox for Ruby on Rails ships with, so we'll simply copy the database.yml configuration file from our original skeletal Rails app to the Tracks configuration directory, followed by performing the standard Rails migration task.

    # Copy the JumpBox's default database over Tracks'
    cp /var/data/app/orig/config/database.yml /var/data/app/current/config/database.yml
    
    # Change to the root of the Rails apps directory
    cd /var/data/app/current
    
    # Set your Rails environment to production
    export RAILS_ENV=production
    
    # Create the Rails database (uses RAILS_ENV)
    rake db:migrate
  4. Start the Apache Webserver

    The Apache Webserver running on the JumpBox needs to be started again so that you may access your newly deployed Rails application.

    # Make sure the tmp directory is created
    mkdir -p /var/data/app/current/tmp
    
    # Restart the Apache Webserver and Phusion Passenger
    sudo /etc/init.d/apache2 start

That's it! Tracks should now be running on your JumpBox. You can confirm this by pointing your browser to the standard http endpoint of the JumpBox.