Skip to content

Instantly share code, notes, and snippets.

@rtekie
Created August 8, 2011 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtekie/1132976 to your computer and use it in GitHub Desktop.
Save rtekie/1132976 to your computer and use it in GitHub Desktop.
RightScale script to generate rails database.yml file upon server launch
#!/bin/bash -ex
# Create database.yml for a Ruby on Rails application
# Storing database.yml in a source code control system with its production database credentials creates a security risk.
# Using this script, you can take advantage of RightScale's secure credentials store
# and generate the file when an application server is launched.
#
# If this is a reboot skip this script.
if test "$RS_REBOOT" = "true" ; then
logger -t RightScale "Skip RB create database.yml."
exit 0
fi
# Create database.yml file
cat <<EOF >/home/webapps/$APPLICATION/shared/system/config/database.yml
$RAILS_ENV:
adapter: mysql2
host: $MASTER_DB_DNSNAME
port: 3306
encoding: utf8
reconnect: false
database: $DB_SCHEMA_NAME
pool: 5
username: $DBAPPLICATION_USER
password: $DBAPPLICATION_PASSWORD
EOF
ln -nfs /home/webapps/$APPLICATION/shared/system/config/database.yml /home/webapps/$APPLICATION/current/config/database.yml
logger -t RightScale "database.yml created."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment