Setting up your own Gitorious installation

In the following I will describe how to install gitorious on a server running Ubuntu Server 10.04.4 LTS. This article describes my way of installing gitorious based on the howto on

Run the following commands as root if not stated otherwise.

  1. Install ALL teh dependencies

    aptitude update
    aptitude install build-essential zlib1g-dev tcl-dev libexpat-dev libcurl4-openssl-dev apache2 mysql-server
      mysql-client apg geoip-bin libgeoip1 libgeoip-dev sqlite3 libsqlite3-dev imagemagick libpcre3 libpcre3-dev
      zlib1g zlib1g-dev libyaml-dev libmysqlclient15-dev apache2-dev libonig-dev libmagick++-dev zip
      unzip memcached git-core git-svn git-doc git-cvs irb sphinxsearch libxslt-dev libxml2-dev

    (optionally also install postfix and phpmyadmin. as I’m already running a postfix on another machine I don’t need it and I don’t need phpmyadmin at all)

  2. Install ActiveMQ

    aptitude install uuid uuid-dev openjdk-6-jre
    cd /tmp
    tar xzvf apache-activemq-5.5.1-bin.tar.gz -C /usr/local/
    echo "export ACTIVEMQ_HOME=/usr/local/apache-activemq-5.5.1" >> /etc/activemq.conf
    echo "export JAVA_HOME=/usr/" >> /etc/activemq.conf
    adduser --system --no-create-home activemq
    chown -R activemq /usr/local/apache-activemq-5.5.1/data
  3. Disable multicasting of ActiveMQ. Open /usr/local/apache-activemq-5.5.1/conf/activemq.xml and change the following lines:

        <transportConnector name="openwire" uri="tcp://"/>

    to something like this:

        <transportConnector name="openwire" uri="static://(tcp://"/>
  4. Setup the startup script for ActiveMQ and start it

    mv activemq /etc/init.d/activemq
    chmod +x /etc/init.d/activemq
    update-rc.d activemq defaults
    service activemq start
  5. Download and install Ruby Enterprise Edition

    dpkg -i ruby-enterprise_1.8.7-2012.02_amd64_ubuntu10.04.deb
  6. Download and install RubyGems

    tar xzvf rubygems-1.8.17.tgz
    cd rubygems-1.8.17
    ruby setup.rb
  7. Install the required Gems

    gem install -b --no-ri --no-rdoc rmagick chronic geoip daemons hoe echoe ruby-yadis ruby-openid mime-types
      diff-lcs json rack ruby-hmac rake stompserver passenger rails ultrasphinx mysql
    gem install -b --no-ri --no-rdoc -v 1.0.1 rack
    gem install -b --no-ri --no-rdoc -v rdiscount
    gem install -b --no-ri --no-rdoc -v 1.1 stomp
  8. Clone the gitorious repository (in the following we assume that /var/www/gitorious is the installation path of gitorious)

    cd /var/www/
    git clone git:// /var/www/gitorious
    git submodule init
    git submodule update
  9. Copy the required init-scripts

    cp /var/www/gitorious/doc/templates/ubuntu/git-daemon /etc/init.d/
    cp /var/www/gitorious/doc/templates/ubuntu/git-ultrasphinx /etc/init.d/
  10. Change the paths in /etc/init.d/git-daemon to fit your installation.

    GIT_DAEMON="bundle exec $RUBY_HOME/bin/ruby $GITORIOUS_HOME/script/git-daemon -d"
  11. It is advised to use bundle exec for rake so change the following lines in /etc/init.d/git-ultrasphinx

    START_CMD="cd $GITORIOUS_HOME && bundle exec rake ultrasphinx:daemon:start RAILS_ENV=production"
    STOP_CMD="cd $GITORIOUS_HOME && bundle exec rake ultrasphinx:daemon:stop RAILS_ENV=production"
    RESTART_CMD="cd $GITORIOUS_HOME && bundle exec rake ultrasphinx:daemon:restart RAILS_ENV=production"
    STATUS_CMD="cd $GITORIOUS_HOME && bundle exec rake ultrasphinx:daemon:status RAILS_ENV=production"
  12. Create the init-scripts for git-poller and stomp from the gitorious tutorial

  13. Change the path of stompserver in /etc/init.d/stomp to /usr/local/bin/stompserver

  14. Set the correct permissions and activate the initialisation files:

    chmod 755 /etc/init.d/git-ultrasphinx /etc/init.d/git-daemon /etc/init.d/stomp /etc/init.d/git-poller
    update-rc.d stomp defaults
    update-rc.d git-daemon defaults
    update-rc.d git-ultrasphinx defaults
    update-rc.d git-poller defaults
  15. Run apache setup script and follow the instructions. When asked to edit the Apache config copy the stated config into /etc/apache2/mods-available/passenger.load:

  16. Enable the required Apache2 modules

    a2enmod passenger
    a2enmod rewrite
    a2enmod ssl
    a2ensite default-ssl
  17. Restart apache:

    service apache2 restart
  18. Add a ‘git’ user to MySQL with global create privileges. Also give it all privileges on gitorious_production.

    mysql -p
    > CREATE USER 'git'@'localhost' IDENTIFIED BY '\*\*\*\*\*\*\*\*';
    > GRANT CREATE ON \*.\* TO 'git'@'localhost';
    > GRANT ALL ON 'gitorious_production'.\* TO 'git'@'localhost';
    > EXIT
  19. Create /etc/apache2/sites-available/gitorious and /etc/apache2/sites-available/gitorious-ssl using the listings on the gitorious tutorial (the SSL is required for login!)

    a2dissite default
    a2dissite default-ssl
    a2ensite gitorious
    a2ensite gitorious-ssl
  20. Add a user ‘git’ to the system:

    adduser --system --home /var/www/gitorious/ --no-create-home --group --shell /bin/bash git
  21. Set permissions on the gitorious tree:

    chown -R git:git /var/www/gitorious 
  22. Now run the following sequence of commands:

    su - git
    cd /var/www/gitorious
    mkdir .ssh
    touch .ssh/authorized_keys
    chmod 700 .ssh
    chmod 600 .ssh/authorized_keys
    mkdir tmp/pids
    mkdir repositories
    mkdir tarballs
    cp config/database.sample.yml config/database.yml
    cp config/gitorious.sample.yml config/gitorious.yml
    cp config/broker.yml.example config/broker.yml
  23. If you have a seperate partition or disk for the repositories create the corresponding entry in /etc/fstab and run

    mount -a
  24. Edit config/database.yml: Remove every section but production and change the database parameter to fit your setup (i.e. change username and password)

  25. Edit config/gitorious.yml: Remove every section but production (so at the top tab level only production: should exist)

  26. Check the settings in config/gitorious.yml and modify the following lines:

    gitorious_client_host: localhost
    repository_base_path: "/var/www/gitorious/repositories"
    archive_cache_dir: "/var/www/gitorious/tarballs"
    archive_work_dir: "/tmp/tarballs-work"
    cookie_secret: ssssht (use `apg -m 64` to generate a key)
    sender_email_address: " <>"
  27. To use an external mail server change the following lines in config/environments/production.rb

    config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
             :address => "",
             :port => 25,
             :domain => "kitty"
  28. Run the following as root:

    cd /var/www/gitorious
    bundle install
  29. Insert the following line at the beginning of Rakefile and config/environment.rb

    require 'thread'
  30. Run the following as git user (note if you have to drop out to root again because it tells you that you missed some gems then remember to do the export again when you have su’d back into the git user!):

    export RAILS_ENV=production
    bundle exec rake db:create
    mysql -u root -p
    > GRANT ALL ON 'gitorious_production'.* TO 'git'@'localhost';
    > EXIT
    bundle exec rake db:migrate
    bundle exec rake ultrasphinx:bootstrap
  31. Add the following line to the crontab (run crontab -e as user ‘git’ to edit the crontab):

    * * * * * cd /var/www/gitorious && /usr/bin/rake ultrasphinx:index RAILS_ENV=production
  32. Now create an admin user. Therefore run the following as git user:

    bundle exec ruby script/create_admin
  33. Restart apache as root

    service apache2 restart
  34. Start the daemons

    service stomp start
    service git-daemon start
    service git-ultrasphinx start
    service git-poller start