Gitorious on Ubuntu Natty
Installing gitorious wasn't as straightforward as I hoped, so here's another howto. It's a slightly modified and updated version of Christian Johansen's blog.
The main problem seemed to be Ruby versions, so my advice is to stick to the versions I mention.
I did not install the main version of Gitorious, but a fork called "yousource", allowing me to make projects private, only readable by project contributors.
Most commands assume you're the root user.
Install required packages
apt-get install git-core git-svn apg build-essential libpcre3 libpcre3-dev postfix make zlib1g zlib1g-dev ssh libreadline5-dev apt-get install libonig-dev libyaml-dev geoip-bin libgeoip-dev libgeoip1 apt-get install imagemagick libmagickwand-dev
Note: this will install postfix as the mail server, if you want to use sendmail that's fine too.
Install Ruby
As said, getting the Ruby versions right seemed to be the main problem when installing Gitorious. I ended up with Ruby Enterprise Edition version 1.8.7 (the latest at the time of writing). You can download the .deb files from http://www.rubyenterpriseedition.com/
Install Ruby Enterprise Edition:
dpkg -i ruby-enterprise_1.8.7-2011.03_amd64_ubuntu10.04.deb
Append these lines to the bottom of to /etc/profile:
export LD_LIBRARY_PATH="/usr/local/lib" export LDFLAGS="-L/usr/local/lib -Wl,-rpath,/usr/local/lib"
Prepend /usr/local/lib to /etc/ld.so.conf so the file reads:
/usr/local/lib include ld.so.conf.d/*.conf
Then run ldconfig.
Install RubyGems
Get the source of RubyGems 1.4.2 from http://rubyforge.org/frs/?group_id=126 and build:
cd ~/ mkdir src cd src wget http://rubyforge.org/frs/download.php/73882/rubygems-1.4.2.tgz tar zxvf rubygems-1.4.2.tgz cd rubygems-1.4.2 ruby setup.rb
Install MySQL
apt-get install libmysqlclient16 mysql-server-5.1 mysql-client-5.1
Install Sphinx
If you want to be able to search your Gitorious, you'll need Sphinx.
cd ~/src wget http://sphinxsearch.com/files/sphinx-0.9.9.tar.gz tar xvfz sphinx-0.9.9.tar.gz cd sphinx-0.9.9 ./configure make && make install
Install ActiveMQ
Gitorious uses the ActiveMessaging framework to talk to a message queue that handles most of it's background processing that is out of scope for a simple web request. Such tasks include adding SSH keys and creating projects and repositories. You should be able to use a variety of messaging systems, but we'll setup ActiveMQ and the Stomp connector, as is recommended by the Gitorious documentation.
You'll find the latest ActiveMQ here. At the time of writing, the latest release is 5.5.0.
ActiveMQ requires java to be installed. I use the Sun Oracle version, but openJDK should work too. The Sun JDK can be installed through Ubuntu's partner repository. Make sure it's added in /etc/apt/source.list:
deb http://archive.canonical.com/ubuntu natty partner
And install sun-java6-jdk:
apt-get install sun-java6-jdk
Install other packages required by ActiveMQ:
apt-get install uuid uuid-dev
And install ActiveMQ:
cd ~/src/ wget http://apache.belnet.be//activemq/apache-activemq/5.5.0/apache-activemq-5.5.0-bin.tar.gz tar zxvf apache-activemq-5.5.0-bin.tar.gz -C /usr/local/ echo "export ACTIVEMQ_HOME=/usr/local/apache-activemq-5.5.0" >> /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.0/data
Turn off the default multicasting activemq does, or other brokers on the same network will receive your queue items. Edit /usr/local/apache-activemq-5.5.0/conf/activemq.xml, find the transportConnectors block and make it look like this:
<transportConnectors>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613"/>
</transportConnectors>
Then get this handy init script:
cd ~/src wget http://selene.lacerta.be/downloads/activemq mv activemq /etc/init.d/activemq chmod +x /etc/init.d/activemq
And add it to the default run levels if you want it to boot with your machine:
update-rc.d activemq defaults
Memcache
Installing memcache is not strictly required to run Gitorious, but it's highly recommended for performance:
apt-get install memcached update-rc.d memcached defaults
Get the Gitorious/yousource source code
As mentioned, I installed a fork of Gitorious, named yousource. More specifically the <code>feat/private</code> branch of yousource.
Create a base directory (I use /var/gitorious) to hold Gitorious and <code>git</code> the source code:
cd /var/ git clone -b feat/private git://gitorious.org/+verso/gitorious/yousource.git gitorious cd gitorious
If you prefer the Gitorious main source code, use git clone git://gitorious.org/gitorious/mainline.git instead.
When using yousource, we also have to apply a fix to gitorious that wasn't included in the yousource fork (yet?):
cd gitorious/ git checkout -b merge-requests/118 git pull git://gitorious.org/gitorious/mainline.git refs/merge-requests/118
We have to create a folder for the pid files and correct some permissions:
rm public/.htaccess mkdir -p tmp/pids sudo chmod ug+x script/* sudo chmod -R g+w config/ log/ public/ tmp/
Install the services
Gitorious ships with ready to use git-ultrasphinx and git-daemon scripts, but the paths to ruby and gitorious are hard coded, so we'll have to correct them.
Edit gdoc/templates/ubuntu/git-daemon, and set the correct paths:
GIT_DAEMON="/usr/local/bin/ruby \
/var/gitorious/script/git-daemon -d"
PID_FILE=/var/gitorious/log/git-daemon.pid
And doc/templates/ubuntu/git-ultrasphinx:
START_CMD="cd /var/gitorious/ && rake ultrasphinx:daemon:start RAILS_ENV=production" STOP_CMD="cd /var/gitorious/ && rake ultrasphinx:daemon:stop RAILS_ENV=production" RESTART_CMD="cd /var/gitorious/ && rake ultrasphinx:daemon:restart RAILS_ENV=production" STATUS_CMD="cd /var/gitorious/ && rake ultrasphinx:daemon:status RAILS_ENV=production" LOCK_FILE=/var/lock/git-ultrasphinx PID_FILE=/var/gitorious/db/sphinx/log/searchd.pid
Copy/link the scripts to the right place:
ln -s /var/gitorious/doc/templates/ubuntu/git-ultrasphinx /etc/init.d/git-ultrasphinx ln -s /var/gitorious/doc/templates/ubuntu/git-daemon /etc/init.d/git-daemon
And install them
chmod +x /etc/init.d/git-ultrasphinx chmod +x /etc/init.d/git-daemon update-rc.d -f git-daemon start 99 2 3 4 5 . update-rc.d -f git-ultrasphinx start 99 2 3 4 5 .
Install Ruby Gems
Yousource doesn't come with the Gemfiles required by Gitorious, so add them:
cd /var/gitorious wget http://gitorious.org/gitorious/mainline/blobs/raw/master/Gemfile wget http://gitorious.org/gitorious/mainline/blobs/raw/master/Gemfile.lock
Now ready to install the gems:
gem install bundler bundle install gem install mongrel
The i18n isn't compatible with this Yousource tho, so uninstall it again:
gem uninstall i18n
Create GIT repository home directory
I store the repositories in /var/git and they are owned by the user git:
adduser --home /var/git git mkdir /var/git mkdir /var/git/repositories mkdir /var/git/tarballs mkdir /var/git/tarball-work chown -R git:git /var/git
Now, we need to login as the git user to do some work. 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 ssh connection is handled by the git-daemon process. We have to create this file, but Gitorious will maintain it for us.
su - git mkdir ~/.ssh chmod 700 ~/.ssh touch ~/.ssh/authorized_keys
Append the following to ~/.bashrc (as git user):
# User specific aliases and functions export RUBY_HOME=/usr/local export GEM_HOME=$RUBY_HOME/lib/ruby/gems/1.8/gems
Configure Gitorious
Next up we'll configure Gitorious and create the database. We need to configure the database, the broker (for the messaging system) and Gitorious itself. If you're still logged in as 'git', log back out and go back to the gitorious home directory (/var/gitorious).
cd /var/gitorious cp config/database.sample.yml config/database.yml cp config/gitorious.sample.yml config/gitorious.yml cp config/broker.yml.example config/broker.yml
Now we'll configure each file. First open confige/gitorious.yml in an editor.
I'm only interested in a production environment, so remove the entries for test and development, and set the parameters for the production environment. It should look like this:
production: cookie_secret: <long_random_string_of_at_least_32_characters> repository_base_path: "/var/git/repositories" extra_html_head_data: system_message: gitorious_client_port: 3000 gitorious_client_host: <hostname> gitorious_host: <hostname> gitorious_user: git gitorious_support_email: <email addresss> exception_notification_emails: <email address> mangle_email_addresses: true public_mode: false locale: en archive_cache_dir: "/var/git/tarballs" archive_work_dir: "/var/git/tarball-work" only_site_admins_can_create_projects: false hide_http_clone_urls: false is_gitorious_dot_org: false
Next up is the database configuration.
First create the database:
mysql -uroot -p > create database gitorious; > grant all privileges on gitorious.* to gitorious@localhost identified by 'YOURPASSWORD'; > exit
And edit the file config/database.yml so it matches the database we just created. Again, I'm only interested in a production environment. If you want more environments you'll have to create multiple databases.
Time to build the database:
rake db:setup RAILS_ENV=production
If you see errors like "undefined local variable or method", it means there is a Ruby version problem. You should either install the versions I mentioned, or try fixing it by editing some Ruby files (Rakefile, script/server, config/environment.rb, others?).
require File.join(File.dirname(__FILE__), 'boot')
hould be preceded with:
require 'thread'
Time to add a first user:
env RAILS_ENV=production ruby script/create_admin script/console production > user = User.first > user.login = "<username>" > user.activate > user.accept_terms > user.save
Start the Ultrasphinx daemon
cd /var/gitorious rake ultrasphinx:bootstrap RAILS_ENV=production
Set permissions
Before running Gitorious, you need to get your permissions right.
- Whatever user owns config/environment.rb is the user who'll own the Rails process under Passenger (i.e., not necessarily the Apache user)
- The user who runs the application needs full access to the git repositories
- The git-daemon process needs full access to the git repositories
- The script/poller process needs full access to the git repositories
The easiest way is to make sure everything is owned by the git user and start the daemons with that user. Alternatively you could create an extra group that owns the gitorious files, which is probably a more secure setup. However, since this is not a linux manual, this is not covered here.
cd /var/gitorious chgrp -R git /var/gitorious chown -R git config/environment.rb script/poller log tmp chmod -R g+w config/environment.rb script/poller log tmp chmod ug+x script/poller
Don't forget log and tmp! If not, Gitorious will break trying to create pids and logs.
Now, run all the services:
/etc/init.d/activemq start
env RAILS_ENV=production /etc/init.d/git-daemon start
su git -c \
"cd /var/gitorious && \
env RAILS_ENV=production script/poller run"
If the script/poller run works fine, you can kill it and start it again with start instead of run so it would go to the background.
Now start the gitorious server:
su git -c \ "cd /var/gitorious && script/server -e production"
Again, if this looks fine, you can kill it and start it again with a -d switch so it would go to the background:
su git -c \ "cd /var/gitorious && script/server -e production -d"
This should start the server successfully. Now head over to http://<hostname>:3000, and with any bit of luck, you didn't miss a detail and the Gitorious splash screen will greet you. Log in with the user you created earlier.

