Table of Contents
Configurare Gitorious 3.0.x su un proprio server Slackware
Questo documento illustra come istallare su una SLackware il server Gitorious version 3.0 La documentazione iniziale è stata presa da questo articolo e da documento ufficiale di installazione. Questo documento spiega come è configurato il sito ufficiale. Per la versione 3.0.x esiste uno script di installazione che si può recuperare da ufficiale per CentOS Gitorious è un'applicazione Rails open source per gestire progetti: repository Git, wikis, timeline ed altro. Non uguale, ma non molto diverso da GitHub. Il fatto di essere open source significa che si può installare un proprio server Gitorious. Questo articolo spiega come installare la versione 3.0.x di Gitorious su un server con Slackware 14.0 (current). Gitorious 3 usa Rails 3.x e Ruby 1.9.3.
Installare le Dipendenze
Slackware è già fornita di parte del software necessario:
Ruby 1.9.3_p484
Git 1.8.4
Httpd Apache 2.4.6
MariaDb 5.5.32
Ruby
Niente da dire tranne per il fatto che la cartella di installazione delle gemme si chiama 1.9.1 .
Sphinx e Ultrasphinx
Per abilitare le ricerche su Gitorious, è necessario installare Sphinx
. Prendiamolo e installiamolo da SlackBuild.org version 2.0.5
sbopkg -i sphinx
Redis
Gitorious usa il framework ActiveMessaging
per mandare messaggi sulle procedure in background che non vengono processate dall'applicazione web come aggioungere chiavi SSH e creare progetti e repository. Gitorious 3 consiglia Redis
per gestire i messaggi. Anche questo preso da SlackBuilds.org versione 2.6.5
sbopkg -i redis chmod +x /etc/rc.d/rc.redis nano /etc/redis.conf /etc/rc.d/rc.redis start
Memcached
Installare Memcached
non è necessario ma è utile in un ambiente di produzione. Recuperiamo la versione 1.4.13 da SlackBuilds.org insieme alla dipendenza libevent
2.0.10
sbopkg -i libevent sbopkg -i memcached
Postgresql
Installare sempre da slackbuilds.org anche il database Postgresql 9.3.4
sbopkg -i postgresql
Ottenere il codice Gitorious
Innanzitutto creiamo l'utente e il gruppo per eseguire Gitorious (controllate questo file per assegnare un id di gruppo libero http://slackbuilds.org/uid_gid.txt)
groupadd -g 264 gitorious adduser -u 264 -g 264 -c "Gitorious" -d /var/www/git.gperon.org/gitorious -s /bin/sh gitorious
Adesso creiamo la directory base per Gitorious
mkdir -p /var/www/git.gperon.org chown gitorious:gitorious /var/www/git.gperon.org chmod -R g+sw /var/www/git.gperon.org
e scarichiamo il software con git e passiamo al branch next
dove si trova l'anteprima della version 3 di Gitorious
git clone git://gitorious.org/gitorious/mainline.git gitorious git submodule init git submodule update ln -s /var/www/git.gperon.org/gitorious/script/gitorious /usr/local/bin/gitorious cd gitorious/ mkdir -p tmp/pids chmod ug+x script/* chmod -R g+w config/ log/ public/ tmp/
Le cartelle /var/www/git.myserver.com/conf
e /var/www/git.myserver.com/log
sono usate dalla configurazione e il log di Apache.
Installare gli eseguibili
Gitorious fornisce alcuni script per eseguire ma occorre adattarli a Slackware, queste le mie versioni
...
Gitorious ships with ready to use git-ultrasphinx and git-daemon scripts. Be aware that the git-daemon script has hardcoded paths to both Ruby Enterprise Edition and Gitorious. Pop open git-daemon and set correct paths to the Ruby you want to use (stick with REE if you installed it earlier) and your Gitorious installation. These are the lines you need to see (lines 16 and 18 at the time of writing):
# in /var/www/git.myserver.com/gitorious/doc/templates/ubuntu/git-daemon GIT_DAEMON="/opt/ruby-enterprise/bin/ruby \ /var/www/git.myserver.com/gitorious/script/git-daemon -d" PID_FILE=/var/www/git.myserver.com/gitorious/log/git-daemon.pid
It is tempting to “correct” the pid file location from log to tmp/pids. Resist this temptation. Doing so will cause you major frustration as you discover that indeed script/git-daemon (which is run by this script) creates the pid file in log anyway, so changing the PID_FILE will only cause the script to fail to find the pid file, thus reporting failures. Don't go there.
The git-ultrasphinx script has paths you should review, too, as seen here:
GITORIOUS_HOME="/var/www/gitorious" RETVAL=0 START_CMD="cd $GITORIOUS_HOME && rake ultrasphinx:daemon:start RAILS_ENV=production" STOP_CMD="cd $GITORIOUS_HOME && rake ultrasphinx:daemon:stop RAILS_ENV=production" RESTART_CMD="cd $GITORIOUS_HOME && rake ultrasphinx:daemon:restart RAILS_ENV=production" STATUS_CMD="cd $GITORIOUS_HOME && rake ultrasphinx:daemon:status RAILS_ENV=production" LOCK_FILE=/var/lock/git-ultrasphinx PID_FILE=$GITORIOUS_HOME/db/sphinx/log/searchd.pid
Fix the paths, then copy the scripts to the right place
sudo ln -s \ /var/www/git.myserver.com/gitorious/doc/templates/ubuntu/git-ultrasphinx \ /etc/init.d/git-ultrasphinx sudo ln -s \ /var/www/git.myserver.com/gitorious/doc/templates/ubuntu/git-daemon \ /etc/init.d/git-daemon
Now install the services
sudo chmod +x /etc/init.d/git-ultrasphinx sudo chmod +x /etc/init.d/git-daemon sudo update-rc.d -f git-daemon start 99 2 3 4 5 . sudo update-rc.d -f git-ultrasphinx start 99 2 3 4 5 .
Recuperare le Gemme
Gitorious usa una gran quantità di gemme che però si possono gestire facilmente con Bundler
. Si rimuova la gemma SystemTime da gitorious/Gemfile
perchè non serve con ruby 1.9.x
gem install -b --no-ri --no-rdoc bundler cd /var/www/git.gperon.org/gitorious && bundle install bundle update
Questo l'output
bundle install gem list *** LOCAL GEMS *** actionmailer (3.2.11) actionpack (3.2.11) activemodel (3.2.11) activerecord (3.2.11) activeresource (3.2.11) activesupport (3.2.11) acts-as-taggable-on (2.3.3) addressable (2.2.8) arel (3.0.2) builder (3.0.4) bundle (0.0.1) bundler (1.2.3) capillary (1.0.2) capybara (1.0.1) childprocess (0.3.6) cocaine (0.4.2) daemons (1.1.0) diff-lcs (1.1.2) erubis (2.7.0) eventmachine (1.0.0) exception_notification (3.0.0) factory_girl (2.6.4) factory_girl_rails (1.7.0) faraday (0.8.4) faraday_middleware (0.9.0) ffi (1.0.11) foreman (0.60.2) geoip (0.8.9) gitorious_openid_auth (1.1.0) hashie (1.2.0) highline (1.6.15) hike (1.2.1) http_parser.rb (0.5.3) httparty (0.9.0) i18n (0.6.1) journey (1.0.4) json (1.7.6) just_paginate (0.0.6) kgio (2.7.4) launchy (2.0.5) libwebsocket (0.1.5) mail (2.4.4) memcache-client (1.8.5) mime-types (1.19) minitest (4.2.0) mocha (0.9.10) multi_json (1.5.0) multi_xml (0.5.1) multipart-post (1.1.5) mysql2 (0.3.11) net-ldap (0.3.1) nokogiri (1.5.5) oauth (0.4.4) paperclip (2.8.0) pg (0.14.1) polyglot (0.3.3) proxymachine (1.2.4) rack (1.4.3) rack-cache (1.2) rack-openid (1.3.1) rack-protection (1.3.2) rack-ssl (1.3.2) rack-test (0.6.2) rails (3.2.11) rails_autolink (1.0.9) railties (3.2.11) raindrops (0.10.0) rake (0.9.6) rdiscount (1.6.8) rdoc (3.12) redis (3.0.2) redis-namespace (1.2.1) resque (1.23.0) riddle (1.5.3) ruby-openid (2.2.2) ruby-yadis (0.3.4) rubyzip (0.9.9) selenium-webdriver (2.26.0) shoulda (3.3.2) shoulda-context (1.0.1) shoulda-matchers (1.4.1) simple_oauth (0.1.9) sinatra (1.3.3) sprockets (2.2.2) state_machine (1.1.2) thin (1.5.0) thinking-sphinx (2.0.13) thor (0.16.0) tilt (1.3.3) tinder (1.9.1) treetop (1.4.12) twitter-stream (0.1.16) tzinfo (0.3.35) unicorn (4.3.1) vegas (0.1.11) will_paginate (3.0.3) xpath (0.1.4)
Altre gemme
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 gem install -b --no-ri --no-rdoc -v 1.3.1.1 rdiscount gem install -b --no-ri --no-rdoc -v 1.1 stomp
Per vedere la lista delle gemme e per rimuovere una gemma o tutte le gemme
gem list gem uninstall activesupport -v 3.2.8 gem list | cut -d" " -f1 | xargs gem uninstall -aIx
Creiamo la cartella per ospitare i repository git
mkdir -p /var/gitorious/{repositories,tarballs,tarball-work} chown -R gitorious:gitorious /var/gitorious
Adesso facciamo login con l'utente gitorious per alcuni lavori.Quando qualcuno tenta il push
sul repositiory Gitorious, l'utente viene ricercato nel file ~/.ssh/authorized_keys
. Se l'utente è presente, la connessione è gestita dal demone git-daemon
, creiamo allora questo file
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 - gitorious mkdir ~/.ssh chmod 700 ~/.ssh touch ~/.ssh/authorized_keys
Configuriamo il database, prima facciamo partire il servizio
chmod +x /etc/rc.d/rc.mysqld mysql_install_db --user=mysql chown -R mysql.mysql /var/lib/mysql /etc/rc.d/rc.mysqld start /usr/bin/mysqladmin -u root password '<new-password>' /usr/bin/mysqladmin -u root -h <hostname> password '<new-password>' cd /var/www/git.myserver.com/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
Modifichiamo il file gitorious.yml
aggiungendo una chiave generata con
apg -m 64
In particolare prestare attenzione alle variabili
gitorious_host: git.gperon.org
repository_base_path: “/var/gitorious/repositories”
archive_work_dir: “/var/gitorious/tarballs-work”
cookie_secret:EmvuehacaipZegCiWagoncotAs(…)
gitorious_user: gitorious
Il valore scritto in gitorious_host
deve essere presente nel file /etc/hosts
. Questo è un esempio di gitorious.yml
Il file config/broker.yml
non dovrebbe avere bisogno di modifiche
Modificare invece il file config/database.yml
secondo le impostazioni che seguono
mysql -uroot -p create database gitorious_production; create database gitorious_test; create database gitorious_development; grant all privileges on gitorious.* to YOURUSER@localhost \ identified by 'YOURPASSWORD'; grant all privileges on gitorious_test.* to YOURUSER@localhost; grant all privileges on gitorious_dev.* to YOURUSER@localhost;
Se si usa nel file config/database.yml
un utente con diritti di creazione database come root
si può usare il comando
bundle exec rake db:drop db:create db:migrate
E' necessario usare bundle exec
perché ruby installa di default rake 0.9.2.2
ma Gitorious necessita di rake 0.8.7
. Per essere sicuri che tutto funzioni è meglio specificare sempre l'ambiente su cui si lavora, ad esempio per migrare il database
rake db:setup RAILS_ENV=production
Aggiungiamo ora l'amministratore del sito Gitorious
cd /var/www/git.gperon.org/gitorious env RAILS_ENV=production ruby ./bin/create-user script/console production > user = User.first > user.login = "christian" # Change to your desired username > user.activate > user.accept_terms > user.save
You'll be prompted for credentials, and the user will be created and automagically activated. You then activate the user by hand by using script/console. Alternately, you could check your email and activate. Get Ultrasphinx running cd /var/www/git.myserver.com/gitorious rake ultrasphinx:bootstrap RAILS_ENV=production
If you want to try search for development, change the RAILS_ENV above. Permissions
The devil's in the details. 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 to achieve this is to run all the services using the git user: cd /var/www/git.myserver.com/gitorious sudo chown -R git:gitorious config/environment.rb script/poller log tmp sudo chmod -R g+w config/environment.rb script/poller log tmp sudo 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: sudo /etc/init.d/activemq start sudo env RAILS_ENV=production /etc/init.d/git-daemon start su git -c \
"cd /var/www/git.myserver.com/gitorious && \ env RAILS_ENV=production script/poller run"
Later, you can use script/poller start to run the poller in the background. For debugging, it's better to be able to follow the output. The gitorious script runs with the production environment as default, so we'll start the application in production mode. If you don't, the daemon won't find the app and pushing won't work (i.e., gitorious_client_host and gitorious_client_port needs to point to a running Gitorious instance, or the git-daemon won't be able to do it's job). Now, the exciting moment: su git -c \
"cd /var/www/git.myserver.com/gitorious && script/server -e production"
This should start the server successfully. Now head over to http://git.local:3000, and with any bit of luck, you didn't miss a detail and the Gitorious splash screen will great you. Log in with the user you created earlier. Head over to http://git.local:3000/~christian/keys/new (substitute your username). Now, in a shell get your public key: cat ~/.ssh/id_rsa.pub
Copy it and paste into the textarea. If you don't have a public key, generate one: ssh-keygen
Pasting in the key and saving it should cause Gitorious to do work via the message server. Wait a moment and refresh the page. Your key should be ready to use. Now, head over to http://git.local:3000/projects/new to create a project. Add a repository in the next step, call it “mainline”.
Now, get back into your shell, create a mumbo-jumbo git repo: mkdir -p ~/projects/mumbo-jumbo cd ~/projects/mumbo-jumbo touch .gitignore git init git add . git commit -m “Initial commit” git remote add origin git@git.local:/mumbo-jumbo/mainline.git git push origin master
If this works, you're done! Setup Ultrasphinx indexing cronjob
You might want to run the Ultrasphinx indexing cronjob. Type in crontab -e and put this line in there: * */1 * * * cd /var/www/git.myserver.com/gitorious && rake ultrasphinx:index RAILS_ENV=production Setup logrotate
Create /etc/logrotate.d/gitorious: cd /var/www/git.myserver.com/gitorious sudo cp doc/templates/ubuntu/gitorious-logrotate /etc/logrotate.d/gitorious sudo chmod +x /etc/logrotate.d/gitorious
The logrotate script template assumes that Gitorious lives in /var/www/gitorious. Update to match your path. Following this guide, that'd look like this: /var/www/git.myserver.com/gitorious/log/*log {
missingok notifempty sharedscripts postrotate /etc/init.d/git-daemon restart > /dev/null 2>/dev/null || true /etc/init.d/git-ultrasphinx restart > /dev/null 2>/dev/null || true /bin/touch /var/www/git.myserver.com/gitorious/tmp/restart.txt > /dev/null 2>/dev/null || true
endscript } Wrapping up
Now you can set up passenger - don't worry, at this point deploying on Passenger is just like deploying any other Rails application. Add Capistrano to the mix if you want to keep working on your Gitorious installation locally - picking up new commits from the core team, adding your own tweaks and so on - and deploy updates every now and then. I have previously written a thorough guide on Capistrano and Passenger, but here are the highlights (for Passenger, this setup does not account for Capistrano). Install Passenger sudo gem install passenger sudo passenger-install-apache2-module
The installer will instruct you to create /etc/apache2/mods-available/passenger.load and /etc/apache2/mods-available/passenger.conf. Enable some Apache modules: sudo a2enmod rewrite sudo a2enmod deflate sudo a2enmod passenger sudo a2enmod expires
Create /var/www/git.myserver.com/conf/vhost.conf with: <VirtualHost *>
<Directory /var/www/git.myserver.com/gitorious/public> Options FollowSymLinks AllowOverride None Order allow,deny Allow from All </Directory>
DocumentRoot /var/www/git.myserver.com/gitorious/public ServerName git.myserver.com
ErrorLog /var/www/git.myserver.com/log/error.log CustomLog /var/www/git.myserver.com/log/access.log combined
# Gzip/Deflate # http://fluxura.com/2006/5/19/apache-for-static-and-mongrel-for-rails-with-mod_deflate-and-capistrano-support AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/x-javascript BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Far future expires date <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> ExpiresActive On ExpiresDefault "access plus 1 year" </FilesMatch>
# No Etags FileETag None
RewriteEngine On
# Check for maintenance file and redirect all requests RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f RewriteCond %{SCRIPT_FILENAME} !maintenance.html RewriteRule ^.*$ /system/maintenance.html [L]
</VirtualHost> Symlink site sudo ln -s /var/www/git.myserver.com/conf/vhost.conf \
/etc/apache2/sites-available/git.myserver.com
sudo a2ensite git.myserver.com Restart Apache sudo /etc/init.d/apache2 restart
A word of warning: If you have SSL enabled on your Apache, Gitorious will want to use it, so if that's the case, set up a VirtualHost for port 443.
That's “all there is to it”. If you had any trouble setting up Gitorious using this guide, please report back, I'd love to help and get this guide correct. As ar as I know, a .deb package is on it's way, which will make this whole process alot easier. In any case I'd still recommend you to go through this setup manually atleast once because it will make familiarize with the Gitorious architecture in a way a prepackaged install can never to.
I want to extend huge thanks to Johan for creating such an awesome project, and to Marius and all the other contributors for continuously improving it. Also, my deepest gratitude for all the help both Marius and Johan provided while I was compiling this guide.
Thanks alot to August for correcting a few minor mistakes while using this guide for Ubuntu JeOS 8.04.
Good luck, and do share your experiences in the comments!
I'm sorry to tell you that I am currently unable to handle the insane amounts of spam hitting this post, nor have I the time to fix a spam filter for eZ Publish right now, so I am closing down comments. Check out the official Gitorious mailing list/Google group if you need help.
ExpiresActive On ExpiresDefault mainlinemainline