Skip to content

Instantly share code, notes, and snippets.

@shapeshed
Created April 11, 2011 09:55
Show Gist options
  • Save shapeshed/913303 to your computer and use it in GitHub Desktop.
Save shapeshed/913303 to your computer and use it in GitHub Desktop.
RVM, Nginx and Passenger sitting in a tree..
# !/bin/bash
# Script: rails_env.sh
# Task: Builds a Rails stack with RVM, Passenger and Nginx
# Author: George Ornbo <george@shapeshed.com>
#
# Copyright (C) 2011 by George Ornbo
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# Thanks to the following..
#
# * http://grosser.it/2010/05/22/one-liner-to-install-nginx-with-passenger-and-ssl/
# * https://gist.github.com/raw/578736/0932236d03b18aff32361ec4718653c12b167209/rails3-nginx-passenger.sh
#---------------------------#
# Variables
#---------------------------#
NGINX_VERSION=0.8.54
RUBY_VERSION=1.9.2
#---------------------------#
# Are we root?
#---------------------------#
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
#---------------------------#
# Install dependencies
#---------------------------#
aptitude -y install curl git-core build-essential zlib1g-dev libssl-dev libreadline5-dev libc6 libpcre3 libssl0.9.8 zlib1g libxml2-dev libsqlite3-dev libcurl4-openssl-dev
#---------------------------#
# Install RVM
#---------------------------#
bash < <(curl -L -k https://rvm.beginrescueend.com/install/rvm)
sed -i 's/^\[ -z "\$PS1" \] && return/if \[\[ -n "\$PS1" \]\] ; then /' ~/.bashrc
echo "fi" >> ~/.bashrc
echo "[[ -s '/usr/local/rvm/scripts/rvm' ]] && source '/usr/local/rvm/scripts/rvm'" >> ~/.bashrc
source /root/.bashrc
#---------------------------#
# Sanity check
#---------------------------#
rvmoutput="rvm is a function"
if [[ `type rvm | head -n1` != "$rvmoutput" ]]; then exit 0; else echo "win"; fi
#---------------------------#
# Install a ruby and make default
#---------------------------#
rvm install $RUBY_VERSION
rvm --default use $RUBY_VERSION
#---------------------------#
# Update Rubygems
# Install Passenger and Bundler
#---------------------------#
gem update --system
gem install passenger --no-ri --no-rdoc
gem install bundler --no-ri --no-rdoc
#---------------------------#
# Install Nginx and compile in passenger
#---------------------------#
wget -O /usr/local/src/nginx-$NGINX_VERSION.tar.gz http://sysoev.ru/nginx/nginx-$NGINX_VERSION.tar.gz
cd /usr/local/src/ && tar xzf nginx-$NGINX_VERSION.tar.gz
rvmsudo passenger-install-nginx-module --nginx-source-dir=/usr/local/src/nginx-$NGINX_VERSION --prefix='/usr/local/nginx' --extra-configure-flags="--with-http_ssl_module" --auto
sudo ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx
wget -O /etc/init.d/nginx http://articles.slicehost.com/assets/2007/10/17/nginx
chmod +x /etc/init.d/nginx
/usr/sbin/update-rc.d -f nginx defaults
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment