Ruby 1.9.2, nginx, mysql, bundler.

by reenhanced
5 deployments · 1 still active · last rev. 5 years ago

ruby 1.9.2

Compatible with: No distros currently supported
# Installs Ruby 1.9, and Nginx with Passenger. 
# <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="rr_env" Label="Rails/Rack environment to run (list here:" default="production" />
# <UDF name="hostname" Label="Hostname" />

source <ssinclude StackScriptID=1>  # Common bash functions

function log {
  echo "$1 `date '+%D %T'`" >> /root/log.txt

# Set hostname
echo $HOSTNAME > /etc/hostname
hostname -F /etc/hostname
cat >> /etc/hosts << EOF    $HOSTNAME

# Set UTC as timezone
ln -sf /usr/share/zoneinfo/UTC /etc/localtime ## for Universal Coordinated Time

# Update packages and install essentials
  cd /tmp
  log "System updated"
  apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev openssh-server libyaml-dev libcurl4-openssl-dev libxslt-dev libxml2-dev
  log "Essentials installed"

# Set up MySQL
  mysql_install "$DB_PASSWORD" && mysql_tune 40
  log "MySQL installed"
  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"

# Set up Postfix

# Installing Ruby
  export RUBY_VERSION="ruby-1.9.2-p290"
  log "Installing Ruby $RUBY_VERSION"

  log "Downloading: (from calling wget$RUBY_VERSION.tar.gz)" 
  log `wget$RUBY_VERSION.tar.gz`

  log "tar output:"
  log `tar xzf $RUBY_VERSION.tar.gz`
  rm "$RUBY_VERSION.tar.gz"

  log "current directory: `pwd`"
  log ""
  log "Ruby Configuration output: (from calling ./configure)" 
  log `./configure` 

  log ""
  log "Ruby make output: (from calling make)"
  log `make`

  log ""
  log "Ruby make install output: (from calling make install)"
  log `make install` 
  cd ..
  rm -rf $RUBY_VERSION
  log "Ruby installed!"

# Install ruby gems
cd /tmp
log "Downloading Ruby Gems with wget"
log `wget`

log 'tar output:'
log `tar xzvf rubygems-1.8.10.tgz`
rm rubygems-1.8.10.tgz

cd rubygems-1.8.10
log "rubygems setup"
log `ruby setup.rb`

log "Updating ruby gems"
log `gem update --system`

# Set up Nginx and Passenger
  log "Installing Nginx and Passenger" 
  gem install passenger
  passenger-install-nginx-module --auto --auto-download
  log "Passenger and Nginx installed"

# Configure nginx to start automatically
  cd /opt
  wget -O
  mv /opt/ /etc/init.d/nginx
  chmod +x /etc/init.d/nginx
  /usr/sbin/update-rc.d -f nginx defaults
  log "Nginx configured to start automatically"

# Install git
  apt-get -y install git-core

# Set up environment
  # Global environment variables
  if [ ! -n "$RR_ENV" ]; then
  cat >> /etc/environment << EOF

# Update rubygems to (=> 1.3.6 as required by rails3)
gem update --system

# Install bundler
gem install bundler

# Add deploy user
echo "deploy:deploy:1000:1000::/home/deploy:/bin/bash" | newusers
cp -a /etc/skel/.[a-z]* /home/deploy/
chown -R deploy /home/deploy
# Add to sudoers(?)
echo "deploy    ALL=(ALL) ALL" >> /etc/sudoers

log "Configuration for nginx is at: /opt/nginx/conf/nginx.conf"
log "Now, run ssh-keygen -t as deploy"
log "Then, clone repo into ~deploy"
log "And edit /opt/nginx/conf/nginx.conf"
log ""
log "more useful:"
log "When done, do /etc/init.d/nginx reload"
log "And change to your app dir and run `bundle install --deployment`"

# Spit & polish
  log "StackScript Finished!"