Shell script for deploying Rails applications

If you are working with a simple environment (an all-in-one production server) and do not follow Capistrano’s conventions (mainly in terms of where your repository resides), it may be easier to deploy your Rails application using a shell script.

This is the one I use at the moment.

Prerequisites

This script assumes the following environment:

  • You use a local SVN-repository to work on your application
  • You have your production server accessible via SSH (using a SSH key)
  • You rsync your files to the production host
  • You use apache/passenger/mysql for production

Installation

Download, unzip and make deploy.sh executable. It doesn't matter where you put it (I tend to place it in the lib-folder of my applications).

Then open the file in your favorite editor and change variables to suit your environment:

LOCAL_PATH: The directory which will be copied to your server (probably a working copy of your trunk).
DEPLOY_TO: The (absolute) path on your production-machine. This is the folder under which everything will happen.
USER: The user you will be using for SSH.
HOST: Your production machine.

Changing the other variables is not necessary.

Usage

Prepare

Use deploy.sh --prepare to prepare your production machine for deployment. This will create the following directory structure:

- yourappname
  - current
  - releases
  - shared
    - log
      - production.log
    - pids
    - system

Deploy

Use deploy.sh --deploy to deploy your application. This will

  • sync your application to your production server (committing to your repository is not required, but strongly recommended)
  • link logfiles and PIDs from your shared-directory
  • flush your application’s cache
  • migrate the database
  • switch to the new version
  • restart the application layer

It will result in the following structure on your production server:

- yourappname
  - current -> releases/20100522115300
  - releases
    - 20100520225813
    - 20100521082442
    - 20100522115300
      - log -> shared/log
      - tmp
        - pids -> shared/pids
  - shared
    - log
    - pids
    - system

Cleanup

deploy.sh --cleanup will remove all but your current release from your production server.

Disclaimer

This script is provided „as is“, with a few important things missing (rollback, error checking, a maintenance page and some others). Please do not request features — I may add them if needed but this script is more of a small hack to make deployment fast and streamlined for simple environments than a complete deployment suite.

Feel free to use it as a starting point and tweak it to your own needs.


Download

deploy.sh.zip (Version 1.0, 1.7 KB)

News

Testing my forthcoming app with the Rails 3 release candidate using the new mysql2-adapter. Seems blazingly fast.

On 30th of July 2010 via web

Rails 3.0.0.rc feels a lot more snappier than beta4 (at least in dev-environment).

On 27th of July 2010 via Twitter for iPhone

@thomasfuchs Maybe try blizznet if it's available — don't know if it's reliable, but it IS fast...

On 7th of July 2010 (in reply to thomasfuchs’s tweet) via Twitter for iPhone

Business logic is now rock-solid. Trying to boost performance now while hoping to release the thang in late summer.

On 7th of July 2010 via Twitter for iPhone

Hard when you realize that your whole application logic needs a complete refactoring before launch. Some design-decisions bite late.

On 1st of July 2010 via web


Please enable JavaScript if you want to comment!