Thursday, November 25, 2010

Gitorious install on Debian Squeeze with stompserver

I have modified this install tutorial from Christian Johansen found here

Some info from here as well

There is also source for a debian package by Marius Mårnes Mathiesen here the most recent commits are forked here

Squeeze is needed for the new magickwand stuff

Had issues with activemq so using stompserver instead

apt-get install -y sudo git-core git-svn apg build-essential libpcre3 libpcre3-dev sendmail \
make zlib1g zlib1g-dev ssh memcached apache2 \
libonig-dev libyaml-dev geoip-bin libgeoip-dev libgeoip1 \
uuid uuid-dev openjdk-6-jre apache2-prefork-dev curl openssl libcurl4-gnutls-dev

apt-get install -y imagemagick libmagickwand-dev && \
gem install --no-ri --no-rdoc rmagick

apt-get install -y mysql-client mysql-server libmysqlclient15-dev && \
gem install --no-ri --no-rdoc mysql

sudo dpkg -i ruby-enterprise*

echo 'export PATH=/opt/ruby-enterprise/bin:$PATH
export LD_LIBRARY_PATH="/usr/local/lib"
export LDFLAGS="-L/usr/local/lib -Wl,-rpath,/usr/local/lib"' >> /etc/profile

echo '/usr/local/lib
include*.conf' >> /etc/


cd /usr/src
tar xvzf rubygems*
cd rubygems*
ruby setup.rb

cd /usr/src
tar xvfz sphinx-*
cd sphinx-*
make && sudo make install
gem install --no-ri --no-rdoc ultrasphinx

gem install stompserver
echo '#!/bin/sh
# Start/stop the stompserver
# Provides: stomp
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 1
# Short-Description: Stomp
# Description: Stomp
test -f $DAEMON || exit 0
. /lib/lsb/init-functions
case $1 in
start) log_daemon_msg Starting stompserver stompserver
     start-stop-daemon --start --name stompserver --startas $DAEMON \
                                      --background --user git
     log_end_msg $?
stop) log_daemon_msg Stopping stompserver stompserver
     start-stop-daemon --stop --name stompserver
     log_end_msg $?
restart) log_daemon_msg Restarting stompserver stompserver
    start-stop-daemon --stop --retry 5 --name stompserver
    start-stop-daemon --start --name stompserver --startas $DAEMON \
                                       --background --user git
    log_end_msg $?
    status_of_proc $DAEMON stompserver && exit 0 || exit $?
*) log_action_msg Usage: /etc/init.d/stomp {start|stop|restart|status}
    exit 2
exit 0' > /etc/init.d/stompserver
chmod +x /etc/init.d/stompserver
update-rc.d stompserver defaults

echo '#!/bin/sh
# Start/stop the git poller
# Provides: git-poller
# Required-Start: stomp
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 1
# Short-Description: Gitorious poller
# Description: Gitorious poller

echo  `date` " Starting git-poller" >> "$GITORIOUS_ROOT/log/git-poller.log"
/bin/su -- git -c " cd $GITORIOUS_ROOT; RAILS_ENV=production script/poller $@"' > /etc/init.d/poller
chmod +x /etc/init.d/poller
update-rc.d poller defaults

git clone git:// gitorious
chmod -R g+sw /var/www/gitorious
ln -s /var/www/gitorious/script/gitorious /usr/local/bin/gitorious
cd gitorious/
rm public/.htaccess
mkdir -p tmp/pids
chmod ug+x script/*
chmod -R g+w config/ log/ public/ tmp/

which ruby
vi doc/templates/ubuntu/git-daemon
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):
GIT_DAEMON="/opt/ruby-enterprise/bin/ruby \
    /var/www/gitorious/script/git-daemon -d"
ln -s /var/www/gitorious/doc/templates/ubuntu/git-ultrasphinx /etc/init.d/.
ln -s /var/www/gitorious/doc/templates/ubuntu/git-daemon /etc/init.d/.

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 .

gem install --no-ri --no-rdoc rails mongrel mime-types textpow chronic \
    ruby-hmac daemons mime-types oniguruma textpow chronic BlueCloth \
    ruby-yadis ruby-openid geoip rspec rspec-rails RedCloth echoe
gem install --no-ri --no-rdoc --version="1.0.1" rack

adduser git
usermod -a -G gitorious git
mkdir /var/git
mkdir /var/git/repositories
mkdir /var/git/tarballs
mkdir /var/git/tarball-work
chown -R git:git /var/git

su git
mkdir ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys
vi ~/.bashrc
Append the following to /home/git/.bashrc
# User specific aliases and functions
export RUBY_HOME=/opt/ruby-enterprise
export GEM_HOME=$RUBY_HOME/lib/ruby/gems/1.8/gems
export PATH=$RUBY_HOME/bin:$PATH

cd /var/www/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
apg -m 64
See original doc for details on this config file
rake db:migrate RAILS_ENV=production
mysql -uroot -p
create database gitorious;
create database gitorious_test;
create database gitorious_dev;
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;
sudo rake gems:install
vi config/database.yml
Make your config match your mysql db setup
rake db:migrate RAILS_ENV=production
cd /var/www/gitorious
env RAILS_ENV=production ruby script/create_admin
> user = User.first
> user.login = "yourname" # Change to your desired username
> user.activate
> user.accept_terms
rake ultrasphinx:bootstrap RAILS_ENV=production
chown -R git:gitorious config/environment.rb script/poller log tmp
chmod -R g+w config/environment.rb script/poller log tmp
chmod ug+x script/poller
/etc/init.d/activemq start
env RAILS_ENV=production /etc/init.d/git-daemon start
su git -c \
  "cd /var/www/gitorious && \
    env RAILS_ENV=production script/poller run"

su git -c \
  "cd /var/www/gitorious && script/server -e production"

echo '* */1 * * * root cd /var/www/gitorious && rake ultrasphinx:index RAILS_ENV=production' >> /etc/crontab
cp doc/templates/ubuntu/gitorious-logrotate /etc/logrotate.d/gitorious
sudo chmod +x /etc/logrotate.d/gitorious
gem install passenger

a2enmod rewrite
a2enmod deflate
a2enmod passenger
a2enmod expires
a2enmod rewrite

vi conf/vhost.conf
Update config
ln -s /var/www/gitorious/conf/vhost.conf /etc/apache2/sites-available/gitorious
a2ensite gitorious