rails 3 + nginx + mongodb + deploy user

by atomicunit
52 deployments · 10 still active · last rev. 6 years ago

Installs rails 3 (pre), nginx, mongodb, git, and adds the deploy user -- tail /root/stackscript.log to watch it run.

Compatible with: No distros currently supported
# Installs Ruby Enterprise edition, and Nginx with Passenger. 
# It also adds REE to the system-wide $PATH
# <UDF name="ree_file" Label="Ruby Enterprise Edition File" default="http://rubyforge.org/frs/download.php/71096/ruby-enterprise-1.8.7-2010.02.tar.gz" example="http://rubyforge.org/frs/download.php/71096/ruby-enterprise-1.8.7-2010.02.tar.gz" />
# <UDF name="ree_version" Label="Ruby Enterprise Edition Version" default="1.8.7-2010.02" example="1.8.7-2010.02" />
# <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="ubuntu_mirror" label="ubuntu mirror url" default="http://us.archive.ubuntu.com/ubuntu">
# <udf name="tmpdir" label="tmp dir (to download & compile)" default="/var/tmp">

exec &> /root/stackscript.log

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


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

  echo "Sleeping for 10" && sleep 10

  # Download
  cd       "$TMPDIR"
  wget     "$REE_FILE" -O "$REE_FILENAME"
  tar xzf  "$REE_FILENAME"
  cd       "$REE_NAME"

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

  # Add REE to the 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 http://library.linode.com/web-servers/nginx/installation/reference/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

# Install mongodb-stable
  echo "deb http://downloads.mongodb.org/distros/ubuntu 9.10 10gen" >> /etc/apt/sources.list
  apt-get update
  # Secure but failing:
  #   echo "MONGO_DB_PUB_KEY" | apt-key add -
  #   apt-get -y install mongodb-stable
  # Insecure but working:
  apt-get -y --force-yes install mongodb-stable
  /etc/init.d/nginx start

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

# Set up environment
  # Global environment variables
  cat > /etc/environment << EOF

# Install Rails 3
  # Update rubygems to (=> 1.3.6 as required by rails3)
  gem update --system
  # Install pre-requirements
  gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n --no-ri --no-rdoc
  gem uninstall -x rails
  gem install rails --pre --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

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

  echo "StackScript Done!"