Für jeden Kunden
die passende Lösung!

GitLab Installation on Ubuntu Server 12.04

For the people not knowing what GIT is or what it’s used for here’s a link to read about it What is GIT. This post wouldn’t have been possible if it was not for the work done by the community at GitLab . Please donate to this project.

Installation

This installation was done on a Ubuntu 12.04 server. A clean install was done with no extra packages installed with the base installation.

Set the hostname of the server and make shure that the server is reachable with this name.

The installation consists of 4 steps:

Run the Install script
Start the web front-end
Start a Resque worker (for background processing

Install curl and sudo

apt-get install curl sudo
curl https://raw.github.com/gitlabhq/gitlab-recipes/master/install/debian_ubuntu.sh | sh

2. Install gitlab and configuration. Check status configuration.

sudo gem install charlock_holmes
sudo pip install pygments
sudo gem install bundler
cd /home/gitlab
sudo -H -u gitlab git clone git://github.com/gitlabhq/gitlabhq.git gitlab
cd gitlab # Rename config files
sudo -u gitlab cp config/gitlab.yml.example config/gitlab.yml

Install apg for password generation

sudo apt-get install apg
cd ~
apg -n1 -m16 -MNCL >  mysqlrootpass
cat  mysqlrootpass

Install mysql server

sudo apt-get install mysql-server

apg -n1 -m16 -MNCL >  mysqlgitlabpass

apt-get install libpq-dev #on some ubuntu systems this is needed

# create mysql gitlab user and database

cd ~

mysql -u root --password=`head mysqlrootpass` -e "CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '`head mysqlgitlabpass`';"
mysql -u root --password=`head mysqlrootpass` -e "CREATE DATABASE gitlab;"
mysql -u root --password=`head mysqlrootpass` -e "GRANT ALL PRIVILEGES ON \`gitlab\` . * TO 'gitlab'@'localhost' WITH GRANT OPTION ;"

cd /home/gitlab/gitlab
sudo -u gitlab cp config/database.yml.example config/database.yml

edit  config/database.yml and change username, password and database in the "production" section.

Install gems

sudo -u gitlab -H bundle install --without development test --deployment

Setup DB

sudo -u gitlab bundle exec rake gitlab:app:setup RAILS_ENV=production

cp ./lib/hooks/post-receive /home/git/share/gitolite/hooks/common/post-receive

chown git:git /home/git/share/gitolite/hooks/common/post-receive

chmod 750 /home/git/.gitolite

Checking status: 

sudo -u gitlab bundle exec rake gitlab:app:status RAILS_ENV=production
#output example
Starting diagnostic
config/database.yml............exists
config/gitlab.yml............exists
/home/git/repositories/............exists
/home/git/repositories/ is writable?............YES
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.
Can clone gitolite-admin?............YES
UMASK for .gitolite.rc is 0007? ............YES
Finished

 

 

Nginx && Unicorn

Install Nginx

sudo apt-get install nginx

Unicorn

cd /home/gitlab/gitlab
sudo -u gitlab
cp config/unicorn.rb.orig config/unicorn.rb
sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D

create nginx gitlab config at /etc/nginx/sites-available/gitlab

#/etc/nginx/sites-available/gitlab
upstream gitlab {
server unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket;
}
server {
listen YOUR_SERVER_IP:80;
server_name gitlab.YOUR_DOMAIN.com;
root /home/gitlab/gitlab/public;
# individual nginx logs for this gitlab vhost
access_log /var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/gitlab_error.log;
location / {
# serve static files from defined root folder;. 
# @gitlab is a named location for the upstream fallback, see below
try_files $uri $uri/index.html $uri.html @gitlab;
}
# if a file, which is not found in the root folder is requested,
# then the proxy pass the request to the upsteam (gitlab unicorn) 
location @gitlab {
proxy_redirect off;
# you need to change this to "https", if you set "ssl" directive to "on"
proxy_set_header X-FORWARDED_PROTO http;
proxy_set_header Host gitlab.YOUR_SUBDOMAIN.com:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://gitlab;
}
}

edit /home/gitlab/gitlab/resque.sh and add #!/bin/bash to the first line

#!/bin/bash
mkdir -p tmp/pids
bundle exec rake environment resque:work QUEUE=post_receive,mailer,system_hook  RAILS_ENV=production PIDFILE=tmp/pids/resque_worker.pid BACKGROUND=yes

 

sudo ln -s  /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab  

edit gitlab

YOUR_DOMAIN.com – change to your domain
YOUR_SERVER_IP – change to your server ip

sudo /etc/init.d/nginx restart

 Create init.d file /etc/init.d/gitlab

 

#!/bin/sh 

### BEGIN INIT INFO
# Provides: gitlab
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the gitlab server
# Description: starts gitlab using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON="/usr/local/bin/bundle"
DAEMON2="/home/gitlab/gitlab/resque.sh"
NAME=unicorn
DESC="Gitlab service"

test -x $DAEMON || exit 0
test -x $DAEMON2 || exit 0

set -e

. /lib/lsb/init-functions
DAEMON_OPTS="exec unicorn_rails -c /home/gitlab/gitlab/config/unicorn.rb -E production -D"
PID=/home/gitlab/gitlab/tmp/pids/unicorn.pid
PID2="/home/gitlab/gitlab/tmp/pids/resque_worker.pid"
dir='/home/gitlab/gitlab'
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --chuid gitlab --quiet --pidfile $PID \
--exec $DAEMON --chdir $dir -- $DAEMON_OPTS || true
start-stop-daemon --start --chuid gitlab --quiet --pidfile $PID2 \
--exec $DAEMON2 --chdir $dir  || true
echo "$NAME."
;;

stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile $PID \
--name ruby --chdir $dir || true
start-stop-daemon --stop --chuid gitlab --quiet --pidfile $PID2 \
--name ruby --chdir $dir || true
echo "$NAME."
;;

restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
$PID --name ruby --chdir $dir || true
start-stop-daemon --stop --chuid gitlab --quiet --pidfile $PID2 \
--name ruby --chdir $dir || true
sleep 1
start-stop-daemon --start --chuid gitlab --quiet --pidfile \
$PID --exec $DAEMON --chdir $dir -- $DAEMON_OPTS || true
start-stop-daemon --start --chuid gitlab --quiet --pidfile $PID2 \
--exec $DAEMON2 --chdir $dir  || true
echo "$NAME."
;;
status)
status_of_proc -p $PID "$DAEMON" unicorn && exit 0 || exit $?
;;
*)
echo "Usage: $NAME {start|stop|restart|reload|force-reload|status}" >&2
exit 1
;;
esac

exit 0

sudo chmod +x /etc/init.d/gitlab
sudo update-rc.d-insserv gitlab defaults
sudo /etc/init.d/gitlab restart
sudo /etc/init.d/nginx restart