Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial commit.

  • Loading branch information...
commit 4cd1518177f5f712beee790766caee794718578e 0 parents
Jordan Thomas authored

Showing 2 changed files with 191 additions and 0 deletions. Show diff stats Hide diff stats

  1. +34 0 README
  2. +157 0 stackscript.sh
34 README
... ... @@ -0,0 +1,34 @@
  1 +This is a stackscript for use on Linode to setup a Ruby on Rails environment. I pieced it together from a few resources mentioned below.
  2 +
  3 +It is intended for use on Ubuntu 10.04 (Lucid Lynx)
  4 +
  5 +It installs:
  6 +
  7 +- MySQL
  8 +- Postfix
  9 +- Ruby 1.9.3 p125
  10 +- Nginx
  11 +- Passenger
  12 +- Rails
  13 +
  14 +It also sets up a couple handy things like:
  15 +
  16 +- Script to control Nginx ($> service nginx start|stop|restart)
  17 +- A deployment user for use with Capistrano
  18 +
  19 +A few notes:
  20 +
  21 +Once the script completes you'll find Nginx installed in /usr/local. You'll likely need to edit Nginx's conf to be appropriate for your setup.
  22 +
  23 +Future possibilities, maybe?:
  24 +
  25 +- rbenv
  26 +- apt-get install Nginx vs Passenger Nginx
  27 +
  28 +Resources:
  29 +
  30 +- http://library.linode.com/web-servers/nginx/installation/ubuntu-10.04-lucid
  31 +- http://www.linode.com/stackscripts/view/?StackScriptID=1291
  32 +- http://library.linode.com/assets/660-init-deb.sh
  33 +- http://articles.slicehost.com/2009/3/4/ubuntu-intrepid-adding-an-nginx-init-script
  34 +- http://railscasts.com/episodes/335-deploying-to-a-vps
157 stackscript.sh
... ... @@ -0,0 +1,157 @@
  1 +#!/bin/bash
  2 +#
  3 +# Installs Ruby 1.9.3-p125, and Nginx with Passenger.
  4 +#
  5 +# <UDF name="db_password" Label="MySQL root password" />
  6 +# <UDF name="deploy_password" Label="Deployment user password" />
  7 +
  8 +NGINX_INSTALL_PATH="/usr/local/nginx"
  9 +NGINX_DAEMON_PATH="/usr/local/nginx/sbin/nginx"
  10 +RUBY_VERSION="ruby-1.9.3-p125"
  11 +
  12 +# http://www.linode.com/stackscripts/view/?StackScriptID=1
  13 +source <ssinclude StackScriptID=1> # Common bash functions
  14 +
  15 +function log {
  16 + echo "$1 `date '+%D %T'`" >> /root/log.txt
  17 +}
  18 +
  19 +cd /tmp
  20 +
  21 +# Update packages and install essentials
  22 +log "Updating system... "
  23 +system_update
  24 +log "System updated!"
  25 +
  26 +log "Installing essentials... "
  27 +apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev openssh-server libyaml-dev libcurl4-openssl-dev libxslt-dev libxml2-dev
  28 +goodstuff
  29 +log "Essentials installed!"
  30 +
  31 +# Set up MySQL
  32 +log "Installing MySQL... "
  33 +mysql_install "$DB_PASSWORD" && mysql_tune 40
  34 +log "MySQL installed!"
  35 +
  36 +# Set up Postfix
  37 +log "Installing Postfix... "
  38 +postfix_install_loopback_only
  39 +log "Postfix installed!"
  40 +
  41 +# Installing Ruby
  42 +log "Installing $RUBY_VERSION... "
  43 +
  44 +log "Downloading ftp://ftp.ruby-lang.org/pub/ruby/1.9/$RUBY_VERSION.tar.gz):"
  45 +log `wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/$RUBY_VERSION.tar.gz`
  46 +
  47 +log `tar xzf $RUBY_VERSION.tar.gz`
  48 +rm "$RUBY_VERSION.tar.gz"
  49 +cd $RUBY_VERSION
  50 +
  51 +log "Ruby configuration output:"
  52 +log `./configure`
  53 +
  54 +log ""
  55 +log "Ruby make output:"
  56 +log `make`
  57 +
  58 +log ""
  59 +log "Ruby make install output:"
  60 +log `make install`
  61 +
  62 +cd ..
  63 +rm -rf $RUBY_VERSION
  64 +
  65 +log "Ruby installed!"
  66 +
  67 +# Set up Nginx and Passenger
  68 +log "Installing Nginx and Passenger... "
  69 +gem install passenger
  70 +passenger-install-nginx-module --auto --auto-download --prefix="$NGINX_INSTALL_PATH"
  71 +log "Passenger and Nginx installed!"
  72 +
  73 +# Configure nginx to start automatically
  74 +cat >> /etc/init.d/nginx << EOF
  75 +#! /bin/sh
  76 +
  77 +### BEGIN INIT INFO
  78 +# Provides: nginx
  79 +# Required-Start: $all
  80 +# Required-Stop: $all
  81 +# Default-Start: 2 3 4 5
  82 +# Default-Stop: 0 1 6
  83 +# Short-Description: starts the nginx web server
  84 +# Description: starts nginx using start-stop-daemon
  85 +### END INIT INFO
  86 +
  87 +PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
  88 +DAEMON="$NGINX_DAEMON_PATH"
  89 +N="/etc/init.d/nginx"
  90 +
  91 +test -x \$DAEMON || exit 0
  92 +
  93 +set -e
  94 +
  95 +case "\$1" in
  96 + start)
  97 + echo -n "Starting Nginx... "
  98 + start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/nginx.pid --exec \$DAEMON -- \$DAEMON_OPTS
  99 + echo "Done!"
  100 + ;;
  101 + stop)
  102 + echo -n "Stopping Nginx... "
  103 + start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/nginx.pid --exec \$DAEMON
  104 + echo "Done!"
  105 + ;;
  106 + restart|force-reload)
  107 + echo -n "Restarting Nginx... "
  108 + start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/nginx.pid --exec \$DAEMON
  109 + sleep 1
  110 + start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/nginx.pid --exec \$DAEMON -- \$DAEMON_OPTS
  111 + echo "Done!"
  112 + ;;
  113 + reload)
  114 + echo -n "Reloading Nginx configuration... "
  115 + start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/nginx.pid --exec \$DAEMON
  116 + echo "Done!"
  117 + ;;
  118 + *)
  119 + echo "Usage: \$N {start|stop|restart|reload|force-reload}" >&2
  120 + exit 1
  121 + ;;
  122 +esac
  123 +
  124 +exit 0
  125 +
  126 +EOF
  127 +
  128 +chmod +x /etc/init.d/nginx
  129 +/usr/sbin/update-rc.d -f nginx defaults
  130 +log "Nginx configured to start automatically."
  131 +
  132 +# Install git
  133 +apt-get -y install git-core
  134 +
  135 +# Update rubygems
  136 +gem update --system
  137 +
  138 +# Install rails
  139 +gem install rails --no-ri --no-rdoc
  140 +
  141 +# Install sqlite gem
  142 +apt-get -y install sqlite3 libsqlite3-dev
  143 +gem install sqlite3-ruby --no-ri --no-rdoc
  144 +
  145 +# Install mysql gem
  146 +apt-get -y install libmysql-ruby libmysqlclient-dev
  147 +gem install mysql2 --no-ri --no-rdoc
  148 +
  149 +# Add deploy user
  150 +echo "deploy:$DEPLOY_PASSWORD:1000:1000::/home/deploy:/bin/bash" | newusers
  151 +cp -a /etc/skel/.[a-z]* /home/deploy/
  152 +chown -R deploy /home/deploy
  153 +echo "deploy ALL=(ALL) ALL" >> /etc/sudoers
  154 +
  155 +# Spit & polish
  156 +restartServices
  157 +log "StackScript Finished!"

0 comments on commit 4cd1518

Please sign in to comment.
Something went wrong with that request. Please try again.