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.
Please enable JavaScript if you want to comment!