Gitorious on Ubuntu 12.04 mini-HOWTO

Gitorious provides open source infrastructure for hosting open source projects that use Git. This mini-HOWTO will guide you though the installation procedure on Ubuntu 12.04.

Before start I will assume you have a clean Ubuntu Server 12.04 installed with minimal packages requirement. It is strongly recommend to install on a new host, as it will modify a lot of default settings ;-)

Install the base system

First of all you should install Ubuntu 12.04 with minimal packages, almost nothing else is required at the beginning.

After initial installation run the following command to upgrade your system as latest stable + some optional useful packages:

aptitude update && \
aptitude -y full-upgrade && \
tasksel install openssh-server && \
tasksel install server && \
tasksel install mail-server && \
aptitude -y install colordiff locate ntp pwgen rsync vim

Install packages

Let's clone the similar setup as DebianSqueezeInstallation:

aptitude -y install activemq apache2 apache2-threaded-dev apg aspell aspell-en build-essential geoip-bin git-core git-cvs git-doc git-svn imagemagick libapache2-mod-passenger libapache2-mod-xsendfile libaspell-dev libcurl4-openssl-dev libdbd-mysql-ruby libexpat1-dev libgeoip-dev libgeoip1 libmagick++-dev libmagick++4 libmysql-ruby libmysqlclient-dev libonig-dev libpcre3 libpcre3-dev libreadline-dev libreadline5 libruby libsqlite3-dev libxslt1-dev libyaml-dev memcached mysql-client mysql-server openjdk-6-jre postfix ruby ruby-dev rubygems sphinxsearch sqlite3 unzip zip zlib1g zlib1g-dev

Fetch Gitorious

git clone git://gitorious.org/gitorious/mainline.git /var/www/gitorious
cd /var/www/gitorious
git submodule init
git submodule update
ln -s /var/www/gitorious/script/gitorious /usr/local/bin/gitorious

Install RubyGem

REALLY_GEM_UPDATE_SYSTEM=1 gem update --system
gem install -b --no-ri --no-rdoc bundler
cd /var/www/gitorious/
bundle pack --all
bundle install --path vendor/cache

Initialize services

Refer to latest changes since 2012-11-01, we no longer use ultrasphinx and replace with thinking_sphinx, therefore create our own /var/www/gitorious/doc/templates/ubuntu/git-thinking_sphinx as below:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          git-thinking_sphinx
# Required-Start:    mysql
# Required-Stop:     
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Thinking Sphinx daemon
# Description:       Starts the Thinking Sphinx daemons needed by Gitorious
### END INIT INFO

# Author: Fabio Akita <fabioakita@gmail.com>

GITORIOUS_HOME="/var/www/gitorious"
RETVAL=0
START_CMD="cd $GITORIOUS_HOME && rake thinking_sphinx:start RAILS_ENV=production"
STOP_CMD="cd $GITORIOUS_HOME && rake thinking_sphinx:stop RAILS_ENV=production"
RESTART_CMD="cd $GITORIOUS_HOME && rake thinking_sphinx:restart RAILS_ENV=production"
LOCK_FILE=/var/lock/git-thinking_sphinx
PID_FILE=$GITORIOUS_HOME/db/sphinx/log/searchd.pid

case "$1" in
  start)
    echo -n "Starting git-thinking_sphinx"
    /bin/su - git -c "$START_CMD" 1>/dev/null 2>/dev/null && echo "." || echo ": FAILURE (already running?)"
    ;;
  stop)
    echo -n "Stopping git-thinking_sphinx"
    /bin/su - git -c "$STOP_CMD" 1>/dev/null 2>/dev/null && echo "." || echo ": FAILURE (maybe not runni
ng?)"
    ;;
  restart)
    echo -n "Restarting git-thinking_sphinx"
    /bin/su - git -c "$RESTART_CMD" 1>/dev/null && echo "."  || echo ": FAILURE"
    ;;
  *)
    echo $"Usage: $0 {start|stop|restart}"
    RETVAL=1
esac
exit $RETVAL

Now initialize Gitorious as below:

cd /var/www/gitorious/doc/templates/ubuntu
chmod 755 git-thinking_sphinx git-poller
ln -s /var/www/gitorious/doc/templates/ubuntu/git-thinking_sphinx /etc/init.d/git-thinking_sphinx
ln -s /var/www/gitorious/doc/templates/ubuntu/git-poller /etc/init.d/git-poller
ln -s /var/www/gitorious/doc/templates/ubuntu/gitorious-logrotate /etc/logrotate.d/gitorious
update-rc.d git-thinking_sphinx defaults 99 00
update-rc.d git-poller defaults 99 00
ln -s /usr /opt/ruby-enterprise

Configure Apache2

Enable required modules:

a2enmod passenger rewrite ssl xsendfile
/etc/init.d/apache2 restart

Create /etc/apache2/sites-available/gitorious as below:

<VirtualHost *:80>
  ServerAdmin webmaster@localhost

  DocumentRoot /var/www/gitorious/public

  ErrorLog /var/log/apache2/gitorious-error.log
  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel warn

  CustomLog /var/log/apache2/gitorious-access.log combined

  <IfModule mod_xsendfile.c>
    XSendFile on
    XSendFilePath /var/www/gitorious/tarballs
  </IfModule>

</VirtualHost>

Create /etc/apache2/sites-available/gitorious-ssl as below:

<IfModule mod_ssl.c>
  <VirtualHost _default_:443>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/gitorious/public

    ErrorLog /var/log/apache2/gitorious-error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/gitorious-ssl_access.log combined

    SSLEngine on

    SSLCertificateFile  /etc/ssl/certs/ssl-cert-snakeoil.pem
    SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

    BrowserMatch ".*MSIE.*" \
      nokeepalive ssl-unclean-shutdown \
      downgrade-1.0 force-response-1.0

    <IfModule mod_xsendfile.c>
      XSendFile on
      XSendFilePath /var/www/gitorious/tarballs
    </IfModule>

  </VirtualHost>
</IfModule>

So let's restart Apache2 with new site setup:

a2dissite default
a2dissite default-ssl
a2ensite gitorious
a2ensite gitorious-ssl
/etc/init.d/apache2 restart

Setup MySQL

Start the mysql command line client by running:

mysql -uroot -p <<-EOF
DROP DATABASE IF EXISTS gitorious_production;
CREATE DATABASE IF NOT EXISTS gitorious_production DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
EOF

Configure ActiveMQ

Create new ActiveMQ instance:

cp -rfp /etc/activemq/instances-available/main /etc/activemq/instances-available/gitorious

Edit /etc/activemq/instances-available/gitorious/activemq.xml. Remove the predefined transportConnector and add a new one using the stomp protocol:

sed -i 's/<transportConnector name=.*/<transportConnector name="stomp" uri="stomp:\/\/127.0.0.1:61613"\/>/g' /etc/activemq/instances-available/gitorious/activemq.xml

Enable ActiveMQ instance:

cd /etc/activemq/instances-enabled
ln -s ../instances-available/gitorious .

Restart ActiveMQ:

/etc/init.d/activemq restart

Configure Gitorious

Run the following:

cd /var/www/gitorious
adduser --system --home /var/www/gitorious --no-create-home --group --shell /bin/bash git
chown -R git:git /var/www/gitorious
git submodule init
git submodule update
mkdir .ssh
touch .ssh/authorized_keys
chmod -R go-rwx .ssh
mkdir tmp/pids repositories tarballs tarballs-work
cp config/database.sample.yml config/database.yml
cp config/gitorious.sample.yml config/gitorious.yml
cp config/broker.yml.example config/broker.yml
chown -R git:git /var/www/gitorious

Edit config/gitorious.yml: Remove every section but production

  • gitorious_client_port should be 80
  • gitorious_client_host should be your localhost for Apache2
  • gitorious_host needs to be the exact hostname (e.g. gitorious.example.com) that clients will use (cookies get messed up otherwise)
  • repository_base_path should be something like /var/www/gitorious/repositories
  • archive_cache_dir should be something like /var/www/gitorious/tarballs
  • archive_work_dir should be something like /var/www/gitorious/tarballs-work
  • cookie_secret should generated by "apg -m 64"
  • exception_notification_emails should be something like admin@example.com
  • disable_record_throttling should be true (optional, but RECOMMENED!)
  • public_mode should be false (optional)
  • enable_private_repositories should be true (optional)
  • repos_and_projects_private_by_default should be true (optional, if most of your GIT are private)
  • only_site_admins_can_create_projects should be true (optional, better for local team management)
  • hide_http_clone_urls should be true (they require extra unknown setup to work)
  • is_gitorious_dot_org should be false
  • sender_email_address should be something "Gitorious <no-reply@example.com>"
  • gitorious_support_email should be something like support@example.com

Update your database connection for production in config/database.yml as below:

production:
  adapter: mysql
  database: gitorious_production
  username: root
  password: "your_secret_password"
  host: localhost
  encoding: utf8

Run the following:

cd /var/www/gitorious
export RAILS_ENV=production
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake thinking_sphinx:configure
bundle exec rake thinking_sphinx:index

Update contab by "crontab -e" as below:

sudo su -
crontab -e
* * * * * cd /var/www/gitorious && /usr/bin/bundle exec /usr/bin/rake thinking_sphinx:index RAILS_ENV=production >/dev/null 2>&1

Create a Admin User as User ‘git’:

env RAILS_ENV=production script/create_admin

Double check file permission for /var/www/gitorious:

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

Finish

First of all reboot your system.

Now access your setup with browser, e.g. https://gitorious.example.com. Login and enjoy it ;-)

Upgrading

Assume you are using latest gitorious 2.2.x version, you can simply upgrade your installation as below:

export RAILS_ENV=production
cd /var/www/gitorious
git pull
git submodule init
git submodule update
bundle pack --all
bundle install --path vendor/cache
rake assets:clear
rake db:migrate
chown -R git:git /var/www/gitorious

To keep it simple and stupid, just reboot your system and everything should now work fine; or you can execute the following command in order to restart all related services without reboot:

/etc/init.d/activemq restart
/etc/init.d/apache2 restart
/etc/init.d/git-poller restart
/etc/init.d/git-thinking_sphinx restart
/etc/init.d/memcached restart
/etc/init.d/mysql restart

Comments

root's picture

I had the following error after modifying environment.rb:

$ bundle exec rake db:create
(in /var/www/gitorious)
rake aborted!
uninitialized constant ActiveSupport::Dependencies::Mutex
/var/www/gitorious/Rakefile:10:in `require'
(See full trace by running task with --trace)

My research turned up the following link:
http://stackoverflow.com/questions/5176782/uninitialized-constant-active...

It turns out the the following lines should be at the top of boot.rb instead of environment.rb (not also that 'config', is not in the second line as it is in the instructions above):
require 'thread'
require File.join(File.dirname(__FILE__), 'boot')

root's picture

You need to make sure that you the correct password in database.yml for rake db: commands to work.

root's picture

thanks a lot for this. i searched for days to find a tutorial which actually works. keep it up! cheers from austria!

root's picture

Hi,
Thanks a lot for this. But I have an error when I create a new project. the browser turn, turn and ... turn but no project is created....
In conf/production.log I have this error :
ActiveRecord::StatementInvalid (Mysql::Error: lock wait timeout exceeded)

What is my problem ? Can you help me ? I search but I don't find a solution.

Good day
Olivier

root's picture

Thanks for the tutorial. Everything works as expected, but I would like Gitorious to run at myserver.example.com/gitorious instead of myserver.example.com. That way I can serve other websites within other subdirectories. How can I go about doing this?

I tried modifying /etc/apache2/sites-available/gitorious so that the DocumentRoot is /var/www/ instead of /var/www/gitorious/public/. But then when I visit myserver.example.com/gitorious/public/ in a web browser, I get a listing of the files in that directory instead of the Gitorious application. Seems very strange to me. I also tried making an alias so that /gitorious/ points to /var/www/gitorious/public/, but that does the same thing (just lists the files).

Any help would be greatly appreciated.

root's picture

Wheu update submodules "git submodule init"
if you get this error:
error: server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none while accessing https://git.gitorious.org/buster/buster-core.git/info/refs

try: GIT_SSL_NO_VERIFY=true git submodule update --init

may be you need to delete /var/www/gitorious/public/javascripts/lib/buster-core
and retry

Hope this help someone!

root's picture

Hi,

I just installed gitorious and as I login with my admin account, I get an error.

ActionController::InvalidAuthenticityToken in SessionsController#create ActionController::InvalidAuthenticityToken

The only difference I can see in my install is that I'm using passenger-3.0.13

Any ideas?

Thanks, Steve

root's picture

Hi,

I'd like change the configuration so the gitorious URL is:

<myhost>/gitorious

I've been playing with DocumentRoot and Alias in the Apache but
not got it to work yet.

Any suggestions would be very welcome.

Thanks, Steve

root's picture

Very good guide, all works fine for me. Thank you !

root's picture

Hi Guys,
when I set up gitorious with the newest Ubuntu 12.04 updates, I was not able to install it when I changed my config/environment.rb to "require(File.join(File.dirname(__FILE__), 'config', 'boot'))".
But when I left it without the 'config' all worked fine.
Maybe it could help somebody.
Greetings

root's picture

Has anyone gotten LDAP to work with Gitorious? I have tried various permutations of http://gitorious.org/gitorious/pages/LdapIntegration without success.

root's picture

Congratulations on this article, very well documented and throughfull.

I found it while trying to restore my Gitorious setup after upgrading from 10.04 all the way into 12.04.

All is working now.

Regards,

Giannis's picture

At last an article with instructions that worked!

Thanks!

Diego Hernandes's picture

bundle exec rake ultrasphinx:bootstrap
shows me an error! he does not know the target, anyone? tanks

kurt's picture

I'm having the same problem. It's not getting installed. When I do the suggested "bundle exec rake --tasks" I don't see ultrasphinx as a possible task:
[code]

rake test:units # Run tests for unitsdb:test:prepare / Run the unit tests in test/unit
rake thinking_sphinx:configure # Generate the Sphinx configuration file using Thinking Sphinx's settings
rake thinking_sphinx:index # Index data for Sphinx using Thinking Sphinx's settings
rake thinking_sphinx:rebuild # Stop Sphinx (if it's running), rebuild the indexes, and start Sphinx
rake thinking_sphinx:reindex # Reindex Sphinx without regenerating the configuration file
rake thinking_sphinx:restart # Restart Sphinx
rake thinking_sphinx:running_start # Stop if running, then start a Sphinx searchd daemon using Thinking Sphinx's settings
rake thinking_sphinx:start # Start a Sphinx searchd daemon using Thinking Sphinx's settings
rake thinking_sphinx:stop # Stop Sphinx using Thinking Sphinx's settings
rake thinking_sphinx:version # Output the current Thinking Sphinx version
rake time:zones:all # Displays names of all time zones recognized by the Rails TimeZone class, grouped by offset.
rake time:zones:local # Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system loc...
rake time:zones:us # Displays names of US time zones recognized by the Rails TimeZone class, grouped by offset.
rake tmp:cache:clear # Clears all files and directories in tmp/cache
rake tmp:clear # Clear session, cache, and socket files from tmp/
rake tmp:create # Creates tmp directories for sessions, cache, sockets, and pids
rake tmp:pids:clear # Clears all files in tmp/pids
rake tmp:sessions:clear # Clears all files in tmp/sessions
rake tmp:sockets:clear # Clears all files in tmp/sockets
rake ts:conf # Generate the Sphinx configuration file using Thinking Sphinx's settings
rake ts:config # Generate the Sphinx configuration file using Thinking Sphinx's settings
rake ts:in # Index data for Sphinx using Thinking Sphinx's settings
rake ts:rebuild # Stop Sphinx (if it's running), rebuild the indexes, and start Sphinx
rake ts:reindex # Reindex Sphinx without regenerating the configuration file
rake ts:restart # Restart Sphinx
rake ts:run # Stop if running, then start a Sphinx searchd daemon using Thinking Sphinx's settings
rake ts:start # Start a Sphinx searchd daemon using Thinking Sphinx's settings
rake ts:stop # Stop Sphinx using Thinking Sphinx's settings
rake ts:version # Output the current Thinking Sphinx version
rake versioning:changelog # Show current and available Gitorious versions and details about individual versions
rake versioning:unreleased # List commits not versioned yet
[/code]

kurt's picture

I found this link:
https://groups.google.com/forum/?fromgroups#!topic/gitorious/8_wMtl0PfnQ

Hey Graziano,

I just ran into this problem myself. The forums have a posting from Nov 1, where they mention that they've changed to use a common sphinx backend, and to now refer to thinking_sphinx instead of ultrasphinx. The posting can be found here:

https://groups.google.com/forum/?fromgroups=#!topic/gitorious/HQtGmQS2OuU

Instead of calling:

bundle exec rake ultrasphinx:bootstrap

you should call:

bundle exec rake thinking_sphinx:configure
bundle exec rake thinking_sphinx:index

Hope that helps!

Regards,
Liam Chasteen

hswong3i's picture

Thank you very much, also figure out this changes during re-installation and already update with detail procedure ;-)
hswong3i's picture

Refer to https://groups.google.com/forum/?fromgroups=#!topic/gitorious/8_wMtl0PfnQ, now syntax for ultrasphinx is replace with thinking_sphinx. Please refer to above guideline changes for latest version of gitorious installtion ;-)
Graziano's picture

Hi guys,

if I run
ps aux | grep git-poller
ps aux | grep git-thinkin_sphinx

I don't see anything. Where is the problem?

Help me.

Thank you

Add new comment