Ruby 1.9.3,Mysql,Nginx,Unicorn - CTS-V1.4

by ctsimpson
40 deployments · 5 still active · last rev. 4 years ago

Ruby 1.9.3, Nginx, mysql, essentials and deploy user with bundler,rails,and unicorn gems

Compatible with: No distros currently supported
						#!/bin/bash

source <ssinclude StackScriptID="1">

# <UDF name="db_password" Label="MySQL root Password" />
# <UDF name="db_name" Label="Create Database" default="" example="Optionally create this database" />
# <UDF name="db_user" Label="Create MySQL User" default="" example="Optionally create this user" />
# <UDF name="db_user_password" Label="MySQL User's Password" default="" example="User's password" />

# <udf name="rails_version" label="Rails Version" oneOf="3.2.8" example="These versions have been tested" />

# <udf name="ruby_version" label="Choose Ruby Version" oneOf="ruby-1.9.3-p194" example="These are downloaded from ftp://ftp.ruby-lang.org" />
# <udf name="gems_to_install1" label="Gems to install" manyOf="mysql,unicorn,bundler,sqlite3-ruby,rspec,rcov,capistrano" default="mysql,unicorn,bundler" example="Each selected gem will be installed." />
# <udf name="gems_to_install2" label="More gems to install" default="" example="Comma separated inputs to gem install. Example: rails,nifty-generators,formtastic,... Add the -v if you need a specific version." />

logfile="/root/log.txt"
rubyscript="/root/ruby_script_to_run.rb" 
# This script is generated and run after gem is installed to
# install the list of gems given by the stack script."

export logfile
export gems_to_install1="$GEMS_TO_INSTALL1"
export gems_to_install2="$GEMS_TO_INSTALL2"
# exported to be available in ruby_script_to_run.rb

system_update
echo "System Updated" >> $logfile
postfix_install_loopback_only
echo "postfix_install_loopback_only" >> $logfile
mysql_install "$DB_PASSWORD" && mysql_tune 40
echo "Mysql installed" >> $logfile
mysql_create_database "$DB_PASSWORD" "$DB_NAME"
mysql_create_user "$DB_PASSWORD" "$DB_USER" "$DB_USER_PASSWORD"
mysql_grant_user "$DB_PASSWORD" "$DB_USER" "$DB_NAME"

if [[ $PHP_INSTALL == yes ]]
then
  php_install_with_apache && php_tune
  echo "Php installed" >> $logfile
fi

#installing nginx
echo -ne '\n' | apt-add-repository ppa:nginx/stable
apt-get -y update
apt-get -y install nginx
echo "Nginx installed" >> $logfile

#install nodejs
echo -ne '\n' | apt-add-repository ppa:chris-lea/node.js
apt-get -y update
apt-get -y install nodejs

#install imagemagick
apt-get -y install imagemagick

#installing ruby
apt-get -y install curl build-essential openssl ruby-dev libmysqlclient-dev libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison python-software-properties
echo "libs for ruby installed" >> $logfile
echo "$RUBY_VERSION.tar.gz" >> $logfile
echo "$RUBY_VERSION" >> $logfile

echo "" >> $logfile
if [[ $RUBY_VERSION == ruby\-1\.9* ]]
then
	echo "Downloading: (from calling wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/$RUBY_VERSION.tar.gz)" >> $logfile
echo "" >> $logfile
	wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/$RUBY_VERSION.tar.gz  >> $logfile
else
	echo "Downloadin: (from calling wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/$RUBY_VERSION.tar.gz)" >> $logfile
echo "" >> $logfile
	wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/$RUBY_VERSION.tar.gz  >> $logfile
fi

echo ""
echo "tar output:"
tar xzf $RUBY_VERSION.tar.gz >> $logfile
rm $RUBY_VERSION.tar.gz
cd $RUBY_VERSION

echo ""
echo "current directory:"
pwd >> $logfile

echo "" >> $logfile
echo "Ruby Configuration output: (from calling ./configure --disable-ucontext --enable-pthread)" >> $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 /
rm -rf $RUBY_VERSION

echo "" >> $logfile
echo "Downloading Ruby Gems with wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.24.tgz" >> $logfile
echo "" >> $logfile
wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.24.tgz >> $logfile

echo ""
echo "tar output:"
tar xzvf rubygems-1.8.24.tgz  >> $logfile
rm rubygems-1.8.24.tgz

echo ""
echo "rubygems setup:"
cd rubygems-1.8.24
ruby setup.rb >> $logfile
cd /
rm -rf rubygems-1.8.24

#install rails
gem install rails -v $RAILS_VERSION --no-ri --no-rdoc >> $logfile

echo ""
echo "gem update --system:"
gem update --system >> $logfile

# echo the ruby code to a file to be run
echo "
    ##### Ruby Code Starts Here #####

    gems_to_install1 = ENV['gems_to_install1']
    gems_to_install2 = ENV['gems_to_install2']
    
    puts gems_to_install1
    puts gems_to_install2
    
    gems_to_install1.split(',').each do |gem_name|
      \`gem install #{gem_name} --no-ri --no-rdoc >> $logfile\`
    end
    
    gems_to_install2.split(',').each do |gem_name|
      \`gem install #{gem_name} --no-ri --no-rdoc >> $logfile\`
    end

    ##### Ruby Code Ends Here #####" >> $rubyscript

ruby $rubyscript >> $logfile

restartServices
echo "StackScript Finished!" >> $logfile