Skip to content

Installation

Ethan Turkeltaub edited this page Jun 19, 2013 · 17 revisions

This is for a production version of the clock. There are some differences with development.


This is a guide for re-installing the clock server (what is running at fhsclock.com). Here's what the clock needs to run:

  • Ruby (MRI 2.0.0-p0)
  • MongoDB (~ 2.4.1)
  • Redis (~ 1.3.15)
  • Memcached (~ 1.4.5)
  • Phusion Passenger + Nginx (~ 3.0.18)
  • Node.js (> 0.8.21)

First things first, SSH into the server.

$ ssh -i clock.pem ubuntu@fhsclock.com

Prerequisites

Now that we're in, we're going to update the system.

$ sudo apt-get update
$ sudo apt-get upgrade

Let's install some basic packages.

$ sudo apt-get install build-essential make bison openssl libreadline5 git-core curl libcurl4-gnutls-dev libssl-dev libxslt-dev libxml2-dev libreadline6-dev libyaml-dev zlib1g-dev libsasl2-dev

Ruby

Now we're going to install rbenv to get Ruby. rbenv is a handy tool that allows you to handle multiple Ruby versions simultaneously.

$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv

Add the rbenv command to your $PATH and initalize the rbenv init script.

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.profile
$ echo 'eval "$(rbenv init -)"' >> ~/.profile

Restart your prompt to get rbenv.

$ exec $SHELL -l

Run rbenv -v to ensure that it's been installed correctly.

$ rbenv -v
rbenv 0.4.0

Now, get the ruby-build plugin to actually start installing Ruby.

$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

Also get the rbenv-sudo plugin so you can run Ruby commands as root.

$ git clone git://github.com/dcarley/rbenv-sudo.git ~/.rbenv/plugins/rbenv-sudo

Now, run the installer to get Ruby version 2.0.0-p0.

$ rbenv install 2.0.0-p0

Make sure that version is used globally.

$ rbenv global 2.0.0-p0

MongoDB

You can just install MongoDB from the sources.

$ sudo apt-get install mongodb

Redis

You can get Redis from the sources as well.

$ sudo apt-get install redis-server

Memcached

Ditto with Memcached.

$ sudo apt-get install memcached

Node.js

The version of Node.js that's in the sources should be fine. It's probably very outdated, but as long as it's after version 0.8.21, you should be fine.

$ sudo apt-get install nodejs

Phusion Passenger

Phusion Passenger is installed as a RubyGem.

$ gem install passenger -v '0.4.2' --no-ri --no-rdoc
$ rbenv rehash

Now, run the Passenger install of Nginx.

$ rbenv sudo passenger-install-nginx-module

The installer will walk you through the process. The default values should be fine.

Clock

Get the latest version of the clock code.

$ sudo mkdir /var/www
$ sudo chmod 755 -R /var/www
$ cd /var/www
$ git clone https://github.com/fhsclock/clock.git
$ cd clock

Install Bundler for the RubyGems.

$ gem install bundler --no-ri --no-rdoc
$ rbenv rehash

Run Bundler to get the dependencies.

$ bundle install

Configure Nginx

Fire up your favorite text editor to edit /opt/nginx/conf/nginx.conf.

#user  nobody;
worker_processes  4;
 
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
#pid        logs/nginx.pid;
 
 
events {
    worker_connections  1024;
}
 
#proxy_buffers 8 16k;
#proxy_buffer_size 32k;
 
http {
    passenger_root /home/ubuntu/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/passenger-4.0.2;
    passenger_ruby /home/ubuntu/.rbenv/versions/2.0.0-p0/bin/ruby;    
 
    include       mime.types;
    default_type  application/octet-stream;
 
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
    #access_log  logs/access.log  main;
 
    sendfile        on;
    #tcp_nopush     on;
 
    #keepalive_timeout  0;
    keepalive_timeout  65;
 
    gzip on;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_proxied any;
    gzip_min_length  1100;
    gzip_buffers 16 8k;
    gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;      
    gzip_disable "MSIE [1-6].(?!.*SV1)";
    gzip_vary on;
 
    server {
        listen       80;
        server_name  fhsclock.com;
        root /var/www/clock/public;
 
        #error_log /var/www/clock/log/production.log;
 
        passenger_enabled on;

    #location ~ ^/(i)/ {
    # gzip_static on;
    # expires     max;
    # add_header  Cache-Control public;
    # add_header  Last-Modified "";
    # add_header  ETag "";
    # break;
    #}
    }
 
 
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
 
    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;
 
    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
 
    #    ssl_session_timeout  5m;
 
    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
}

Add the Nginx service script. Open up /etc/init.d/nginx in your favorite text editor, and put in this:

#! /bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/opt/nginx/sbin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/nginx/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
        . /etc/default/nginx
fi

set -e

case "$1" in
  start)
        echo -n "Starting $DESC: "
        start-stop-daemon --start --quiet --pidfile /opt/nginx/logs/$NAME.pid \
                --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --quiet --pidfile /opt/nginx/logs/$NAME.pid \
                --exec $DAEMON
        echo "$NAME."
        ;;
  restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --quiet --pidfile \
                /opt/nginx/logs/$NAME.pid --exec $DAEMON
        sleep 1
        start-stop-daemon --start --quiet --pidfile \
                /opt/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  reload)
          echo -n "Reloading $DESC configuration: "
          start-stop-daemon --stop --signal HUP --quiet --pidfile     /opt/nginx/logs/$NAME.pid \
              --exec $DAEMON
          echo "$NAME."
          ;;
      *)
            N=/etc/init.d/$NAME
            echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
            exit 1
            ;;
    esac

    exit 0

Change the permissions of that script to make it executable.

$ sudo chmod a+x /etc/init.d/nginx

Restart Nginx to save changes

sudo service nginx restart

All done!

If you run ifconfig, you should be able to get the IP and assign the domain to that IP.

Clone this wiki locally