-
Notifications
You must be signed in to change notification settings - Fork 0
Server Configuration
#Server configuration
This document will outline the steps neccessary to set up roomtrol server on a linux machine. These instructions were written for CentOS 5.5, but they should work with some modification for other linux distributions (or OS X).
###Installing packages
We need some things to start out with:
sudo yum install -y git gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel couchdb avahi-devel avahi-compat-libdns_sd-devel
###Installing RVM
I highly recommend using RVM (the ruby version manager) instead of trying to use a distro-packaged ruby. Package manager ruby might work, but it's probably not worth the hassle. Installing RVM is simple:
$ sudo su -
# wget http://bit.ly/rvm-install-system-wide
# chmod +x install-system-wide
# ./install-system-wide
When that's done, we need to actually install a ruby. We'll be using ruby 1.9.2, which is the new hotness.
# rvm package install openssl
# rvm install 1.9.2 -C --with-openssl-dir=/usr/local/rvm/usr
and wait while rvm downloads and compiles it. This will take a while. Finally, we need to add rvm loading code to the system-wide .bashrc file. Open /etc/bashrc and add this line to the end:
[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"
###Creating roomtrol user
We don't want to run the server as root, so we're going to create a roomtrol user to run everything under
$ sudo su -
# useradd -G rvm roomtrol
We also need to create a deployment directory and assign it to the roomtrol user:
# mkdir /var/roomtrol-server
# chown roomtrol /var/roomtrol-server
# mkdir /var/www/
# chown roomtrol /var/www
###Modify sudo In order for our automated sudo scripts to work, we need to make some modifications to the sudo policies.
sudo su -
visudo
Find the line Defaults requiretty
and comment it out (prepend with a #). Also, add this line:
roomtrol ALL=(ALL) NOPASSWD: ALL
###Add deploy public key
In order to deploy code onto the server, you need to add your personal public key to the roomtrol user's .ssh directory for SSH public key authentication. If you don't yet have a personal key pair, on your local machine do:
$ ssh-keygen -t rsa -C "[email protected]"
Make sure to set a strong passphrase for your key. To set up ssh key authentication, copy the ~/.ssh/id_rsa.pub file you just created to the server. I assume that it is located at /home/roomtrol/id_rsa.pub.
$ sudo su roomtrol
$ mkdir ~/.ssh
$ cat ~/id_rsa.pub > ~/.ssh/authorized_keys
You should now be able to ssh in to the server without providing a password (though you will need to decrypt your private key with the passphrase you set earlier).
###Get a copy of the repository
You're going to need a local copy of the roomtrol-server repository to push to the server.
$ sudo git clone [email protected]:mwylde/roomtrol-server.git
$ cd roomtrol-server
$ sudo git submodule init
$ sudo git submodule update
###Pushing the source
Finally we're ready to actually push the code to the server. First, we need to make sure that the server's address is in the servers.json file located in the roomtrol-server directory. servers.json should look like this:
{
"servers": [
"ozymandias.class.wesleyan.edu",
"YOUR_SERVERS_ADDRESS_HERE"
],
"controllers": [
"wescontrol-509a.class.wesleyan.edu"
]
}
You should add your server if it's not already there. Now, navigate into your local roomtrol-server directory and run
$ bundle install # installs all the gems we need, including capistrano
$ rake deploy_servers # deploys the sproutcore app onto the server
$ rake deploy_roomtrol_server # set up the directory structure on the server
###Setting up god
We're using god to manage everything. We need to add it to init.d so that it will get started up at boot. Copy this to /etc/init.d/god
#!/bin/bash
#
# God
#
# chkconfig: - 85 15
# description: start, stop, restart God
#
RETVAL=0
\. "/usr/local/rvm/environments/ruby-1.9.2-p0"
case "$1" in
start)
god -P /var/run/god.pid -l /var/log/god.log
god load /var/roomtrol-server/roomtrol-server.god
RETVAL=$?
;;
stop)
kill `cat /var/run/god.pid`
RETVAL=$?
;;
restart)
kill `cat /var/run/god.pid`
god -P /var/run/god.pid -l /var/log/god.log
god load /var/roomtrol-server/roomtrol-server.god
RETVAL=$?
;;
status)
RETVAL=$?
;;
*)
echo "Usage: god {start|stop|restart|status}"
exit 1
;;
esac
exit $RETVAL
And run these commands:
$ sudo su -
# chmod a+x /etc/init.d/god
# chkconfig --add god
# chkconfig --level 345 god on
# /etc/init.d/god start
We're using apache even though it kind of sucks, because it's installed by default on CentOS. We need to make a small change to the configuration to point it to the correct web directory. Edit /etc/httpd/conf/httpd.conf and change the line
DocumentRoot /var/www/html
to
DocumentRoot /var/www