Version 1 (modified by 11 years ago) (diff) | ,
---|
Installation of a Rails platform
- Note: this doc was originally published as http://bearstech.com/doc/installation-rails-locale
This is a short documentation which explains how to set up a Rails environment in a Unix "home". Expected usage is to have one account per application: it makes it very easy to maintain parallel environmenens with their own Gems and such, while sharing a server and the basic infrastructure like the Ruby interpreter and core libs.
1. Install a local version of Gem
Because its repository and install paths are setup at install time, we need to install and build it with GEM_HOME already set into our user account.
Recommended: 'apt-get remove rake rubygems libgems-ruby1.8'
# su - ror $ cd ~ $ mkdir gem $ export GEM_HOME=~/gem $ wget http://rubyforge.org/frs/download.php/57643/rubygems-1.3.4.tgz $ tar xzf rubygems-1.3.4.tgz $ cd rubygems-1.3.4 $ ruby1.8 setup.rb --prefix=~
Set up a useful symlink:
cd ~/bin ln -s gem1.8 gem
In ~/.bashrc (and no other file), add:
export EDITOR=vim alias less='less -R' alias grep='grep --color=auto' alias ls='ls --color=auto' alias ll='ls --color=auto -la' alias reload='thin restart -C ~/site/prod/config/thin.yml' alias maintenance='touch ~/site/prod/public/maintenance/ENGAGED' alias no_maintenance='rm ~/site/prod/public/maintenance/ENGAGED' alias sc='./script/console' source ~/ruby-env
Create a ~/ruby-env file (which can be sourced from your cronjobs):
#!/bin/sh export GEM_HOME=~/gem export RUBYLIB=~/lib export PATH=~/bin:$GEM_HOME/bin:$PATH if [ -z "$LANG" ]; then export LANG=en_US.UTF-8 fi # Comment this if you're not on a production environment! export RAILS_ENV=production
Create a ~/.gemrc file:
--- :sources: - http://gems.rubyforge.org - http://gems.github.com :bulk_threshold: 1000 :update_sources: true :verbose: true :backtrace: false :benchmark: false gem: --no-ri --no-rdoc
And finally, a ~/.vimrc config:
set bg=dark set bs=2 set dir-=. set ek set ff=unix set is set ls=2 set lz set nojs set pt=<F11> set wildmenu set wildignore+=*.o,*.so,*.a,.svn,*.pyc
...and log in again.
2. Install a local Rails (deprecated, let the devs choose which version they want)
This is pure Ruby code, nothing special - it should just work.
$ gem install rails --no-rdoc --no-ri
3. Install a local Mongrel (deprecated, let the devs choose which server they want, usually "thin")
This boring part has some C blurbs. So:
$ sudo aptitude install build-essential ruby1.8-dev $ gem install mongrel
4. Install an init script
For instance as /etc/init.d/thin
, then run update-rc.d thin defaults 99
to insert it in the sysv boot sequence.
Source code for such a script:
#! /bin/bash # thind init script (c) 2009 Bearstech - http://bearstech.com # Author: Lucas Fernandez <lfernandez@bearstech.com> # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # Do NOT "set -e" # PATH should only include /usr/* if it runs after the mountnfs.sh script # PATH=/sbin:/usr/sbin:/home/ror/bin:/home/ror/gem/bin:/home/ror/bin:/usr/local/bin:/usr/bin:/bin DESC="Ruby on Rails webserver" NAME="thin" DAEMON=/home/ror/gem/bin/$NAME DAEMON_ARGS="-C /home/ror/http/thin.conf" PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/home/ror/init.d/thind # # Function that starts the daemon/service # do_start() { if [ "x`pgrep ^${NAME}$ | head -n1`" != "x" ] ; then echo -e "\n \\033[0;31;40mErr :\\033[0;39m $NAME already running" exit 1 else $DAEMON $DAEMON_ARGS start fi } # # Function that stops the daemon/service # do_stop() { if [ "x`pgrep ^${NAME}$ | head -n1`" == "x" ] ; then echo -e "\\033[0;31;40mErr :\\033[0;39m $NAME already stop" exit 1 fi $DAEMON $DAEMON_ARGS stop } # # Function that restart the daemon/service # do_restart() { $DAEMON $DAEMON_ARGS restart } # # Function that check daemon/service status # do_check_status() { if [ "x`pgrep ^${NAME}$ | head -n1`" != "x" ] ; then echo "Thin is running PID : " pgrep ^${NAME}$ return 1 else echo "Thin is not running" return 2 fi } case "$1" in start) echo "Starting $NAME ..." do_start ;; stop) echo "Stopping $NAME ..." do_stop ;; restart|force-reload) echo "Restarting $NAME ..." do_restart ;; status) do_check_status ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2 exit 3 ;; esac