I recently installed Gitorious on our centos 5.5 development machine and written down this recipe of the steps I took to acomplish it.

this is not a complete guide to installing gitorious and some of the steps here may be different depending on the os version, installed packages etc.

you should consult other documents available on the web, I followed these guides and a lot of googling and gitorious google group, read them for more details on the various components.

http://cjohansen.no/en/ruby/setting_up_gitorious_on_your_own_server
http://gitorious.com/gitorious/mainline/blobs/master/doc/recipes/install...

 

Most of the scripts I use are taken from gitorious doc/recipes/ with my changes, check to see there are no major changes in future releases of gitorious. the scripts are attched here as a zip file. Please register to view and download attached zip.

 

My installation assumes there is ruby 1.8 installed on the machine and we want to use ruby 1.9 with gitorious, so we'll install ruby 1.9 to a non standard location and we have to remember that all the way.

 

http clones are disabled, it requires a domain name with no subdomain, like http://tikalk.com, gitorious uses a subdomain 'git.' for http clones.

 

We will use Monit to control and monitor the various daemons, its the last section of this doc.

 

This installation procedure is for centos 5.5, it should be identical on other versions except for the package installations.
you should check every command before executing it, this is not a script.

 

note that if any step during the process fails you end up with a non working gitorious and a hard time finding the problems.

 

I do not explain how to set up gitorious for ssl and this installation disables ssl.

 

choose a name for the site, we're using git.tikalk.com.
Gitorious needs to be able to resolve its site name through dns, If installing on a vm or on a home network with no dns, add an alias in the hosts file on the machine where gitorious is installed. and also on your client machine.
for example:
192.168.1.107    git.tikalk.com

 

lets start..

All the following is executed with root privileges, and as 'git' user where noted.

 

Install a whole banch of packages

install rpmforge
http://wiki.centos.org/AdditionalResources/Repositories/RPMForge?action=...

install epel repository
http://fedoraproject.org/wiki/EPEL/FAQ#How_can_I_install_the_packages_fr...

install yum priorities
http://wiki.centos.org/PackageManagement/Yum/Priorities

in my setup epel and rpmforge have the same priority.
 

yum update
yum groupinstall "Development tools"

because I started with a clean os I just took this list from yum log. some of these may not be necessary because I installed some tools to work with like screen.

yum install imake pyspi autoconf automake libstdc++ libtool automake17 pstack redhat-rpm-config automake14 automake15\
automake16 apr neon apr-util libtermcap-devel glibc-devel keyutils-libs-devel libsepol-devel libselinux-devel\
e2fsprogs-devel krb5-devel curl-devel cyrus-sasl-devel apr-devel openldap-devel expat-devel db4-devel apr-util-devel\
httpd-devel sphinx bzip2-devel libtiff-devel lcms-devel ghostscript-devel libXau-devel  uuid uuid-devel memcached\
libntlm libntlm libgsasl libgsasl-devel libgpg-error-devel libgcrypt-devel gnutls-devel libidn-devel mod_xsendfile\
distcache apg geoip httpd sqlite sqlite-devel httpd-devel libjpeg libjpeg-devel readline-devel curl-devel pcre pcre-devel\
zlib zlib-devel openssl openssl-devel libyaml libyaml-devel gcc gcc-c++ autoconf automake readline readline-devel\
glibc-devel openssl openssl-devel pcre pcre-devel kernel-devel kernel-headers glibc-common glibc-headers sqlite-devel\
ruby-sqlite3 dspam-sqlite3 java-1.6.0-openjdk java-1.6.0-openjdk-devel aspell aspell-en


yum install git git-svn
 
Install some packages from source

gitorious currently works with those version, you may want to try newer versions.

cd /usr/src
	
wget 'http://www.geocities.jp/kosako3/oniguruma/archive/onig-5.9.1.tar.gz'
tar xvfz onig-5.9.1.tar.gz 
cd onig-5.9.1
./configure 
make && make install
cd ..

yum remove ImageMagick
wget 'ftp://ftp.imagemagick.net/pub/ImageMagick/ImageMagick-6.5.9-10.tar.gz'
tar xvzf ImageMagick-6.5.9-10.tar.gz
cd ImageMagick-6.5.9-10
./configure --prefix /usr 
make && make install

 

note the /usr prefix in ImageMagick, or install to the default location and create links to /usr/bin ,
I think ruby needs that in /usr/bin and not /usr/local/bin which is the default for ImageMagick.
If you installed ImageMagick to the default location then link it.

 

sudo ln -s /usr/local/bin/Magick-config /usr/bin/Magick-config
sudo ln -s /usr/local/bin/Magick++-config /usr/bin/Magick++-config
sudo ln -s /usr/local/bin/MagickCore-config /usr/bin/MagickCore-config
sudo ln -s /usr/local/bin/MagickWand-config /usr/bin/MagickWand-config
cd ..

 

Install and setup mysql
yum install mysql mysql-server mysql-devel mysql++-devel mysql++

chkconfig --add mysqld
chkconfig mysqld on

service mysqld start
mysqladmin -u root password 'root'

 

set password to all root accounts and remove anonymous accounts
http://dev.mysql.com/doc/refman/5.1/en/default-privileges.html
http://dev.mysql.com/doc/refman/5.1/en/adding-users.html

login to mysql client program and:

 

create database gitorious;
CREATE USER 'gitorious'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON gitorious.* TO 'gitorious'@'localhost';

 restart mysql.

 

Install activemq

if using a different activemq version check its docs.
disable multicasting if its enables.

 

cd /usr/src
wget 'http://apache.spd.co.il/activemq/apache-activemq/5.3.2/apache-activemq-5.3.2-bin.tar.gz'
tar xzvf apache-activemq-5.3.2-bin.tar.gz -C /usr/local/
ln -s /usr/local/apache-activemq-5.3.2 /usr/local/apache-activemq
sh -c 'echo "export ACTIVEMQ_HOME=/usr/local/apache-activemq" >> /etc/activemq.conf'
sh -c 'echo "export JAVA_HOME=/usr/" >> /etc/activemq.conf'
sh -c 'echo "export ACTIVEMQ_OPTS=\"-Xmx512M\"" >> /etc/activemq.conf'

adduser activemq
chown -R activemq /usr/local/apache-activemq/data

 

do this fix:
http://activemq.apache.org/web-console.html

there is probably a bug with jmx:
https://issues.apache.org/activemq/browse/AMQ-2122
in a vm or local network add the hostname from /etc/sysconfig/network to /etc/hosts, it will fix the jmx problem.

we're going to use the stomp connector,
backup activemq.xml

 

mv /usr/local/apache-activemq/conf/activemq.xml /usr/local/apache-activemq/conf/activemq.xml.org

and enable the stomp configuration

cp /usr/local/apache-activemq/conf/activemq-stomp.xml /usr/local/apache-activemq/conf/activemq.xml

 

make sure the transport connectors look like that:

<transportConnectors>
            <transportConnector name="stomp" uri="stomp://0.0.0.0:61612?transport.closeAsync=false"/>
            <transportConnector name="stomp+nio" uri="stomp+nio://0.0.0.0:61613?transport.closeAsync=false"/>
</transportConnectors>

 

we will disable the web console and demos , comment or delete this line in activemq.xml:
<import resource="jetty.xml"/>

 

we will run activemq with the java service wrapper,
see activemq startup script in the attached zip, copy it to /etc/init.d/activemq.
notice this script is for 64 bit machine, replace linux-x86-64 with linux-x86-32 if your on a 32 bit machine.
see the actiivemq launchers in ACTIVEMQ_HOME/bin/linux.
make is executable.

 

chmod u+x /etc/init.d/activemq
mkdir -p /var/run/activemq
/sbin/chkconfig --add activemq
/sbin/chkconfig activemq on

start it

/etc/init.d/activemq start

 

check that activemq is running

netstat -an|grep "61612"
netstat -an|grep "61613"

 

monitoring activemq
there are many ways to monitor activemq:
http://activemq.apache.org/how-can-i-monitor-activemq.html

you can enable activemq web console at http://localhost:8161/admin/
see: http://activemq.apache.org/web-console.html

we will just enable jmx monitoring at the command line from localhost, we don't want to expose too many ports on this machine. if activemq is going to be under high load then other approaches are necessary.

just tell activemq to start a management connector:
see: http://activemq.apache.org/jmx
in activemq.xml

 

<managementContext>
            <managementContext createConnector="true" connectorPort="1999"/>
</managementContext>

 

and restart activemq

and using the command line tools we can now query activemq:
see: http://activemq.apache.org/activemq-command-line-tools-reference.html

list brokers:
/usr/local/apache-activemq/bin/activemq-admin list --jmxurl service:jmx:rmi:///jndi/rmi://localhost:1999/jmxrmi

to view all mbeans and their attributes:
/usr/local/apache-activemq/bin/activemq-admin query --jmxurl service:jmx:rmi:///jndi/rmi://localhost:1999/jmxrmi

to view all Gitorious queues and their attributes:
/usr/local/apache-activemq/bin/activemq-admin query -QQueue=*Git* --jmxurl service:jmx:rmi:///jndi/rmi://localhost:1999/jmxrmi

 

Create /etc/logrotate.d/activemq

 

/usr/local/apache-activemq/data/*log {
    missingok
    notifempty
}

and set its permissions:

chmod 644 /etc/logrotate.d/activemq

 

Install memcached

 

yum install memcached
/sbin/chkconfig --add memcached
/sbin/chkconfig memcached on
/sbin/service memcached start

 

Install ruby

As mantioned, we already have ruby 1.8 installed and used as default ruby by some applications, we don't want to override the default installation,so we'll install ruby-1.9.1 to /usr/local/ruby/ruby191 and add symlinks:
/usr/local/ruby/ruby-home -> /usr/local/ruby/ruby191
/usr/local/ruby/gem-home -> /usr/local/ruby/ruby191/lib/ruby/gems/1.9.1
/usr/local/ruby/ruby -> /usr/local/ruby/ruby191/bin/ruby
/usr/local/ruby/gem -> /usr/local/ruby/ruby191/bin/gem
/usr/local/ruby/rake -> /usr/local/ruby/ruby191/bin/rake

 

We will add the path to ruby191 in every script we use, we will export those in git's user bashrc file.
with this setup it should be easy to install another ruby version and replace a ruby version for Gitorious.
for example for trying ruby enterprise edition.
replacing a ruby version requires changing those links and changing the passenger LoadModule directive to reflect the required ruby installation.
see bug: http://www.ruby-forum.com/topic/213353

note that I had strange problems with newer ruby patch levels, you may want to try other patches, 378 works.

 

cd /usr/src
wget 'ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p378.tar.gz'
tar xvzf ruby-1.9.1-p378.tar.gz
cd ruby-1.9.1-p378
./configure --prefix /usr/local/ruby/ruby191
make && make install
/usr/local/ruby/ruby191/bin/gem update --system
cd ..

ln -s /usr/local/ruby/ruby191 /usr/local/ruby/ruby-home
ln -s /usr/local/ruby/ruby191/lib/ruby/gems/1.9.1 /usr/local/ruby/gem-home
ln -s /usr/local/ruby/ruby191/bin/ruby /usr/local/ruby/ruby
ln -s /usr/local/ruby/ruby191/bin/gem /usr/local/ruby/gem
ln -s /usr/local/ruby/ruby191/bin/rake /usr/local/ruby/rake

export some paths on the current shell for the rest of the installation process:

export RUBY_HOME=/usr/local/ruby/ruby-home
export GEM_HOME=/usr/local/ruby/gem-home
export PATH=$RUBY_HOME/bin:$PATH

 

Install gems

REMEMBER TO USE /usr/local/ruby/gem , if the paths above where exported then just gem would be the correct version.
we must make sure all gems are installed correctly or we'll have a lot of pain later..
when I installed everything works great, if you're not lucky newer gems version may expose problems.

 

aword about gems:

I'm not a ruby developer but I know all the following gems should be installed succesfuly , some of them don't always succeed because of compatability issues. for example I could install mongrel only with: gem install mongrel --pre

 

/usr/local/ruby/gem uninstall json_pure
/usr/local/ruby/gem install json_pure --no-ri --no-rdoc --version="1.2.3"

/usr/local/ruby/gem install rack --no-ri --no-rdoc --version="1.0.1"

/usr/local/ruby/gem install rdiscount --no-ri --no-rdoc --version="1.3.1.1"
/usr/local/ruby/gem install stomp --no-ri --no-rdoc --version="1.1"
/usr/local/ruby/gem install diff-lcs --no-ri --no-rdoc

 

install more gems

 

/usr/local/ruby/gem install --no-ri --no-rdoc rails mongrel ruby-hmac ruby-openid mime-types oniguruma textpow chronic \
BlueCloth ruby-yadis ruby-openid rmagick geoip ultrasphinx rspec rspec-rails RedCloth echoe daemons geoip mysql rmagick

 

If all this went well we won't need any other gems. if not, ruby will complain during db migrate or other stages and we will probably be in a problem..

 

Install ruby data base binding, this is important
read this:
http://forums.mysql.com/read.php?116,359591,359591#msg-359591
http://forums.mysql.com/read.php?116,353922,359544#msg-359544

 

run command mysql_config and copy the path from the line that starts with Usage:
"Usage: /usr/lib/mysql/mysql_config [OPTIONS]"
and install mysql-ruby with --with-mysql-config=

 

wget 'http://rubyforge.org/frs/download.php/51087/mysql-ruby-2.8.1.tar.gz'
tar xzvf mysql-ruby-2.8.1.tar.gz
cd mysql-ruby-2.8.1
/usr/local/ruby/ruby extconf.rb --with-mysql-config=/usr/lib/mysql/mysql_config
make && sudo make install

 

Install and configure gitorious

 

 

mkdir -p /opt/gitorious
cd /opt/gitorious/
git clone git://gitorious.org/gitorious/mainline.git gitorious
ln -s /opt/gitorious/gitorious/ /var/www/gitorious
cd /var/www/gitorious
ln -s /opt/gitorious/gitorious/script/gitorious /usr/local/bin/gitorious
rm /opt/gitorious/gitorious/public/.htaccess
mkdir log
mkdir tmp
mkdir tmp/pids
mkdir public/tarballs-cache
mkdir public/tarballs-work

 

create git user

adduser git
chown -R git:git /opt/gitorious/
mkdir /var/git
chown -R git:git /var/git

 

FROM NOW ON WE ARE LOOGED WITH git USER

 

su git 

the git user will always use our new ruby version.
edit /home/git/.bashrc or /home/git/.bash_profile and add the following three lines:

export RUBY_HOME=/usr/local/ruby/ruby-home
export GEM_HOME=/usr/local/ruby/gem-home
export PATH=$RUBY_HOME/bin:$PATH

source it:

source /home/git/.bashrc

 

PERMISIONS HERE ARE CRITICAL OR GIT DAEMON WILL NOT WORK

 

mkdir /home/git/.ssh
chmod -R 700 /home/git/.ssh
touch /home/git/.ssh/authorized_keys
chmod 600 /home/git/.ssh/authorized_keys
mkdir /opt/gitorious/repos
chmod -R 700 /opt/gitorious/repos
cd /var/www/gitorious
chmod ug+x script/*
chmod -R ug+w config/ log/ public/ tmp/
cp config/database.sample.yml config/database.yml
cp config/gitorious.sample.yml config/gitorious.yml
cp config/broker.yml.example config/broker.yml

 

edit config/database.yml and set mysql password in the production section.
edit config/gitorious.yml, follow the instructions in the doc/recipes/install-centos.txt.
make sure to edit the production section and NOT the test section.
create the secret with 'apg -m 64' and paste it as a one line to the property cookie_secret.

gitorious.yml:

 

cookie_secret: BeijeunchumJodheyddivpoavNopZobegipjissoshVoabWudsOvCepaigvarsIdSwiavyitMityoryisBakinwuxyeitOrrAtAdd,ufDejaur(oshDyRyncyftyojImtocImRatunfewnErnepVeyChejdedpafCupBochHennEnAwcawpisdabsOkOjbebecOkPowOrgyedLotPosEgnitDouvrainQuaijShelpajPhutechdoumsAwUcWeuvmeufnishnybErkOrgavFawyefradoodcanEaravNinHuvkunRinobsOlojencoj8thympIaglothelCiefekAfthijyeargyac\glyGrasopundojNoblerd^OfNabif

  repository_base_path: "/opt/gitorious/repos"
  extra_html_head_data:
  system_message:
  gitorious_client_port: 80
  gitorious_client_host: git.tikalk.com
  gitorious_host: git.tikalk.com
  gitorious_user: git
  gitorious_support_email: 'gitorious@tikalk.com'
  exception_notification_emails:  'gitorious@tikalk.com'
  mangle_email_addresses: true
  public_mode: true
  locale: en
  archive_cache_dir: "/var/www/gitorious/public/tarballs-cache"
  archive_work_dir: "/var/www/gitorious/public/tarballs-work"
  only_site_admins_can_create_projects: false
  hide_http_clone_urls: true
  is_gitorious_dot_org: false

 

NOTE:
the archive_cache_dir in gitorious.yml must point to a folder under gitorious public or we'll not ba able to download tarballs, I couldn't make it work even with xsendfile XSendFileAllowAbove on.I could make http clones work only if the git repos are also under gitorious public, not when the repos are under /home/git, so its not a good solution, still have to figure that out.

 

NOTE:
our site name is git.tikalk.com, the cname git. is reserved by gitorious and used to identify http clones. it requires us to have another domain name, one without a subdomin, and therefor we disabled http clones.there's another thing to do, edit app/models/site.rb and change HTTP_CLONING_SUBDOMAIN to something other then git otherwise gitorious will constantly complain in log messages about that 'git.' is reserved. this is only when your site name starts with git.

 

There's nothing to do in config/broker.yml

 

Remember: our ruby installation is in git's PATH

cd /var/www/gitorious

if all went well with our gems installations earlier then the following will do nothing.

rake gems:install RAILS_ENV=production

make sure the log dir is owned by git, if not change it

chown -R git:git log

migrate db:

rake db:migrate RAILS_ENV=production

Then, add a site administrator:

env RAILS_ENV=production ruby script/create_admin

 

ultrasphinx bootstrap, this will actually start the ultrasphinx search daemon, we will create a startup script for it later.

rake ultrasphinx:bootstrap RAILS_ENV=production

add crontabs (still with git user):

crontab -e
* */1 * * * cd /var/www/gitorious && /usr/local/ruby/rake ultrasphinx:index RAILS_ENV=production

 

disable girorious ssl:
edit config/environments/production.rb and add a line:
   SslRequirement.disable_ssl_check = true
- TODO: enable ssl

 

to force production uncomment this line in config/environment.rb
ENV['RAILS_ENV'] ||= 'production'

 

LOGOUT FROM GIT USER TO ROOT

 

Create /etc/logrotate.d/gitorious
TODO: I'm not sure why gitorious docs suggest to restart the daemons with logrotate? when monitoring the daemons with monit then the postrotate script is not necessary.
paste this content to /etc/logrotate.d/gitorious:

/var/www/gitorious/log/*log {
    missingok
    notifempty
    sharedscripts
    postrotate
        /sbin/service git-daemon restart > /dev/null 2>/dev/null || true
	/sbin/service git-poller restart > /dev/null 2>/dev/null || true
        /bin/touch /var/www/gitorious/tmp/restart.txt > /dev/null 2>/dev/null || true
endscript
}

/var/www/gitorious/db/sphinx/log/*log {
    missingok
    notifempty
    sharedscripts
    postrotate
        /sbin/service git-ultrasphinx restart > /dev/null 2>/dev/null || true
endscript
}

change the file permission

chmod 644 /etc/logrotate.d/gitorious

 

Install Phusion Passenger

make sure our ruby installation is still in you path, or export it:

export RUBY_HOME=/usr/local/ruby/ruby-home
export GEM_HOME=/usr/local/ruby/gem-home
export PATH=$RUBY_HOME/bin:$PATH

then:

gem install passenger --no-rdoc --no-ri
/usr/local/ruby/ruby-home/lib/ruby/gems/1.9.1/bin/passenger-install-apache2-module

follow instructions, copy and keep the directives it prints at the end of the installation, it will be something like this:

LoadModule passenger_module /usr/local/ruby/ruby191/lib/ruby/gems/1.9.1/gems/passenger-2.2.15/ext/apache2/mod_passenger.so
   PassengerRoot /usr/local/ruby/ruby191/lib/ruby/gems/1.9.1/gems/passenger-2.2.15
   PassengerRuby /usr/local/ruby/ruby191/bin/ruby

 

Apache httpd

 

yum install mod_xsendfile

 

on a clean install edit /etc/httpd/conf.d/welcome.conf and change "Options -Indexes" to "Options Indexes".

as root create a file /etc/httpd/conf.d/gitorious.conf, copy the file from the attached zip and replace the passenger directives with the output from passenger installations change server name an other values.
read about xsendfile.
restart apache.

 

if you have permission errors when starting apache see this:

http://www.modrails.com/documentation/Users%20guide.html#_the_apache_err...

 

 

Setting up daemons

 

create git-daemon
see  git-daemon in the attached zip.
copy it to /etc/init.d/git-daemon.
change the ruby path to reflect your installation.
make it executable.

chmod +x /etc/init.d/git-daemon

add it as a init script:

/sbin/chkconfig --add git-daemon
/sbin/chkconfig git-daemon on

/etc/init.d/git-daemon start

the git daemon listenes on port 9418 for git clone requests, we shoud open that port in centos:

iptables -A INPUT -p tcp --dport 9418 -j ACCEPT
service iptables save

 

create ultrasphinx daemon.
see git-ultrasphinx in the attached zip.
copy it to /etc/init.d/git-ultrasphinx.
make it executable.

chmod +x /etc/init.d/git-ultrasphinx

add it as a init script:

/sbin/chkconfig --add git-ultrasphinx
/sbin/chkconfig git-ultrasphinx on
- start it, or restart because it was started before when we bootstrupted it
/etc/init.d/git-ultrasphinx restart

 

create poller daemon.
note that its possible to execute a few poller instances, we will only execute one.
its pid file is: /var/www/gitorious/tmp/pids/poller0.pid
remember also that the poller depends on activemq and wil not start if activemq is not running.
see git-poller in the attached zip.
copy it to /etc/init.d/git-poller.
make it executable.

chmod +x /etc/init.d/git-poller
/sbin/chkconfig --add git-poller
/sbin/chkconfig git-poller on
- start it
/etc/init.d/git-poller start

 

check it with:
ps U git
you should see git-daemon, searchd and poller, and maybe some cron jobs, this is my output:
[root@centos www]# ps U git
  PID TTY      STAT   TIME COMMAND
17586 ?        Sl     0:00 /usr/local/ruby/ruby-home/bin/ruby /var/www/gitorious/script/git-daemon -d
17774 ?        S      0:00 searchd --config /var/www/gitorious/config/ultrasphinx/production.conf
17855 ?        Rl     0:06 poller                                               
17859 ?        S      0:00 crond
17860 ?        Ss     0:00 /bin/sh -c cd /var/www/gitorious && /usr/local/ruby/rake ultrasphinx:index RAILS_ENV=production
17861 ?        Rl     0:00 /usr/local/ruby/ruby191/bin/ruby /usr/local/ruby/rake ultrasphinx:index RAILS_ENV=production

or
netstat -an|grep 9418
you should see the git-daemon process

netstat -an|grep 3312
for ultrasphinx

 

 

Email setup

We'll send notification emails through a gmail account.
The best is to configure sendmail, I didn't.
Gitorious uses sendmail by default , or it can be setup to send smtp directly,some problems I had: couldn't make ruby smtp send emails through a gmail account, and even if I could I don't think it will overcome network errors and queue emails for later sending, sendmail will but is too much configuration. So i'm using a solution common to the Mutt community, msmtp which is sendmail compatible(almost) , and msmtpq wrapper scripts to overcome failure when sending. msmtpq and msmtpQ are two scripts, msmtpQ send emails and if it fails it keeps them in a file system queue. msmtpq can priodically process this queue and try to send the emails. so we'll use msmtpQ to send emails and set a cron job to run msmtpq for every 10 minutes.

msmtpq has recently been updated to be one script but I couldn't make it work, it keeps a queue file also with success.
http://www.mail-archive.com/msmtp-users@lists.sourceforge.net/msg00127.html

I will use the two scripts I have on my machine or you can try and find them somewhere in mutt users mailing list.
I also could not find a recent centos RPM for msmtp, it is easily installed on ubuntu , opensuse and debian, nothing for centos.

so we'll install froum source:
make sure you have those packages installed:

yum install openssl openssl-devel libgsasl libgsasl-devel gnutls gnutls-devel libidn libidn-devel

 and install msmtp:

cd /usr/src
wget 'http://sourceforge.net/projects/msmtp/files/msmtp/1.4.21/msmtp-1.4.21.tar.bz2/download'
tar xjvf msmtp-1.4.21.tar.bz2
cd msmtp-1.4.21
./configure
make && make install

 

 

create the two scripts msmtpq and msmtpQ, copy them from the attached zip file, or try to find them in mutt users - mailing list.
in both you can change three arguments: Q for the queue location, LOG for log location, and the MSMTP executable. defaults are good for me, see where msmtp was installed for you.
copy both scripts to /usr/local/bin and make them executable.

chmod +x /usr/local/bin/msmtpQ
chmod +x /usr/local/bin/msmtpq

 

NOTE:
look at vendor/rails/actionmailer/lib/action_mailer/base.rb line 690,if there will be a return-path configured then emails will not be sent, it will break the msmtp command line.

 

LOGIN with git user

su git
touch ~/.msmtprc
chmod 600 ~/.msmtprc

NOTE: if the queue directory does not exist sending mail will fail and ruby just reports a broken pipe, even though msmtp does return a nice message. so create the queue folder:

mkdir ~/.msmtp.queue

create the log files otherwise the scripts fail, couldn't find the time to fix it. and thus 'create' in the logrotate is mandatory.

touch ~/.msmtpq.log
touch ~/.msmtpQ.log
touch ~/.msmtp.log

still logged with git user edit ~/.msmtprc and change to your email account:

msmtprc:

remove the ' from the email addresses, I put it just to fix a html error in this post.

defaults
account default
host smtp.gmail.com
port 587
timeout off
auth on
user 'gitorious@tikalk.com'
password PASSWORD
auto_from off
from 'gitorious@tikalk.com'
tls on
tls_starttls on
tls_certcheck off
maildomain gmail.com
logfile ~/.msmtp.log

 

config gitorious with msmtpQ

cd /var/www/gitorious
cp config/environments/production.rb config/environments/production.rb.org

edit config/environments/production.rb,
find the line :

config.action_mailer.delivery_method = :sendmail
and add bellow it:

config.action_mailer.sendmail_settings = {
        :location => "/usr/local/bin/msmtpQ",
        :arguments => "-t -- "
        }

Notice the arguments, it will not work without the -- , it was a lot of pain to figure that out.
The application will run with the git user and environment and thus will use the .msmtprc in git's home.
as I mentioned before, see vendor/rails/actionmailer/lib/action_mailer/base.rb

 

finally create a cron job for msmtpq, still with git user logged in. the cron should run with git's environment and thus use the .msmtprc in git's home. This job will do nothing most of the time.

crontab -e
*/10 * * * *     /usr/local/bin/msmtpq -r

 

to check email sending is working from ruby:
login as git and cd to /var/www/gitorious.
start irb:

irb(main):001:0> IO.popen("/usr/local/bin/msmtpQ -t -- shalom@tikalk.com","w+") do |sm|
irb(main):002:1* sm.print("Hello from irb")
irb(main):003:1> sm.flush
irb(main):004:1> end

the email should be send or you'll see the eror if ruby prints it.

 

NOTE: if for some reason a user registered but didn't receive the email he will be pending activation and will not be able to register again with that email. in this case either delete the record in the db or copy the registration time column to the activation time column.

 

LOGOUT FROM git user.

 

Create /etc/logrotate.d/git-msmtp with this content:

/home/git/.msmtp*log {
    create
    missingok
    notifempty

}

and set its permisions:

chmod 644 /etc/logrotate.d/git-msmtp

 

you may want to create a cron to delete the spool mails that git user receives for all the other cron jobs, to view those emails: mutt -f /var/spool/mail/git

crontab -e
@weekly rm /var/spool/mail/git

 

 

Monitoring daemons with Monit

read monit docs at http://mmonit.com/monit/
we can install monit with yum from epel repository, but to get the latest version:

wget 'http://packages.sw.be/monit/monit-5.1.1-1.el5.rf.x86_64.rpm'
or for 32 bit os:
wget 'http://packages.sw.be/monit/monit-5.1.1-1.el5.rf.i386.rpm'

rpm -i monit-5.1.1-1.el5.rf.XXX.rpm

sudo chmod 0700 /etc/monit.conf

the rpm installes a sysv init script for monit but we want it to start by inittab,so remove the sysv init script:

chkconfig monit off

remember that git-poller depends on activemq.

we will start our daemons with monit so first remove them from sysv init:

chkconfig git-daemon off
chkconfig git-ultrasphinx off
chkconfig git-poller off
chkconfig activemq off

 

create a file /etc/monit.d/gitorious-monitrc, copy from attached zip.
make sure you set the correct pid files for the daemons, mine may be different locations then yours, aspecially the activemq one depends on the OS arch.
I'm not going to document all details on configuring monit, read the monit manual.
with activemq monit will monitor the java warper, the java wraper monitors the real java process.

in monit.conf: REMOVE THE ' FROM THE EMAIL ADDRESS

set daemon 120 with start delay 240
set logfile /var/log/monit.log
set idfile /var/.monit.id
set statefile /var/.monit.state

set alert 'youremail@somewhere.com'  with reminder on 5 cycle

set mailserver 
smtp.gmail.com port 465 username "community@tikalk.com" password "xxx" using SSLV3, 
smtp.gmail.com port 587 username "community@tikalk.com" password "xxx" using TLSV1,
     with timeout 15 seconds

set eventqueue
      basedir /var/monit
      slots 5000

run syntax check with monit -t

we start monit from init, add to /etc/inittab:

mo:2345:respawn:/usr/bin/monit -Ic /etc/monit.conf

then:

telinit q

 

Create /etc/logrotate.d/monit with this content:

/var/log/monit.log {
    create
    missingok
    notifempty
}

and change its permissions:

chmod 644 /etc/logrotate.d/monit

 

set your time zone by changing in config/environmet.rb
config.time_zone = 'UTC'
to your time zone.
discover timezones with:
su - git
cd /var/www/gitorious
rake -D time
rake time:zones:local

restart gitorious with:
touch tmp/restart.txt
 

 

we're done, restart apache.

You may encounter problems related to SELinux so you can disable SELInux and when everything works enable it and hope it still works, or fix the SELinux issues.