June 20, 2013, Thursday, 170

Install Gitorious with Ruby 1.9 on NetBSD

From ezUnix

Jump to: navigation, search
                                    pdf_icon.png Download this article as a single PDF document 

Contents

WORK IN PROGRESS !!!

Introduction

Gitorious is an excellent open source Ruby on Rails application for managing projects which provides developers or teams of developers with a web based interface to easily handle miscellaneous tasks when working with GIT.
More information about Gitorious can be found on http://gitorious.org/about


Install software

First of all you need to define a system wide version of ruby to use on your server by editing /etc/mk.conf and adding there

RUBY_VERSION_DEFAULT=1.9

Install Ruby

# cd /usr/pkgsrc/lang/ruby ; make install clean

Install MySQL

# cd /usr/pkgsrc/databases/mysql51-server ; make install clean

Install Apache

# cd  /usr/pkgsrc/www/apache22/ ; make install clean

Install Git

 # cd /usr/pkgsrc/devel/scmgit-base ; make install clean

Install ImageMagic

Edit /etc/mk.conf and put there following:

PKG_OPTIONS.ImageMagick=jasper ghostscript djvu x11 

Then run:

# cd /usr/pkgsrc/graphics/ImageMagick ; make install clean

You may want to skip x11 if you did not chose to install the NetBSD X11 sets during installation by defining:

PKG_OPTIONS.ImageMagick=jasper ghostscript djvu -x11 

Install Ruby gem bundler package

# gem19 install --no-ri --no-rdoc bundler

Intall the Apache 2 xsendfile module

# cd /usr/pkgsrc/wip/ap2-xsendfile ; make install clean

Install Memcached

# cd /usr/pkgsrc/devel/memcached ; make install clean

Edit /etc/rc.conf and add there following:

memcached=YES

Copy scripts to automatically start services:

# cp /usr/local/share/examples/rc.d/memcached /etc/rc.d/memcached 


Install Gitorious

Gitorious is installed by fetching the source code using GIT.
Create a directory where you want to keep your website and check out the gitorious sources there:

# mkdir /web/src.ezunix.org/
# cd /web/src.ezunix.org/
# git clone git://gitorious.org/gitorious/mainline.git gitorious

Create a symlink in the PATH to the gitorious binary.

# ln -s /web/src.ezunix.org/gitorious/script/gitorious /usr/local/bin/gitorious

Install remaining gems

Now you can install the remaining gems ( still being in the root directory of gitorious i.e /web/src.ezunix.org/gitorious ):

# bundle install

This will result in output like that:

Fetching source index for http://rubygems.org/
Using rake (0.8.7) 
Installing builder (3.0.0) 
Installing chronic (0.3.0) 
Installing daemons (1.1.0) 
Installing diff-lcs (1.1.2) 
Installing gemcutter (0.6.1) 
Installing json_pure (1.5.0) 
Installing rubyforge (2.0.4) 
Installing echoe (4.3.1) 
Installing factory_girl (1.3.3) 
Installing geoip (0.8.9) 
Installing hoe (2.8.0) 
Installing mime-types (1.16) 
Installing mocha (0.9.10) 
Installing mysql (2.8.1) with native extensions 
Installing oauth (0.4.4) 
Installing paperclip (2.2.9.2) 
Installing rack (1.0.1) 
Installing rdiscount (1.3.1.1) with native extensions 
Installing riddle (1.2.2) 
Installing ruby-openid (2.1.8) 
Installing ruby-yadis (0.3.4) 
Installing shoulda (2.9.2) 
Installing state_machine (0.9.4) 
Installing stomp (1.1) 
Using bundler (1.0.10) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

Install Eventmachine

Eventmachine must be patched to use KQUEUE so we need to install it from pkgsrc:

# cd /usr/pkgsrc/devel/ruby-eventmachine/

Install Stompserver

We will use Stompserver 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 such as ActiveMQ or CoilMQ

# gem19 install --no-ri --no-rdoc stompserver

Install Sphinx and Ultrasphinx

# cd /usr/pkgsrc/wip/sphinxsearch ; make install clean
# gem19 install --no-ri --no-rdoc ultrasphinx

Install Thin

# gem19 install --no-ri --no-rdoc thin


Configuration

Create new system user

Create a new user for Gitorious, i.e _git

# groupadd git
# useradd -d /home/git -g git -m git

Create /home/git/.shrc and add there

RUBY_HOME=/usr/local
GEM_HOME=/usr/local/lib/ruby/gems/1.8/gems
PATH=$PATH:$RUBY_HOME/bin
export RUBY_HOME GEM_HOME PATH


Now make the git user owner of the Gitorious directory

# chown -R git:git /web/src.ezunix.org/gitorious


Gitorious

Go to the Gitorious`s config directory, in my case /web/src.ezunix.org/gitorious/config
Copy the examle files to correct ones:

# cp database.sample.yml  database.yml
# cp broker.yml.example broker.yml
# cp gitorious.sample.yml gitorious.yml

My broker.yml looks as follows:

adapter: stomp
deadLetterQueue: '/queue/GitoriousDeadLetter'
production:
   adapter: stomp

My database.yml looks as follows:

production:
  adapter: mysql
  database: gitorious_database
  username: database_user
  password: database_password
  host: localhost
  encoding: utf8

And finally my gitorious.yml production: production: &development

 cookie_secret: some_random_text
 repository_base_path: "/gitorious/repos"                                                                                      
 extra_html_head_data:                                                                                                         
 system_message:                                                                                                               
 gitorious_client_port: 80                                                                                                     
 gitorious_client_host: src.yazzy.net                                                                                          
 gitorious_host: src.yazzy.net                                                                                                 
 gitorious_user: git                                                                                                           
 gitorious_support_email: yazzy@yazzy.org                                                                                      
 exception_notification_emails:  yazzy@yazzy.org                                                                              
 mangle_email_addresses: true                                                                                                  
 public_mode: false                                                                                                            
 locale: en                                                                                                                    
 archive_cache_dir: "/gitorious/tarballs"
 archive_work_dir: "/gitorious/tarballs-work"
 only_site_admins_can_create_projects: false 
 hide_http_clone_urls: true
 is_gitorious_dot_org: false
 default_license: None
  
development:  
<<: *production  


MySQL

Copy the MySQL start up script to /etc/rc.d/

# cp /usr/local/share/examples/rc.d/mysqld /etc/rc.d/mysqld

Start MySQL

# /etc/rc.d/mysqld start

Run following to set password of the MySQL root user:

# /usr/local/bin/mysqladmin -u root -p password 'new-password'

There is a script distributed with MySQL that can help you lock down an installation.

# /usr/local/bin/mysql_secure_installation


Postfix

Postfix comes with NetBSD, it's in the base install of the operating system.
First edit /etc/rc.conf and add there following:

postfix=YES

Now edit /etc/postfix/main.cf
I won`t describe how to set up Postifx here. There are numerous HowTos available on the Internet describing that.


Apache

Copy the Apache start up script to /etc/rc.d/:

# cp /usr/local/share/examples/rc.d/apache /etc/rc.d/apache

Edit /etc/rc.conf and add there apache options so it will start at every boot:

apache=YES
apache_start="startssl"

Edit /usr/local/etc/httpd/httpd.conf and add there:

LoadModule xsendfile_module lib/httpd/mod_xsendfile.so                                                              
                                                                                                                    
<IfModule mod_xsendfile.c>                                                                                          
  XSendFile on                                                                                                      
</IfModule>  

And comment out the line with

Include httpd-vhosts.conf

Edit /usr/local/etc/httpd/httpd-vhosts.conf and add there something as

NameVirtualHost *:80                                                                                                             
                                                                                                                                 
<VirtualHost *:80>                                                                                                  
  ServerName src.ezunix.org                                                                                         
  ServerAdmin webmaster@yourdomain.org                                                                                   
  DocumentRoot /web/src.ezunix.org/gitorious/public                                                                  
  <Directory /web/src.ezunix.org/gitorious/public>                                                                   
    Options -MultiViews                                                                                             
    AllowOverride All                                                                                               
    Order allow,deny                                                                                                
    allow from all                                                                                                  
  </Directory>                                                                                                      
                                                                                                                    
  LogLevel debug                                                                                                    
  CustomLog     /var/log/httpd/src.ezunix.org_access.log common                                              
  ErrorLog      /var/log/httpd/src.ezunix.org_error.log                                                      
                                                                                                                    
  FileETag None                                                                                                     
  XSendFile on
#Match repository_base_path in config gitorious.yml                                                                                                      
  XSendFilePath /gitorious/repos                                                                                    
                                                                                                                    
  <Proxy balancer://thinservers>                                                                                    
    BalancerMember http://127.0.0.1:8000                                                                            
    BalancerMember http://127.0.0.1:8001                                                                            
    BalancerMember http://127.0.0.1:8002                                                                            
  </Proxy>                                                                                                          
                                                                                                                    
RewriteEngine On                                                                                                    
                                                                                                                    
# Redirect all non-static requests to thin                                                                          
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f                                                                
RewriteRule ^/(.*)$ balancer://thinservers%{REQUEST_URI} [P,QSA,L]                                                  
                                                                                                                    
ProxyPass / balancer://thinservers/                                                                                 
ProxyPassReverse / balancer://thinservers/                                                                          
ProxyPreserveHost on                                                                                                
                                                                                                                    
<Proxy *>                                                                                                           
Order deny,allow                                                                                                    
Allow from all                                                                                                      
</Proxy>                                                                                                            
                                                                                              
</VirtualHost> 

And the same for SSL, edit /usr/local/etc/httpd/httpd-ssl.conf and add there something as

AddType application/x-pkcs7-crl    .crl
SSLPassPhraseDialog  builtin
SSLSessionCache        "shmcb:/var/run/ssl_scache(512000)"
SSLSessionCacheTimeout  300
SSLMutex  "file:/var/run/ssl_mutex"
  
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
  
Listen 0.0.0.0:443
NameVirtualHost *:443
 
<VirtualHost *:443>
 ServerName src.ezunix.org
 ServerAdmin webmaster@yourdomain.org
 DocumentRoot /web/src.ezunix.org/gitorious/public

#  LogLevel debug
 ErrorLog "/var/log/httpd/ssl_error.log"
 TransferLog "/var/log/httpd/ssl_access.log"
 CustomLog "/var/log/httpd/ssl_request.log" \
         "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

 FileETag None
 XSendFile on
 XSendFilePath /usr/gitorious/repos/
 <Proxy balancer://thinservers>
   BalancerMember http://127.0.0.1:8000
   BalancerMember http://127.0.0.1:8001
   BalancerMember http://127.0.0.1:8002
 </Proxy>

 RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
 RewriteRule ^/(.*)$ balancer://thinservers%{REQUEST_URI} [P,QSA,L]

 ProxyPass / balancer://thinservers/
 ProxyPassReverse / balancer://thinservers/
 ProxyPreserveHost on
 <Proxy *>
 Order deny,allow
 Allow from all
 </Proxy>  
 RequestHeader set X_FORWARDED_PROTO 'https'
 SSLEngine on
 SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
 SSLCertificateFile /usr/local/etc/httpd/ssl.crt/server.crt
 SSLCertificateKeyFile /usr/local/etc/httpd/ssl.key/server.key

 BrowserMatch ".*MSIE.*" \
        nokeepalive ssl-unclean-shutdown \
        downgrade-1.0 force-response-1.0
</VirtualHost>

NOTE: Do not call your host git.something.tld since the git name is reserved in Gitorious.
See http://gitorious.org/gitorious/pages/ErrorMessages for further explanation


Thin

Create initial config file in /usr/local/etc/gitorious.yml :

# thin config -C /usr/local/etc/gitorious.yml -c /web/src.ezunix.org/gitorious --servers 3 -p 8000 -a 127.0.0.1 -e production -u _git -g _git -d

You can see what all the options mean by running just the thin command.

To start Thin automatically at boot edit /etc/rc.local and add there something like this:

if [ -d /web/src.ezunix.org/gitorious ]; then
       thin -C /usr/local/etc/gitorious.yml start
fi


Create MySQL Database

  • Create an initial MySQL database for Gitorious. Login as root using the MySQL CLI:
# mysql -u root -p
   Enter password:
  • Then type following in the CLI
mysql> GRANT ALL ON gitorious_db.* TO gitorious_user@'localhost' IDENTIFIED BY 'secret_password;

Where gitorious_db is the database Gitorious will use, gitorious_use is the user it will connect as and secret_password is the password of that MySQL user.

  • With all the software installed we can create an initial database (still being in the gitorious directory):
# rake19 db:migrate RAILS_ENV=production

To update the database run:

# rake19 ultrasphinx:configure RAILS_ENV=production

This command will update /web/src.ezunix.org/gitorious/config/ultrasphinx/production.conf and define sql_host, sql_user, sql_pass and sql_db so they would match definitions in database.yml


Create Admin user

This will be done using the Gitorious CLI. Following command will create a user with user name admin.

# cd /web/src.ezunix.org/gitorious/script/
# env RAILS_ENV=production ruby ./create_admin

This should result in something like that:

Type in Administrator's e-mail: 
email_address@domain.tld
Type in Administrator's password: 
your_password
Admin user created successfully.


Now run following to activate the admin user:
  1. env RAILS_ENV=production ruby ./console production
>> user = User.first
>> user.login = "marcin" # Change to your desired username
>> user.activate
>> user.accept_terms
>> user.save

Press CTRL + d to leave the CLI.


Links

http://cjohansen.no/en/ruby/setting_up_gitorious_on_your_own_server
http://www.silly-science.co.uk/2010/12/12/installing-gitorious-on-ubuntu-10-04-howto/


That's all folks.
Marcin



You are not allowed to post comments. Login or register first.


Talk:Install Gitorious with Ruby 1.9 on NetBSD