We are using Passenger to serve Rails application requests, which integrates into Apache (it's also known as mod_rails). This means there is not much configuration to keep Rails running.
Rails internally handles a lot of the different environments. To set which environment Rails is running in, simply set the RailsEnv
configuration in the apache vhost config file, which for this app is located at /etc/httpd/sites-available/application_name
. We currently have 4 environments, of which only the last two will be relevant for you - development, test, staging and production.
If all goes well, this should handle almost everything for the application to function in its different environments. It can not, however, update the cron jobs. A bit of background:
The application needs to pull relevant tweets from twitter once every 5 minutes. We use cron jobs to trigger this. As the production environment has two servers, having both of the servers doubling the number of requests to twitter would be wasteful, and may get us blocked by Twitter. So only one of the servers needs to have this cron script running.
We usually deploy each version of the application using Capistrano scripts. The basic outline of this is:
- create a new copy of the entire app using a
git
, the version control system. - run migrations (see below)
- a few tidy up bits, e.g. ln some folders like the user generated images
- switch the current link from the old version to the new version
- restart Passenger (also see below)
This means the file structure is:
- ~/application_name/current (ln to current version)
- ~/application_name/releases (The current and previous versions of the application)
- ~/application_name/shared (files which persist between deployments)
We update the database schema on most releases, and we do this using migration scripts. These are run as part of our deployment script. You can manually run them by cd
ing to the current version of the application and running rake db:migrate RAILS_ENV=production
It is very simple to tell Passenger to restart the application. Simply touch
the file at tmp/restart.txt
in the current version.