Rails 3 & Ruby 1.9.2 stack

by crnixon
216 deployments · 42 still active · last rev. 8 years ago

Sets up Ruby 1.9.2, MySQL, Passenger and nginx, and Rails 3.

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"
  aptitude -y install build-essential zlib1g-dev libssl-dev libreadline5-dev openssh-server libyaml-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-p0"
  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"
  log "Passenger and Nginx installed"

# Configure nginx to start automatically
  wget http://library.linode.com/web-servers/nginx/installation/reference/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
  # Install pre-requirements
  gem install rails -v '~> 3.0.0'

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

# Spit & polish
  log "StackScript Finished!"