A copy of the official 2013 Rails Rumble StackScript, but with Postgresql instead of MySQL
#!/bin/bash # <UDF name="user_name" label="Username for Postgres Users (No Special Characters)" /> # <UDF name="user_password" label="Password for System www-data User and Postgres root User (No Special Characters)" /> # <UDF name="installapache" label="Install Apache and Passenger?" oneof="Yes,No" default="Yes" /> # <UDF name="installpostgres" Label="Install Postgres?" oneof="Yes,No" default="Yes" /> source <ssinclude StackScriptID="1"> logfile="/root/stackscript.log" RUBY_VERSION='ruby-2.0.0-p247' RUBY_GEMS_VERSION='2.0.7' export logfile echo "2013 Rails Rumble StackScript" >> $logfile echo "" >> $logfile echo "Adding unprivileged www-data user..." >> $logfile echo "www-data:$USER_PASSWORD:1000:1000::/home/www-data:/bin/bash" | newusers echo "System Updating (this may take a while)..." >> $logfile sleep 5 system_update >> $logfile echo "System Updated" >> $logfile echo "" >> $logfile if [ "$INSTALLPOSTGRES" == "Yes" ] ; then echo "Installing Postgresql Database Server..." >> $logfile echo "" >> $logfile add-apt-repository ppa:pitti/postgresql -y >> $logfile aptitude update >> $logfile aptitude -y install postgresql libpq-dev postgresql-client >> $logfile # Create postgres user echo "CREATE ROLE $USER_NAME WITH LOGIN ENCRYPTED PASSWORD '$USER_PASSWORD';" | sudo -u postgres psql >> $logfile # Create postgres database sudo -u postgres createdb --owner "$USER_NAME" "railsrumble_production" >> $logfile echo "" >> $logfile fi postfix_install_loopback_only >> $logfile echo "Configured: postfix_install_loopback_only" >> $logfile echo "" >> $logfile goodstuff >> $logfile echo "Installed: goodstuff" >> $logfile echo "" >> $logfile apt-get -y install build-essential >> $logfile apt-get -y install libssl-dev >> $logfile apt-get -y install libreadline5-dev >> $logfile apt-get -y install zlib1g-dev >> $logfile apt-get -y install libyaml-dev >> $logfile apt-get -y install libxslt-dev >> $logfile apt-get -y install git >> $logfile apt-get -y install git-core >> $logfile apt-get -y install memcached >> $logfile apt-get -y install libcurl4-openssl-dev >> $logfile apt-get -y install libapr1-dev >> $logfile apt-get -y install libaprutil1-dev >> $logfile apt-get -y install libreadline-dev >> $logfile apt-get -y install libncurses5-dev >> $logfile apt-get -y install nodejs >> $logfile apt-get -y install fail2ban >> $logfile apt-get -y install htop >> $logfile echo "Installed: various libraries, etc." >> $logfile echo "" >> $logfile # Install Ruby echo "Installing Ruby..." >> $logfile echo "$RUBY_VERSION.tar.gz" >> $logfile echo "$RUBY_VERSION" >> $logfile echo "" >> $logfile echo "Retrieving: $RUBY_VERSION.tar.gz" >> $logfile echo "" >> $logfile cd /root wget ftp://ftp.ruby-lang.org/pub/ruby/$RUBY_VERSION.tar.gz >> $logfile echo "" >> $logfile echo "tar output:" >> $logfile tar zxvf $RUBY_VERSION.tar.gz >> $logfile rm $RUBY_VERSION.tar.gz >> $logfile cd $RUBY_VERSION >> $logfile echo "" >> $logfile echo "Current Directory:" >> $logfile pwd >> $logfile echo "" >> $logfile echo "Ruby configure output: from calling ./configure" >> $logfile echo "" >> $logfile ./configure >> $logfile echo "" >> $logfile echo "Ruby make output: from calling make" >> $logfile echo "" >> $logfile make >> $logfile echo "" >> $logfile echo "Ruby make install output: from calling make install" >> $logfile echo "" >> $logfile make install >> $logfile cd >> $logfile rm -fr $RUBY_VERSION >> $logfile echo "" >> $logfile echo "Downloading Ruby Gems with wget http://production.cf.rubygems.org/rubygems/rubygems-$RUBY_GEMS_VERSION.tgz" >> $logfile echo "" >> $logfile wget http://production.cf.rubygems.org/rubygems/rubygems-$RUBY_GEMS_VERSION.tgz >> $logfile echo "" >> $logfile echo "tar output:" >> $logfile tar xzvf rubygems-$RUBY_GEMS_VERSION.tgz >> $logfile rm rubygems-$RUBY_GEMS_VERSION.tgz >> $logfile echo "" >> $logfile echo "Installing: RubyGems" >> $logfile cd rubygems-$RUBY_GEMS_VERSION >> $logfile ruby setup.rb >> $logfile cd rm -rf rubygems-$RUBY_GEMS_VERSION echo "" >> $logfile echo "gem update --system" >> $logfile gem update --system >> $logfile echo "" >> $logfile echo "Installing Bundler" >> $logfile gem install bundler --no-ri --no-rdoc >> $logfile export LC_CTYPE=en_US.UTF-8 export LANG=en_US.UTF-8 unset LC_ALL echo "" >> $logfile echo "Configuring /var/www/apps/railsrumble" >> $logfile mkdir -p /var/www/apps/railsrumble/releases mkdir -p /var/www/apps/railsrumble/shared/config mkdir -p /var/www/apps/railsrumble/shared/log if [ "$INSTALLPOSTGRES" == "Yes" ] ; then echo "Setting up Postgres for deploy" >> $logfile echo -e 'production:\n adapter: postgresql\n encoding: unicode\n database: \n pool: 5\n username:\n password: \n' >> /var/www/apps/railsrumble/shared/config/database.yml sed -i "s/ database:/ database: railsrumble_production/" /var/www/apps/railsrumble/shared/config/database.yml sed -i "s/ username:/ username: $USER_NAME/" /var/www/apps/railsrumble/shared/config/database.yml sed -i "s/ password:/ password: \"$USER_PASSWORD\"/" /var/www/apps/railsrumble/shared/config/database.yml sed -i "s/^local\s\s*all\s\s*all\s\s*peer/local all all md5/" /etc/postgresql/9.1/main/pg_hba.conf service postgresql restart fi echo "Fixing permissions on /var/www/apps" >> $logfile chown www-data:www-data -R /var/www/apps if [ "$INSTALLAPACHE" == "Yes" ] ; then echo "Installing Apache & Passenger (this may take a while)..." >> $logfile apache_install && apache_tune 40 && apache_virtualhost_from_rdns && a2enmod rewrite apt-get -y install apache2-prefork-dev gem install passenger --no-ri --no-rdoc --version '= 4.0.19' >> $logfile passenger-install-apache2-module --auto wget -O /etc/apache2/apache2.conf http://railsrumble.com.s3.amazonaws.com/2013/linode/apache2.conf wget -O /etc/apache2/passenger.conf http://railsrumble.com.s3.amazonaws.com/2013/linode/passenger.conf service apache2 restart elif [ "$WEBINSTANCE" == "No" ] ; then echo "Skipping installation of Apache & Passenger..." >> $logfile fi echo "" >> $logfile ssh -T -oStrictHostKeyChecking=no git@github.com echo "Configured: github.com as known host" >> $logfile mkdir -p ~/.ssh ssh-keygen -N '' -f ~/.ssh/github-deploy-key -t rsa -q echo "Generated: SSH key for deployment (you need to add ~/.ssh/github-deploy-key.pub to your GitHub repository's deploy keys)" >> $logfile touch ~/.ssh/config echo "Host github.com IdentityFile ~/.ssh/github-deploy-key" >> ~/.ssh/config echo "Configured: ~/.ssh/config this ensures the above deploy key is used for github.com" >> $logfile touch ~/.ssh/authorized_keys curl http://railsrumble.com.s3.amazonaws.com/rumblebot.pub >> ~/.ssh/authorized_keys chmod 0700 ~/.ssh/ chmod 0644 ~/.ssh/authorized_keys echo "Configured: ~/.ssh/authorized_keys do not remove the key for organizers@railsrumble.com, this is necessary for verification" >> $logfile restartServices echo "********************" >> $logfile echo "StackScript Finished" >> $logfile