Rails application deployment using shell script

I have used following shell script to deploy one of my Ruby on Rails applications:

DATES=`date +%Y%m%d%H%I%S`
service apache2 stop &&
mysqldump -u[user] -p[pass] [yourdbname] > "your backup directory"[yourdbname]_${DATES}.sql
git pull &&
bundle install --path [your bundle path] &&
bundle exec rake db:migrate RAILS_ENV=production &&
mv [your application's production log file] [your application's production log backup path]/production_${DATES}.log &&
touch [your application's production log path]/production.log &&
chown [user]:[group] [your application's production log file] &&
service apache2 start

In the above code snippet,

  • Line 01: Used to get the current date time
  • Line 02: Stopped the Apache server
  • Line 03: Used to take database backup in the backup directory
  • Line 04: Getting update source from repository
  • Line 05: Bundle install to update gem list
  • Line 06: Run database migration to migrate latest script if any
  • Line 07: Rotating log in every deployment
  • Line 08: Creating new production log file
  • Line 09: Providing proper user access to write log
  • Line 10: And, then start the server again

That’s all. Your application should run without any issue if you configure third bracket’s([]) information perfectly.

But, now a days – Capistrano allows you to deploy a Rails applications easily. You can try that and can customize if you need to.

Leave a Comment