Installing and Setting Up Gitorious on RHEL 5

Gitorious is an open source application originally
developed for hosting open source projects in git repositories. This document
describes how to install Gitorious on Red Hat Enterprise 5 (RHEL 5) server.

This guide also covers how to install the services Gitorious is dependent on,
including:

  • Web server (Apache)
  • Database server (MySQL)
  • Ruby (Enterprise Edition)

The guide is based on:

The installation guide is tested with customized version of Gitorious named
YouSource, version
b6e0a37f99fd73523fbc369a635cf73d24ca5cb6 (Git hash, 19.5.2011).

All the commands are meant to run as root user, if not mentioned otherwise.

Install Required Packages

Gitorious needs a lot of software:

yum install -y git pcre pcre-devel zlib sendmail libssh2 libssh2-devel \
  openssh openssh-server memcached libyaml libyaml-devel \  
  ImageMagick ImageMagick-devel apr-devel uuid glibc-devel sphinx

Yousource needs also python-ldap.

yum install -y python-ldap

Install Ruby and Rubygems

Gitorious runs on a variety of Rubys (>= 1.8.7). If you want to use the basic
Ruby, you can install it with:

yum install -y ruby ruby-devel rubygems

If you want to install Ruby Enterprise Edition,
you have to download the source tarball. The source tarball contains a cross-platform
installer. This guide is based on Ruby Enterprise so we recommend to use it.

wget http://rubyenterpriseedition.googlecode.com/files/ruby-enterprise-1.8.7-2011.03.tar.gz
tar xzvf ruby-enterprise-1.8.7-2011.03.tar.gz  
./ruby-enterprise-1.8.7-2011.03/installer  
ln -s /usr/local/ruby-enterprise-1.8.7-2011.03/ /usr/local/ruby-enterprise

Ruby Enterprise installer might ask you to install some packages it depends on,
install them as the installer guides you to. We needed to do this:

yum install gcc-c++ zlib-devel openssl-devel readline-devel curl-devel

Install and Configure MySQL

Gitorious should work with any SQL server, but it’s only tested with MySQL.

  • Install MySQL

    yum install mysql mysql-server mysql-devel
    
  • Start the service

    service mysqld start
    
  • Set a password for root user. Replace <password> with your own password.

    mysqladmin -u root password '<password>'
    

Install a Web Server

Gitorious is a web application, so you need a web server. Here we install
Apache, but you can use some other web server as well.
Install also the XSendFile module
to get source tarball downloading working.

yum install -y httpd httpd-devel mod_xsendfile

Set Up git User

Gitorious needs a specific user which runs the services. Here it’s named git.
Gitorious uses SSH keys in authentication in Git push. The git user needs to
have a home directory, where the SSH keys are saved.

adduser --create-home git

Because git push is authenticated via git user, the git user must have a ssh
access to the server. So add git user to AllowGroups in /etc/ssh/sshd_config
and restart sshd.

Add these lines in the end of the git user’s ~/.bashrc file so that git user
can run ruby programs. Change RUBY_HOME to match your Ruby installation
directory.

export RUBY_HOME=/usr/local/ruby-enterprise
export GEM_HOME=$HOME/gems  
export PATH=$GEM_HOME/bin:$RUBY_HOME/bin:$PATH

Load new paths as a git user:

source ~/.bashrc

Make git User’s authorized_keys File

When someone tries to push to a repository through Gitorious, the user will be
looked up in the git user’s ~/.ssh/authorized_keys. If the user is found here,
the git operation is handled by gitorious script which will be discussed later.
We have to create authorized_keys file, but Gitorious will maintain it for us.

Make sure the permissions on authorized_keys are 600 and ~/.ssh are 700.

mkdir ~/.ssh
chmod 700 ~/.ssh  
touch ~/.ssh/authorized_keys  
chmod 600 ~/.ssh/authorized_keys

Clone the Gitorious Repository

Go to the directory where you want to download the application, for example to
/var/www. Use git to download Gitorious.

git clone git://gitorious.org/gitorious/mainline.git gitorious

Or if you want to install customized version of Gitorious named YouSource:

git clone git://yousource.it.jyu.fi/yousource/yousource.git gitorious

Make a symbolic link of gitorious script to /usr/local/bin/.
The script is used to check the permission rights to repository when
accessing it via SSH.

ln -s /var/www/gitorious/script/gitorious /usr/local/bin/gitorious

Install Required Gems

Gitorious is not currently compatible with gem version 1.5 and newer,
version 1.4.2 works fine.

gem update --system 1.4.2

Install the required gem packages as a git user.

su - git -c "cd /var/www/gitorious && bundle install --deployment"

On development environment you can run bundle install without the
--deployment option to install the gems system-wide.

Create the Directories for Repositories and Tarballs

Make the directories where the git repositories, releases and tarballs are saved.

mkdir /var/git /var/git/repositories /var/git/tarballs /var/git/tarballs-work /var/git/releases

Change the owner of these and the application directories to git user.

chown -R git:git /var/git /var/www/gitorious

Install and Configure Passenger

Install Phusion Passenger module to simplify Rails application deployment.

/usr/local/ruby-enterprise/bin/passenger-install-apache2-module

Follow the instructions as provided by the installation script.

Edit Apache configuration file /etc/httpd/conf/httpd.conf and add the lines
the installation script recommend, something like this:

LoadModule passenger_module /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-3.0.7  
PassengerRuby /usr/local/ruby-enterprise/bin/ruby

Add XSendFile configurations below the LoadModule lines.

XSendFile on
XSendFilePath /var/git/tarballs

In the same file set DocumentRoot to <your-gitorious-root>/public, for example
/var/www/gitorious/public, and set your ServerName (ours is yousource.it.jyu.fi).

<VirtualHost *:80>
   ServerName yousource.it.jyu.fi  
   DocumentRoot /var/www/gitorious/public  

   <Directory /var/www/gitorious/public>  
      AllowOverride all  
      Options -MultiViews  
   </Directory>  
</VirtualHost>

<VirtualHost *:443>  
   ServerName yousource.it.jyu.fi  
   DocumentRoot /var/www/gitorious/public  

   <Directory /var/www/gitorious/public>  
      AllowOverride all  
      Options -MultiViews  
   </Directory>  
</VirtualHost>

Restart Apache and after that Passenger should recognize the application and
start it when accessing the web page through a web browser.

Install Messaging Server

Some operations Gitorious performs take too long to run for the user to wait for
it to complete before a page is rendered. Cloning a large Git repository,
for example, can take several minutes to complete.

Gitorious solves this by creating a message describing the operation that should
be performed, and sending this off to a separate process. This is achieved using
the ActiveMessaging plugin. This plugin supports a number of different message
queue services; the config/broker.yml file defines which service you use.

One option is to use ActiveMQ but in this guide
we use stompserver and stomp connector.

su - git -c "gem install stompserver stomp json"

Configuration

Next go to your Gitorious root dir (for example cd /var/www/gitorious) and
make a directory for pid files.

mkdir -p tmp/pids

Make all the Gitorious scripts executable.

chmod ug+x script/*

Copy the configuration sample files and edit the settings. The files includes
good instructions.

cp config/database.sample.yml config/database.yml
cp config/gitorious.sample.yml config/gitorious.yml  
cp config/broker.yml.example config/broker.yml

If you installed customized YouSource, you have to edit these files too:

cp config/email.yml.example config/email.yml
cp script/ldap_settings.py.template script/ldap_settings.py

Create the database and schema:

bundle exec rake db:setup RAILS_ENV=production

Search Indexing

Build the search index and start the search daemon:

bundle exec rake ultrasphinx:configure RAILS_ENV=production
bundle exec rake ultrasphinx:index RAILS_ENV=production  
bundle exec rake ultrasphinx:daemon:start RAILS_ENV=production

Schedule Sphinx search engine to index the site automatically. Add to the
crontab, using crontab -e, the following line:

* * * * * cd /var/www/gitorious && /usr/local/ruby-enterprise/bin/bundle exec rake ultrasphinx:index RAILS_ENV=production

Scripts

Copy git-daemon, git-poller, stomp and git-ultrasphinx from
doc/templates/centos to /etc/init.d/ as root user.

In these files edit the RUBY_HOME and GITORIOUS_HOME variables to match
your installation. In stomp script edit also the GEMS_HOME variable to
point to the directory where you installed stompserver gem.

Start the Services

Add services to start automatically on boot:

chkconfig --add stomp
chkconfig --add git-daemon  
chkconfig --add git-poller  
chkconfig --add git-ultrasphinx  
chkconfig --add memcached

chkconfig stomp on  
chkconfig git-daemon on  
chkconfig git-poller on  
chkconfig git-ultrasphinx on  
chkconfig memcached on

Now you can start the services:

service stomp start
service git-daemon start  
service git-poller start  
service git-ultrasphinx start  
service memcached start  
service httpd restart

Now you should have Gitorious up and running! Go to your web page through a
browser and start using Gitorious.