Gitorious Install On Debian Squeeze

Gitorious install on Debian Squeeze

Gitorious is a repositories hosting based on a distributing version of Git control system. This is the second popular service after Github. The source code for the project is available on the AGPL license. AGPL claims that the modified source code of the application would remain available to users on the network. I.e. if you make any changes to your Gitorious installation — all changes should be available to its users.

Installation of all required packages for Gitorious:

aptitude install nginx mysql-server mysql-client git-core git-svn apg build-essential libpcre3 libpcre3-dev make zlib1g zlib1g-dev ssh libonig-dev libyaml-dev geoip-bin libgeoip-dev libgeoip1 imagemagick libmagickwand-dev memcached libssl-dev libreadline5-dev libxslt-dev libxml2-dev libmysqlclient-dev openjdk-6-jre

Set the standard encoding for MySQL:

(в /etc/mysql/my.cfg)

character-set-server=utf8
collation-server=utf8_general_ci

# /etc/init.d/mysql restart

That's how we do Gitorious install on Debian Squeeze.

Installing Ruby Enterprise Edition:

Ruby Enterprise Edition is focused on server-side use of Ruby assembly. It includes optimized performance and main storage usage. Read more here.

# wget http://rubyenterpriseedition.googlecode.com/files/ruby-enterprise-1.8.7-2012.02.tar.gz
# cd ruby-enterprise-1.8.7-2012.02/ && ./installer

The installer will check the availability of all required packages and if needed will offer to deliver them. Set in /opt/ruby-enterprise/

Add /opt/ruby-enterprise/bin in the variable $ PATH. This will let to perform the binary files in this directory without showing full path.

# echo PATH=$PATH:/opt/ruby-enterprise/bin >> /etc/bash.bashrc
# PATH=$PATH:/opt/ruby-enterprise/bin

Installing Apache ActiveMQ

Apache ActiveMQ is a message broker with open source software, it enables clustering, storage of messages with the possibility to use different databases and Gitorious needs it to work properly.

# wget http://apache.infocom.ua/activemq/apache-activemq/5.5.1/apache-activemq-5.5.1-bin.tar.gz
# tar xzvf apache-activemq-5.5.1-bin.tar.gz  -C /usr/local/
# ln -s /usr/local/apache-activemq-5.5.1/ /usr/local/apache-activemq

And in configuration /usr/local/apache-activemq/conf/activemq.xml edit a single line:


Then add an individual user and start ActiveMQ:

# useradd activemq
# chown -R activemq /usr/local/apache-activemq/*
# su activemq
# /usr/local/apache-activemq/bin/activemq start
# crontab -e
@reboot /usr/local/apache-activemq/bin/activemq start
# exit

We get the sources of Gitorious and start customizing it:

# useradd git
# mkdir -p /var/www/gitorious.exmaple.com && cd /var/www/gitorious.exmaple.com
# git clone git://gitorious.org/gitorious/mainline.git ./

# /opt/ruby-enterprise/bin/gem install bundler
# /opt/ruby-enterprise/bin/gem install nokogiri -v '1.5.0'
# /opt/ruby-enterprise/bin/gem install mysql -v '2.8.1'
# /opt/ruby-enterprise/bin/gem install thin
# /opt/ruby-enterprise/bin/gem install ultrasphinx

# /opt/ruby-enterprise/bin/bundle install

# chown -R git:git /var/www/gitorious.exmaple.com/

Lets create a database:

# mysql -uroot -p
> CREATE DATABASE gitorious_production;
> CREATE USER 'gitorious_prod'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD';
> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, CREATE VIEW, EVENT, TRIGGER, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EXECUTE ON `gitorious\_production` . * TO 'gitorious_prod'@'localhost';

Prepare a directory for the repository:

mkdir -p /var/git/{repositories,tarballs,tarball-work}
chown -R git /var/git/
mkdir .ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys
# ln -s /var/www/gitorious.example.com/script/gitorious /usr/local/bin/gitorious

Rules configs of Gitorious:

# cd /var/www/gitorious.example.com/config
# cp database.sample.yml database.yml
# vi database.yml
production:
  adapter: mysql
  database: gitorious_production
  username: gitorious_prod
  password: 301522
  host: localhost
  encoding: utf8
# cp broker.yml.example broker.yml
# cp gitorious.sample.yml gitorious.yml

We need to edit the following parameters in gitorious.yml:

gitorious_client_port: 3000
gitorious_client_host: gitorious.example.com
gitorious_host: gitorious.example.com
cookie_secret: !this option you should fill with random symbols, for example, with result of apg -m 64 (in one line)!
use_ssl: false
public_mode: false
enable_private_repositories: true
only_site_admins_can_create_projects: true
is_gitorious_dot_org: false

Lets fulfill migrates of database:

# rake db:setup RAILS_ENV=production

If you get an error "uninitialized constant ActiveSupport::Dependencies::Mutex":

# gem install rubygems-update -v='1.4.2'
# update_rubygems

Now add the administrator:

# env RAILS_ENV=production ruby script/create_admin
Type in Administrator's e-mail:
myname@example.com
Type in Administrator's password:
yours_strong_password
Admin user created successfully.

>> user = User.first
...
>> user.login = "myname" 
=> "myname" 
>> user.activate
=> true
>> user.accept_terms
=> true
>> user.save
=> true
>> quit

Now add the scripts in the crontab:

# su git
# crontab -e
@reboot cd /var/www/gitorious.example.com/ && /opt/ruby-enterprise/bin/bundle exec thin start -d -e production
@reboot cd /var/www/gitorious.example.com/script && /opt/ruby-enterprise/bin/bundle exec ./git-daemon
@reboot cd /var/www/gitorious.example.com/script && RAILS_ENV=production /opt/ruby-enterprise/bin/bundle exec ./poller start
@reboot cd /var/www/gitorious.example.com && /opt/ruby-enterprise/bin/bundle exec rake ultrasphinx:daemon:start RAILS_ENV=production

50      *       *       *       *       cd /var/www/gitorious.example.com && /opt/ruby-enterprise/bin/bundle exec rake ultrasphinx:index RAILS_ENV=production

Now you need to run them all by hand, or simply reboot the system.

If Gitorious has no reference to the addresses of repositories, it is necessary to download java script from gitorious.org:

# cd /var/www/gitorious.example.com/public/javascripts
# rm all.js
# wget http://gitorious.org/javascripts/all.js

Configuring of nginx

We need Nginx, for several reasons:

  • Thin can serve only one ROR application, and if we want to host for something else – we won’t do it without a proxy web server.
  • Slow-connection. Nginx copes much better with slow connections and its use will increase productivity.

In /etc/nginx/nginx.conf, section add http:

include /etc/nginx/vhost/*;
# vi /etc/nginx/vhost/gitorious.example.com

server {
        listen server_ip:80;
        server_name gitorious.example.com;
        client_max_body_size 5M;

        location / {
                proxy_pass http://127.0.0.1:3000/;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

}

# /etc/init.d/nginx reload

Search setting

Putting sphinx.

# wget http://sphinxsearch.com/files/sphinx-2.0.4-release.tar.gz
# tar zxf sphinx-2.0.4-release.tar.gz && cd sphinx-2.0.4-release/
# ./configure
# make
# make install

Run ultrasphinx.

# su git
# cd /var/www/gitorious.example.com/
# /opt/ruby-enterprise/bin/bundle exec rake ultrasphinx:bootstrap

Usefull links: