REE + Nginx + Passenger Library for RH Derivatives

by eclubb
26 deployments · 3 still active · last rev. 6 years ago

Installs Ruby Enterprise Edition, and Nginx with Passenger. Optionally installs mysql and/or sqlite-ruby gems. It also adds REE to the system-wide $PATH. Modified port of mocra's "Postgres + REE + Nginx + Passenger" to Centos/Fedora.

Compatible with: CentOS 5.6
						#!/bin/bash

# Set up some necessary ENV variables
# Should be set from UDF if run through Linode
if [ ! -n "$REE_VERSION" ]; then
  REE_VERSION="1.8.7-2010.01"
fi
if [ ! -n "$INSTALL_PREFIX" ]; then
  INSTALL_PREFIX="/opt/local"
fi
if [ ! -n "$RR_ENV" ]; then
  RR_ENV="production"
fi
if [ ! -n "$INSTALL_MYSQL_GEM" ]; then
  INSTALL_MYSQL_GEM="no"
fi
if [ ! -n "$INSTALL_SQLITE_GEM" ]; then
  INSTALL_SQLITE_GEM="no"
fi

#########################
#  REE/Nginx/Passenger  #
#########################
function ree_nginx_passenger_install {
  REE_NAME="ruby-enterprise-$REE_VERSION"
  REE_FILENAME="$REE_NAME.tar.gz"
  REE_DOWNLOAD="http://rubyforge.org/frs/download.php/68719/$REE_FILENAME"
  WORKING_DIR="/tmp/ree"

  mkdir -p "$WORKING_DIR"

  # Install dependencies
  yum -y install gcc-c++ make patch
  yum -y install zlib-devel openssl-devel readline-devel

  # Download
  cd       "$WORKING_DIR"
  wget     "$REE_DOWNLOAD" -O "$REE_FILENAME"
  tar xzf  "$REE_FILENAME"
  cd       "$REE_NAME"

  # Install
  ./installer --auto="$INSTALL_PREFIX/$REE_NAME" --no-dev-docs --dont-install-useful-gems
  ln -s "$INSTALL_PREFIX/$REE_NAME" "$INSTALL_PREFIX/ree"

  # Add REE to the PATH
  export PATH="$INSTALL_PREFIX/ree/bin:$PATH"

  # Install useful gems
  gem install --no-ri --no-rdoc rake rack fastthread passenger

  # Install Nginx/Passenger
  passenger-install-nginx-module --auto --auto-download --prefix="$INSTALL_PREFIX/nginx" --extra-configure-flags="--with-http_ssl_module"

  # Install Nginx init script
  wget http://www.gtlib.gatech.edu/pub/fedora-epel/5/i386/nginx-0.6.39-4.el5.i386.rpm
  rpm2cpio nginx-0.6.39-4.el5.i386.rpm | cpio -idm
  cp etc/rc.d/init.d/nginx /etc/init.d/
  chmod +x /etc/init.d/nginx

  # Install MySQL gem, if selected
  if [[ $INSTALL_MYSQL_GEM == yes ]]; then
    yum -y install mysql-devel
    gem install --no-ri --no-rdoc mysql
  fi

  # Install Sqlite3 gem, if selected
  if [[ $INSTALL_SQLITE_GEM == yes ]]; then
    yum -y install sqlite-devel
    gem install --no-ri --no-rdoc sqlite3-ruby
  fi

  # Set up global environment variables
  cat > /etc/environment << EOF
PATH="$PATH"
RAILS_ENV="$RR_ENV"
RACK_ENV="$RR_ENV"
EOF

  # Clean up
  rm -rf "$WORKING_DIR"
}