Rails 3 + Ruby 1.9.2

by tlabs
7 deployments · 6 still active · last rev. 4 years ago

Added nginx gz serving

Compatible with: No distros currently supported
# Installs Ruby 1.9, and Nginx with Passenger. 
# <UDF name="db_password" Label="MySQL root Password" />
# <UDF name="rr_env" Label="Rails/Rack environment to run" default="production" />

source <ssinclude StackScriptID=1>  # Common bash functions

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

# 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 libpcre3 libpcre3-dev
  log "Essentials installed"

# Set up MySQL
  mysql_install "$DB_PASSWORD" && mysql_tune 40
  log "MySQL installed"

# Set up Postfix

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

  log "Downloading: (from calling wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/$RUBY_VERSION.tar.gz)" 
  log `wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/$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!"

# Set up Nginx and Passenger
  log "Installing Nginx and Passenger" 
  gem install passenger
  passenger-install-nginx-module --auto --auto-download --prefix="/usr/local/nginx" --extra-configure-flags=--with-http_gzip_static_module
  log "Passenger and Nginx installed"

# Configure nginx to start automatically
  wget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh
  cat init-deb.sh | sed 's:/opt/:/usr/local/:' > /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

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

  # Install rails
  gem install rails --no-ri --no-rdoc

  # Install sqlite gem
  apt-get -y install sqlite3 libsqlite3-dev
  gem install sqlite3-ruby --no-ri --no-rdoc

  # Install mysql gem
  apt-get -y install libmysql-ruby libmysqlclient-dev
  gem install mysql2 --no-ri --no-rdoc

# 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

# Spit & polish
  log "StackScript Finished!"