[WIP] - REE+Rails3+Nginx+MySql+Admin user

by jcorcuera
8 deployments · 3 still active · last rev. 5 years ago

recrea script [http://www.linode.com/stackscripts/view/?StackScriptID=1288] but updated:

Updated Ree download url
Added some dependencies
Change deploy to Admin user
Need to implement: SSH access, root disable, ip-table configuration

Compatible with: No distros currently supported
						#!/bin/bash
# 
# Installs Ruby Enterprise edition, and Nginx with Passenger. 
# It also adds REE to the system-wide $PATH
#
# <UDF name="ree_version" Label="Ruby Enterprise Edition Version" default="1.8.7-2011.03" example="1.8.7-2011.03" />
# <UDF name="install_prefix" Label="Install Prefix for REE and Passenger" default="/opt/local" example="/opt/local will install REE to /opt/local/ree" />
# <UDF name="rr_env" Label="Rails/Rack environment to run" default="production" />
# <UDF name="db_password" label="Opendata DB user password" />
# <UDF name="admin_user" label="Admin user to disable root to access from ssh" default="admin" />
# <UDF name="tmpdir" label="Tmp Dir (to download & compile)" default="/var/tmp">

exec &> /root/stackscript.log

source <ssinclude StackScriptID=1>
source <ssinclude StackScriptID=904>

system_update

#finx same dependencies:
aptitude -y install libc6
aptitude -y install libc6-dev
aptitude -y install libncurses5-dev
aptitude -y install libcurl4-openssl-dev 

# Install some niceties
goodstuff

# 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-2011.03"
fi
if [ ! -n "$INSTALL_PREFIX" ]; then
	INSTALL_PREFIX="/opt/local"
fi
if [ ! -n "$RR_ENV" ]; then
	RR_ENV="production"
fi
if [ ! -n "$TMPDIR" ]; then
	TMPDIR="/var/tmp"
fi
if [ ! -n "$ADMIN_USER" ]; then
	ADMIN_USER="admin"
fi

REE_NAME="ruby-enterprise-$REE_VERSION"
REE_FILENAME="$REE_NAME.tar.gz"
REE_DOWNLOAD="http://rubyenterpriseedition.googlecode.com/files/$REE_FILENAME"
WORKING_DIR="$TMPDIR/flux-setup"

mkdir -p "$WORKING_DIR"

# Set up Ruby Enterprise Edition
	# Dependencies
	apt-get -y install build-essential zlib1g zlib1g-dev libssl-dev libreadline5-dev libxml2-dev curl libpcre3-dev bison

	echo "REE_FILENAME = $REE_FILENAME"
	echo "REE_DOWNLOAD = $REE_DOWNLOAD"
	echo "Sleeping for 10" && sleep 10

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

	# Install
	./installer --auto="$INSTALL_PREFIX/$REE_NAME"
	ln -s "$INSTALL_PREFIX/$REE_NAME" "$INSTALL_PREFIX/ree"

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

# Set up Nginx and Passenger
	passenger-install-nginx-module --auto --auto-download --prefix="$INSTALL_PREFIX/nginx"

# Configure nginx to start automatically
	ln -s "$INSTALL_PREFIX/nginx" "/opt/nginx"
	wget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh
	mv init-deb.sh /etc/init.d/nginx
	chmod +x /etc/init.d/nginx
	/usr/sbin/update-rc.d -f nginx defaults

# MySQL install
	mysql_install "$DB_PASSWORD" && mysql_tune 90

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

# Set up environment
	# Global environment variables
	cat > /etc/environment << EOF
PATH="$PATH"
RAILS_ENV="$RR_ENV"
RACK_ENV="$RR_ENV"
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 mysql gem
apt-get -y install libmysql-ruby libmysqlclient-dev
gem install mysql2 --no-ri --no-rdoc

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

# Clean up
rm -rf "$WORKING_DIR/*"

# Restart Services
restartServices

echo "StackScript Done!"