Difference between revisions of "Gitlab"

From ArchWiki
Jump to: navigation, search
m (Check status: typo)
(systemd support: Fixed systemd service files, gitlab.target makes no sence -> change to multi-user.target)
(41 intermediate revisions by 12 users not shown)
Line 6: Line 6:
 
{{Article summary wiki|Ruby on Rails}}
 
{{Article summary wiki|Ruby on Rails}}
 
{{Article summary end}}
 
{{Article summary end}}
[http://gitlabhq.com/ Gitlab] is a free git repository management application based on [[Ruby on Rails]] and [[Gitolite]]. It is distributed under the MIT License and its source code can be found on [https://github.com/gitlabhq/gitlabhq Github]. It is a very active project with a monthly release cycle and ideal for businesses that want to keep their code private. Consider it as a self hosted Github but open source. You can try a demo page [http://gitlabhq.com/ here].
+
[http://gitlab.org/ Gitlab] is a free git repository management application based on [[Ruby on Rails]]. It is distributed under the MIT License and its source code can be found on [https://github.com/gitlabhq/gitlabhq Github]. It is a very active project with a monthly release cycle and ideal for businesses that want to keep their code private. Consider it as a self hosted Github but open source. You can try a demo [http://demo.gitlabhq.com/ here].
 
+
 
{{Note|Throughout the article, sudo is heavily used, assuming that the user that is running the commands is root or someone with equal privileges. There is no need to edit the sudoers file whatsoever. It is only used to change to the appropriate user. For more info read {{ic|man sudo}}.}}
 
{{Note|Throughout the article, sudo is heavily used, assuming that the user that is running the commands is root or someone with equal privileges. There is no need to edit the sudoers file whatsoever. It is only used to change to the appropriate user. For more info read {{ic|man sudo}}.}}
  
Line 14: Line 13:
 
Install the packages below as they are needed to proceed further.
 
Install the packages below as they are needed to proceed further.
  
  # pacman -Syu --needed sudo git wget curl checkinstall libxml2 libxslt mysql++ base-devel zlib icu redis openssh python2 python2-pygments python2-pip libyaml ruby
+
  # pacman -Syu --noconfirm --needed sudo base-devel zlib libyaml openssl gdbm readline ncurses libffi curl git openssh redis libxml2 libxslt icu python2
  
==Create user accounts==
+
{{Note| In order to receive mail notifications, make sure to install a mail server. By default, Archlinux does not ship with one. The recommended mail server is [[postfix]], but you can use others such as [[SSMTP]], [[msmtp]], [[sendmail]], [https://wiki.archlinux.org/index.php/Category:Mail_Server etc].}}
  
Add {{ic|git}} and {{ic|gitlab}} user. {{ic|git}} is a system user that will be used for [[gitolite]]. {{ic|gitlab}} user will be used for Gitlab and is part of group git.
+
== PKGBUILDs for Gitlab and Gitlab-shell ==
 +
There are some (not fully working) PKGBUILDs available to create installable packages:
  
# usermod -d /home/git git
+
[https://github.com/mtorromeo/archlinux-packages/tree/master/gitlab Gitlab PKGBUILD on GitHub.com]
# mkdir -pv /home/git
+
# chown -R git:git /home/git
+
# useradd --user-group --shell /bin/bash --comment 'gitlab system' --create-home --groups git gitlab
+
  
Note that the user ''git'' must have its initial group set to ''git'' (not ''users''). If the initial group is not ''git'', then all files created by the ''git'' user will be owned by git:users which will prevent gitlab from showing you a newly created repo (it will get stucked at the page where it tells you how to push to the new repo). Running ''sudo usermod -g git git'' will set the ''git'' user's initial group.
+
[https://github.com/mtorromeo/archlinux-packages/tree/master/gitlab-shell Gitlab-shell PKGBUILD on GitHub.com]
  
==Gitolite==
+
(Please extend/rename this section with further instructions)
  
 +
==Ruby==
  
Clone the gitolite repository from Gitlab's fork. Note that it's version 3.
+
GitLab supports [[ruby]] >= {{ic|1.9.3}} and {{ic|2.0.0}}, but some dependencies gems work better with ruby {{ic|1.9.3}}. Install it from the official repositories and if you bump into any trouble use [[rvm]] with latest ruby {{ic|1.9.3}}.
# cd /home/git
+
# sudo -H -u git git clone -b gl-v304 https://github.com/gitlabhq/gitolite.git /home/git/gitolite
+
  
Generate Gitlab's ssh key to be used with gitolite:
+
{{Note|If you want to use rvm be sure to check out [[Gitlab#Running GitLab with rvm]] before starting with the installation}}
  
{{ic|<nowiki> # sudo -H -u gitlab ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa</nowiki>}}
+
==User accounts==
  
Add the following path to git's {{ic|.bash_profile}}:
+
Add {{ic|git}} user:
  # sudo -u git sh -c 'echo "export PATH=/home/git/bin:$PATH" >> /home/git/.bash_profile'
+
 
# sudo -u git sh -c 'mkdir /home/git/bin'
+
  # useradd -U -m -d /home/git git
# sudo -u git -H sh -c "export PATH=/home/git/bin:$PATH; /home/git/gitolite/install -ln"
+
 
 +
{{Note| {{ic|git}} user must have its initial group set to {{ic|git}} (not {{ic|users}}). If the initial group is not {{ic|git}}, then all files created by the {{ic|git}} user will be owned by {{ic|git:users}} which will prevent GitLab from showing you a newly created repository (it will get stucked at the page where it tells you how to push to the new repository).}}
 +
 
 +
==gitlab-shell==
 +
 
 +
GitLab Shell is an ssh access and repository management software developed specially for GitLab.
 +
 
 +
Login as git:
 
   
 
   
Copy Gitlab's public key to gitolite's home and change permissions:
+
  # su - git
  # cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub
+
# chmod 0444 /home/git/gitlab.pub
+
  
Install gitolite:
+
Clone gitlab shell:
  # sudo -u git -H sh -c "export PATH=/home/git/bin:$PATH; /home/git/gitolite/src/gitolite setup -pk /home/git/gitlab.pub"
+
   
 +
$ git clone https://github.com/gitlabhq/gitlab-shell.git
 +
$ cd gitlab-shell
  
{{hc|Example output|
+
Switch to the right version:
creating gitolite-admin...
+
Initialized empty Git repository in /home/git/repositories/gitolite-admin.git/
+
creating testing...
+
Initialized empty Git repository in /home/git/repositories/testing.git/
+
[master (root-commit) 012fdf5] start
+
2 files changed, 6 insertions(+)
+
create mode 100644 conf/gitolite.conf
+
create mode 100644 keydir/gitlab.pub
+
}}
+
  
Change permissions:
+
  $ git checkout v1.4.0
  # chmod -R g+rwX /home/git/repositories/
+
# chmod g+x /home/git
+
# chown -R git:git /home/git/repositories/
+
  
{{Note| The next step is '''important''' to succeed. If not, do not try to proceed any further.}}
+
Edit {{ic|config.yml}} and replace gitlab_url with something like {{ic|http://domain.com/}}:
  
Add Gitlab's ssh key to known hosts:
+
  $ cp config.yml.example config.yml
  # sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin
+
  
Answer yes. At this point you should be able to clone the gitolite-admin repository.
+
Setup the environment:
  
{{hc|Example output|
+
$ ./bin/install
Cloning into '/tmp/gitolite-admin'...
+
The authenticity of host 'localhost (::1)' can't be established.
+
ECDSA key fingerprint is 5a:50:69:47:1f:1c:61:79:08:a8:2c:fa:a1:fb:48:bf.
+
Are you sure you want to continue connecting (yes/no)? yes
+
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
+
remote: Counting objects: 6, done.
+
remote: Compressing objects: 100% (4/4), done.
+
Receiving objects: 100% (6/6), 712 bytes, done.
+
remote: Total 6 (delta 0), reused 0 (delta 0)
+
}}
+
  
If the repository is cloned successfully, it is safe to remove it:
+
You should see this result:
# rm -rf /tmp/gitolite-admin
+
  
==Gitlab==
+
{{hc|Example output|<nowiki>
 +
mkdir -p /home/git/repositories: true
 +
mkdir -p /home/git/.ssh: true
 +
chmod 700 /home/git/.ssh: true
 +
touch /home/git/.ssh/authorized_keys: true
 +
chmod 600 /home/git/.ssh/authorized_keys: true
 +
chmod -R ug+rwX,o-rwx /home/git/repositories: true
 +
find /home/git/repositories -type d -print0 | xargs -0 chmod g+s: true
 +
</nowiki>}}
  
===Installation===
+
==Database selection==
  
{{Tip| If you do not want to download any documentation, add {{ic|gem: --no-rdoc --no-ri}} to {{ic|/home/gitlab/.gemrc}}. Be sure to add it as the gitlab user in order to acquire the appropriate permissions.}}
+
Currently GitLab supports [[MySQL]] and [[PostgreSQL]]. [[MariaDB]] has not been officially tested but it works just fine.
  
Add [[ruby]] to Gitlab's {{ic|PATH}}:
+
===MariaDB===
# sudo -u gitlab -H sh -c 'echo "export PATH=$(ruby -rubygems -e "puts Gem.user_dir")/bin:$PATH" >> /home/gitlab/.bashrc'
+
  
Install bundler and charlock_holmes:
+
[[pacman|Install]] {{Pkg|mariadb}} and {{Pkg|libmariadbclient}} from the [[official repositories]] and start the [[daemon]]. Create the database and do not forget to replace {{ic|your_password_here}} with a real one.
# sudo -u gitlab -H gem install charlock_holmes --version '0.6.9'
+
# sudo -u gitlab -H gem install bundler
+
  
{{Note|When installing charlock_holmes don't mind any errors that might occur, that's ''normal''.}}
+
# su - git
 +
$ mysql -u root -p
  
Because systemd requires full path to binaries to launch (the path is not enough), create a symbolic link in /home/gitlab/bin/ that points to the **bundle** executable. We'll also add the folder to gitlab's PATH:
+
  mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
  # sudo -u gitlab -H mkdir /home/gitlab/bin
+
  mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'your_password_here';
  # sudo -u gitlab -H sh -c "ln -s \$(ruby -rubygems -e 'puts Gem.user_dir')/bin/bundle /home/gitlab/bin/"
+
  mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
  # sudo -u gitlab -H sh -c 'echo "export PATH=/home/gitlab/bin:$PATH" >> /home/gitlab/.bashrc'
+
mysql> \q
  
 +
Try connecting to the new database with the new user:
  
Clone Gitlab's stable repository:
+
  $ mysql -u gitlab -p -D gitlabhq_production
  # cd /home/gitlab
+
# sudo -H -u gitlab git clone -b stable git://github.com/gitlabhq/gitlabhq.git gitlab
+
# cd gitlab
+
# sudo -u gitlab mkdir -pv tmp
+
  
===Basic configuration===
+
===PostgreSQL===
  
First we need to rename the example file.
+
[[pacman|Install]] {{Pkg|postgresql}} and {{Pkg|libpqxx}} from the [[official repositories]]. Follow [[PostgreSQL#Installing_PostgreSQL]] to set it up and start the [[daemon]].
  
# sudo -u gitlab cp config/gitlab.yml.example config/gitlab.yml
+
Login to PostgreSQL and remember to change {{ic|your_password_here}} to a real one:
  
The options are pretty straightforward. You can skip this part as it is quite detailed. Open {{ic|/home/gitlab/gitlab/config/gitlab.yml}} with your favorite editor and check the settings below.
+
# sudo -u postgres psql -d template1
  
====Web application specific settings====
+
template1=# CREATE USER git WITH PASSWORD 'your_password_here';
 +
template1=# CREATE DATABASE gitlabhq_production OWNER git;
 +
template1=# \q
  
{{hc|/home/gitlab/gitlab/config/gitlab.yml|<nowiki>
+
Try connecting to the new database with the new user:
host: myhost.example.com
+
port: 80
+
https: false
+
</nowiki>}}
+
  
*{{ic|host}}: Enter your [[Wikipedia:Fully_qualified_domain_name|Fully Qualified Domain Name]].
+
# sudo -u git -H psql -d gitlabhq_production
  
====Email used for notification====
+
===MySQL===
  
{{hc|/home/gitlab/gitlab/config/gitlab.yml|<nowiki>
+
If you are still in favor of {{AUR|mysql}}, follow the same commands as MariaDB.
from: notify@example.com
+
</nowiki>}}
+
  
This is how the mail address will be shown for mail notifications. Gitlab needs the sendmail command in order to send emails (for things like lost password recovery, new user addition etc). This command is provided by packages such as [[msmtp]], [[postfix]], [[sendmail]] etc, but you can only have one of them installed. First, check whether you already have the sendmail command:
+
==Gitlab==
  
# ls /usr/sbin/sendmail
+
===Installation===
  
If you get a ‘cannot access /usr/bin/sendmail’ then install one of the above packages.
+
Clone GitLab's repository:
 +
# su - git
 +
$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab
 +
$ cd gitlab
 +
$ git checkout 5-2-stable
  
====Application specific settings====
+
{{Note| You can change {{ic|5-2-stable}} to {{ic|master}} if you want the bleeding edge version, but do so with caution! Check github to see what is the latest stable version and replace above accordingly.}}
  
{{hc|/home/gitlab/gitlab/config/gitlab.yml|<nowiki>
+
===Basic configuration===
default_projects_limit: 10
+
# backup_path: "/vol/backups"  # default: Rails.root + backups/
+
# backup_keep_time: 604800      # default: 0 (forever) (in seconds)
+
</nowiki>}}
+
  
*{{ic|default_projects_limit}}: As the name suggests, this integer defines the default number of projects new users have. The number can change from within Gitlab by an administrator.
+
First we need to rename the example file.
*{{ic|backup_path}}: The path where backups are stored. Default location is {{ic|/home/gitlab/gitlab/backups}}. The {{ic|backups}} folder is created automatically after first backup.
+
*{{ic|backup_keep_time}}: Time to preserve backups. The default option is to never be deleted.
+
  
Also check [[#Backup_and_restore| Backup and restore]].
+
$ cp config/gitlab.yml.example config/gitlab.yml
  
====Git Hosting configuration====
+
The options are pretty straightforward. Open {{ic|config/gitlab.yml}} with your favorite editor and edit where needed.
 +
Make sure to change {{ic|localhost}} to the fully-qualified domain name of your host serving GitLab where necessary.
  
{{hc|/home/gitlab/gitlab/config/gitlab.yml|<nowiki>
+
Make sure GitLab can write to the {{ic|log/}} and {{ic|tmp/}} directories:
admin_uri: git@localhost:gitolite-admin
+
base_path: /home/git/repositories/
+
hooks_path: /home/git/share/gitolite/hooks/
+
# host: localhost
+
git_user: git
+
upload_pack: true
+
receive_pack: true
+
# port: 22
+
</nowiki>}}
+
  
*{{ic|admin_uri}}: Do not change it. Leave as is.
+
$ chown -R git log/
*{{ic|base_path}}: The path where gitolite's repositories reside. If the repositories directory is different than the default one, change it here.
+
$ chown -R git tmp/
*{{ic|hooks_path}}: change default setting to /home/git/share/gitolite/hooks/
+
$ chmod -R u+rwX  log/
*{{ic|host}}: Should point to your FQDN.
+
$ chmod -R u+rwX  tmp/
*{{ic|git_user}}: Name of the git user we created.
+
*{{ic|upload_pack}}:
+
*{{ic|receive_pack}}:
+
  
*{{ic|port}}: ssh port which git should use. Default one is 22. If you want to change it for safety reasons, do not forget to also add the port number to {{ic|.ssh/config}}.
+
Create directory for satellites:
 +
 +
$ mkdir /home/git/gitlab-satellites
  
{{hc|/home/gitlab/gitlab/.ssh/config|<nowiki>
+
Create directories for sockets/pids and make sure GitLab can write to them:
Host localhost
+
Port 5000
+
</nowiki>}}
+
  
====Git settings====
+
$ mkdir tmp/{pids,sockets}
 +
$ chmod -R u+rwX  tmp/{pids,sockets}
  
{{hc|/home/gitlab/gitlab/config/gitlab.yml|<nowiki>
+
Create the {{ic|public/uploads}} directory otherwise backup will fail:
path: /usr/bin/git
+
git_max_size: 5242880 # 5.megabytes
+
git_timeout: 10
+
</nowiki>}}
+
  
*{{ic|git_max_size}}: Max size of git objects like commits, in bytes,.This value can be increased if you have very large commits.
+
$ mkdir public/uploads
*{{ic|git_timeout}}: git timeout to read commit, in seconds.
+
$ chmod -R u+rwX  public/uploads
  
===Database selection===
+
Copy the example Puma config and edit to your liking:
  
SQLite support in Gitlab is now deprecated. See [https://github.com/gitlabhq/gitlabhq/pull/2093 this bug report].
+
$ cp config/puma.rb.example config/puma.rb
  
====MySQL====
+
Configure Git global settings for git user, useful when editing via web. Edit {{ic|user.email}} according to what is set in {{ic|gitlab.yml}}:
  
[[pacman|Install]] {{Pkg|mysql}} from the [[official repositories]] and start the [[daemon]]. Create the database and do not forget to replace {{ic|your_password_here}} with a real one.
+
$ git config --global user.name "GitLab"
  # mysql -u root -p
+
  $ git config --global user.email "gitlab@localhost"
+
mysql> create database gitlabhq_production;
+
mysql> create user 'gitlab'@'localhost' identified by 'your_password_here';
+
mysql> grant all privileges on gitlabhq_production.* to 'gitlab'@'localhost' with grant option;
+
mysql> exit;
+
  
Copy the example configuration file and make sure to update username/password in {{ic|config/database.yml}} at production section:
+
Configure GitLab database settings:
# sudo -u gitlab cp config/database.yml.mysql config/database.yml
+
  
===Install gems===
+
* MariaDB:
This could take a while as it installs all required libraries.
+
$ cp config/database.yml.mysql config/database.yml
  
# cd /home/gitlab/gitlab
+
* PostgreSQL:
  # export PATH=/home/gitlab/bin:$PATH
+
  $ cp config/database.yml.postgresql config/database.yml
# sudo -u gitlab -H bundle install --deployment
+
  
{{Note|1= Using "--without development test" in bundle command line will ignore required packages for database backup and restore }}
+
Make sure to update {{ic|username}}/{{ic|password}} in {{ic|config/database.yml}}.
  
===Start redis server===
 
  
Start the [[daemon]]. If you are using {{Pkg| initscripts}} you might want to add {{ic|redis}} to your {{ic|DAEMONS}} array in {{ic|rc.conf}}.
+
===Install gems===
  
{{Note|redis might already be running, causing a FAIL message to appear. Check if it is already running with {{ic|rc.d list redis}}.}}
+
{{Tip| If you do not want to download any gem documentation, add {{ic|gem: --no-rdoc --no-ri}} to {{ic|/home/git/.gemrc}}. Be sure to add it as the {{ic|git}} user in order to acquire the appropriate permissions.}}
 +
{{Note|See bug #[https://bugs.archlinux.org/task/33327 33327] for about system-wide gems. As a temporary solution the following packages will be installed as {{ic|git}} user, make sure {{ic|/home/git/.gemrc}} contains {{ic|gem: ... --user-install}}. And then add the {{ic|bin}} path to the {{ic|PATH}} variable like so {{ic|1=export PATH="$PATH:~/.gem/ruby/2.0.0/bin"}}.}}
  
If you have switched to [[systemd]], there is a service file included in the official package. See [[daemon]] how to enable it.
+
Install {{ic|bundler}} and {{ic|charlock_holmes}} under {{ic|/git/home/.gem/}} (normally system wide via sudo):
  
===Populate the database===
+
# su - git
 +
$ gem install charlock_holmes --version '0.6.9.4'
 +
$ gem install bundler
  
# sudo -u gitlab bundle exec rake gitlab:app:setup RAILS_ENV=production
+
Install gems from Gemfile:
  
===Setup gitlab hooks===
+
$ cd gitlab/
  
# cp ./lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive
+
{{Note|When executing the below and you recieve `Could not verify the SSL certificate for https://rubygems.org/` see bug #[https://github.com/gitlabhq/gitlabhq/issues/4095 GitHub-4095] most likely because you're behind a proxy that tries to inject a local certificate for SSL domains in order to verify its content}}
# chown git:git /home/git/.gitolite/hooks/common/post-receive
+
  
===Check status===
+
If you used MariaDB:
  
With the following commands we check if the steps we followed so far are configured properly. Before running the first command you must edit {{ic|/home/gitlab/gitlab/lib/tasks/gitlab/info.rake}}. The script cannot determine OS version; simply replace {{ic|os_name.squish!}} with {{ic|os_name &#61; "Arch Linux"}}.
+
$ bundle install --deployment --without development test postgres
  
# sudo -u gitlab -H bundle exec rake gitlab:env:info RAILS_ENV=production
+
If you used PostgreSQL:
# sudo -u gitlab -H bundle exec rake gitlab:check RAILS_ENV=production
+
  
{{hc|Example output|
+
$ bundle install --deployment --without development test mysql
System information
+
System:        Arch Linux
+
Current User:  gitlab
+
Using RVM:      no
+
Ruby Version:  1.9.3p362
+
Gem Version:    1.8.23
+
Bundler Version:1.2.3
+
Rake Version:  10.0.1
+
  
GitLab information
+
{{Note|1= Using {{ic|--without group_name}} in bundle command line will ignore required packages for the mentioned groups.}}
Version:        4.0.0
+
Revision:      8ef7b9b
+
Directory:      /home/gitlab/gitlab
+
DB Adapter:    mysql2
+
URL:            <nowiki>http://example.com</nowiki>
+
HTTP Clone URL: <nowiki>http://example.com/some-project.git</nowiki>
+
SSH Clone URL:  git@example.com:some-project.git
+
Using LDAP:    no
+
Using Omniauth: no
+
  
Gitolite information
+
===Initialize Database===
Version:        v3.04-4-g4524f01
+
Admin URI:      git@example.com:gitolite-admin
+
Admin Key:      gitlab
+
Repositories:  /home/git/repositories/
+
Hooks:          /home/git/.gitolite/hooks/
+
Git:            /usr/bin/git
+
  
}}
+
{{Note| Make sure the redis [[daemon]] is enabled and started, otherwise the following command will fail. To check the status and see if it's running execute {{ic|systemctl status redis}}, if it's dead start it as per usual via {{ic|systemctl start redis}}}}
  
===Server testing and resque process===
+
Initialize database and activate advanced features:
 +
$ bundle exec rake gitlab:setup RAILS_ENV=production
  
[http://defunkt.io/resque/ Resque] is a Redis-backed library for creating background jobs, placing those jobs on multiple queues, and processing them later. For the backstory, philosophy, and history of Resque's beginnings, please see this [https://github.com/blog/542-introducing-resque blog post].
+
{{Note|If you recieve a error {{ic|No such file or directory - /home/git/repositories/root}} then most likely you've changed the default configuration for {{ic|GitLab}} and you'll need to modify all static paths in {{ic|config/gitlab.yml}} and run the above command again to initialize the database!}}
  
Run resque process for processing queue:
+
===Check status===
# sudo -u gitlab bundle exec rake environment resque:work QUEUE=* RAILS_ENV=production BACKGROUND=yes
+
  
or use Gitlab's start script:
+
With the following commands we check if the steps we followed so far are configured properly.  
# sudo -u gitlab ./resque.sh
+
  
{{Note|If you run this as root, {{ic|/home/gitlab/gitlab/tmp/pids/resque_worker.pid}} will be owned by root causing the resque worker not to start via init script on next boot/service restart}}
+
$ bundle exec rake gitlab:env:info RAILS_ENV=production
 +
$ bundle exec rake gitlab:check RAILS_ENV=production
  
Gitlab application can be started with the next command:
+
{{hc|Example output of gitlab:env:info|
# sudo -u gitlab bundle exec rails s -e production
+
System information
 +
System: Arch Linux
 +
Current User: git
 +
Using RVM: yes
 +
RVM Version: 1.20.3
 +
Ruby Version: 2.0.0p0
 +
Gem Version: 2.0.0
 +
Bundler Version:1.3.5
 +
Rake Version: 10.0.4
  
Open {{ic|localhost:3000}} with your favorite browser and you should see Gitlab's sign in page. In case you missed it, the default login/password are:
+
GitLab information
 +
Version: 5.2.0.pre
 +
Revision: 4353bab
 +
Directory: /home/git/gitlab
 +
DB Adapter: mysql2
 +
URL: http://gitlab.arch
 +
HTTP Clone URL: http://gitlab.arch/some-project.git
 +
SSH Clone URL: git@gitlab.arch:some-project.git
 +
Using LDAP: no
 +
Using Omniauth: no
  
login.........admin@local.host
+
GitLab Shell
password......5iveL!fe
+
Version: 1.4.0
 +
Repositories: /home/git/repositories/
 +
Hooks: /home/git/gitlab-shell/hooks/
 +
Git: /usr/bin/git
 +
}}
  
Since this is a thin web server, it is only for test purposes. You may close it with {{Keypress|Ctrl+c}}. Follow instructions below to make Gitlab run with a real web server.
+
{{Note| {{ic|gitlab:check}} will complain about missing initscripts. Don't worry, we will use ArchLinux' [[systemd]] to manage server start (which GitLab does not recognize).}}
  
 
==Web server configuration==
 
==Web server configuration==
Line 305: Line 257:
  
 
===Unicorn only===
 
===Unicorn only===
 +
 +
{{Note|As of GitLab 5.1 Unicorn is no longer the default server as it got replaced by Puma. You can therefore ignore this section.}}
  
 
Edit {{ic|/home/gitlab/gitlab/config/unicorn.rb}} uncomment:
 
Edit {{ic|/home/gitlab/gitlab/config/unicorn.rb}} uncomment:
Line 392: Line 346:
  
 
====Configure Unicorn====
 
====Configure Unicorn====
 +
 +
{{Note|If the default path is not {{ic|/home/git}} for your installation, change the below path accordingly}}
  
 
As the official installation guide instructs, copy the unicorn configuration file:
 
As the official installation guide instructs, copy the unicorn configuration file:
  # sudo -u gitlab -H cp /home/gitlab/gitlab/config/unicorn.rb.example /home/gitlab/gitlab/config/unicorn.rb
+
  # sudo -u git -H cp /home/git/gitlab/config/unicorn.rb.example /home/git/gitlab/config/unicorn.rb
  
 
Now edit {{ic|config/unicorn.rb}} and add a listening port by uncommenting the following line:
 
Now edit {{ic|config/unicorn.rb}} and add a listening port by uncommenting the following line:
Line 485: Line 441:
 
  # sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D
 
  # sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D
  
==SystemD support==
+
==systemd support==
  
 
Note that you don't need the systemd units to launch shell scripts as suggested by the gitlab authors. Just make sure the ExecStart line points to the full path of the **bundle** executable.  
 
Note that you don't need the systemd units to launch shell scripts as suggested by the gitlab authors. Just make sure the ExecStart line points to the full path of the **bundle** executable.  
  
 
Create:
 
Create:
{{hc|/etc/systemd/system/gitlab.service|<nowiki>
+
{{hc|gitlab.service|<nowiki>
 +
 
 
[Unit]
 
[Unit]
Description=Gitlab Unicorn Rails server
+
Description=GitLab Puma Server
  
 
[Service]
 
[Service]
Type=simple
+
User=git
SyslogIdentifier=gl-unicorn
+
WorkingDirectory=/home/git/gitlab
User=gitlab
+
Environment=RAILS_ENV=production
PIDFile=/home/gitlab/gitlab/tmp/pids/unicorn.pid
+
SyslogIdentifier=gitlab-puma
WorkingDirectory=/home/gitlab/gitlab
+
Type=forking
 
TimeoutStartSec=600
 
TimeoutStartSec=600
 +
PIDFile=/home/git/gitlab/tmp/pids/puma.pid
  
ExecStart=/home/gitlab/bin/bundle exec unicorn_rails -c /home/gitlab/gitlab/config/unicorn.rb -E production -D
+
ExecStart=/usr/bin/bundle exec "puma -C /home/git/gitlab/config/puma.rb -e production"
 
ExecReload=/bin/kill -HUP $MAINPID
 
ExecReload=/bin/kill -HUP $MAINPID
 
ExecStop=/bin/kill -QUIT $MAINPID
 
ExecStop=/bin/kill -QUIT $MAINPID
 +
  
 
[Install]
 
[Install]
 
WantedBy=multi-user.target
 
WantedBy=multi-user.target
</nowiki>}}
+
</nowiki>
 
+
}}
{{hc|/etc/systemd/system/resque.service|<nowiki>
+
  
 +
{{hc|gitlab-sidekiq.service|<nowiki>
 
[Unit]
 
[Unit]
Description=Gitlab Resque
+
Description=GitLab Sidekiq Server
  
 
[Service]
 
[Service]
Type=simple
+
User=git
SyslogIdentifier=gl-resque
+
WorkingDirectory=/home/git/gitlab
User=gitlab
+
Environment=RAILS_ENV=production
PIDFile=/home/gitlab/gitlab/tmp/pids/resque_worker.pid
+
SyslogIdentifier=gitlab-sidekiq
WorkingDirectory=/home/gitlab/gitlab
+
Type=forking
TimeoutStartSec=600
+
PIDFile=/home/git/gitlab/tmp/pids/sidekiq.pid
  
ExecStart=/home/gitlab/bin/bundle exec rake environment resque:work QUEUE=post_receive,mailer,system_hook RAILS_ENV=production PIDFILE=tmp/pids/resque_worker.pid
+
 
ExecReload=/bin/kill -HUP $MAINPID
+
ExecStart=/usr/bin/bundle exec rake sidekiq:start
ExecStop=/bin/kill -QUIT $MAINPID
+
ExecStop=/usr/bin/bundle exec rake sidekiq:stop
  
 
[Install]
 
[Install]
WantedBy=multi-user.target
+
WantedBy=multi-user.target</nowiki>
</nowiki>
+
 
}}
 
}}
  
Line 563: Line 521:
 
===Backup and restore===
 
===Backup and restore===
  
Create a backup of the gitlab system.
+
Create a backup of the gitlab system:
# cd /home/gitlab/gitlab
+
  # sudo -u gitlab -H rake RAILS_ENV=production gitlab:backup:create
  # sudo -u gitlab rake gitlab:app:backup_create
+
  
Restore a previously created backup.
+
Restore the previously created backup file {{ic|/home/gitlab/gitlab/tmp/backups/20130125_11h35_1359131740_gitlab_backup.tar}}:
# cd /home/gitlab/gitlab
+
  # sudo -u gitlab -H rake RAILS_ENV=production gitlab:backup:restore BACKUP=/home/gitlab/gitlab/tmp/backups/20130125_11h35_1359131740
  # sudo -u gitlab rake gitlab:app:backup_restore
+
  
{{Note| Backup folder is set in {{ic|conig.yml}}. Check [[#Application_specific_settings]].}}
+
{{Note| Backup folder is set in {{ic|config/gitlab.yml}}. GitLab backup and restore is documented [https://github.com/gitlabhq/gitlabhq/blob/master/doc/raketasks/backup_restore.md here].}}
  
 
===Update Gitlab===
 
===Update Gitlab===
Line 589: Line 545:
 
Finally restore old data.
 
Finally restore old data.
 
  # sudo -u gitlab bundle exec rake db:data:load RAILS_ENV=production
 
  # sudo -u gitlab bundle exec rake db:data:load RAILS_ENV=production
 +
 +
===Running GitLab with rvm===
 +
 +
To run gitlab with rvm first you have to set up an rvm:
 +
 +
  curl -L https://get.rvm.io | bash -s stable --ruby=1.9.3
 +
 +
{{Note|Version 1.9.3 is currently recommended to avoid some compatibility issues.}}
 +
 +
For the complete installation you will want to be the final user (e.g. {{ic|git}}) so make sure to switch to this user and activate your rvm:
 +
 +
  su - git
 +
  source "$HOME/.rvm/scripts/rvm"
 +
 +
Then continue with the installation instructions from above. However, the systemd scripts will not work this way, because the environment for the rvm is not activated. The recommendation here is to create to separate shell scripts for {{ic|puma}} and {{ic|sidekiq}} to activate the environment and then start the service:
 +
 +
{{hc|gitlab.sh|<nowiki>
 +
#!/bin/sh
 +
source `/home/git/.rvm/bin/rvm 1.9.3 do rvm env --path`
 +
RAILS_ENV=production bundle exec puma -C "/home/git/gitlab/config/puma.rb"</nowiki>
 +
}}
 +
 +
{{hc|sidekiq.sh|<nowiki>
 +
#!/bin/sh
 +
source `/home/git/.rvm/bin/rvm 1.9.3 do rvm env --path`
 +
case $1 in
 +
    start)
 +
        bundle exec rake sidekiq:start RAILS_ENV=production
 +
        ;;
 +
    stop)
 +
        bundle exec rake sidekiq:stop RAILS_ENV=production
 +
        ;;
 +
    *)
 +
        echo "Usage $0 {start|stop}"
 +
esac
 +
</nowiki>}}
 +
 +
Then modify the above systemd files so they use these scripts. Modify the given lines:
 +
 +
{{hc|gitlab.service|<nowiki>
 +
ExecStart=/home/git/bin/gitlab.sh
 +
</nowiki>}}
 +
{{hc|sidekiq.service|<nowiki>
 +
ExecStart=/home/git/bin/sidekiq.sh start
 +
ExecStop=/home/git/bin/sidekiq.sh stop
 +
</nowiki>}}
  
 
==Troubleshooting==
 
==Troubleshooting==

Revision as of 14:26, 21 July 2013

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary end Gitlab is a free git repository management application based on Ruby on Rails. It is distributed under the MIT License and its source code can be found on Github. It is a very active project with a monthly release cycle and ideal for businesses that want to keep their code private. Consider it as a self hosted Github but open source. You can try a demo here.

Note: Throughout the article, sudo is heavily used, assuming that the user that is running the commands is root or someone with equal privileges. There is no need to edit the sudoers file whatsoever. It is only used to change to the appropriate user. For more info read man sudo.

Required packages

Install the packages below as they are needed to proceed further.

# pacman -Syu --noconfirm --needed sudo base-devel zlib libyaml openssl gdbm readline ncurses libffi curl git openssh redis libxml2 libxslt icu python2
Note: In order to receive mail notifications, make sure to install a mail server. By default, Archlinux does not ship with one. The recommended mail server is postfix, but you can use others such as SSMTP, msmtp, sendmail, etc.

PKGBUILDs for Gitlab and Gitlab-shell

There are some (not fully working) PKGBUILDs available to create installable packages:

Gitlab PKGBUILD on GitHub.com

Gitlab-shell PKGBUILD on GitHub.com

(Please extend/rename this section with further instructions)

Ruby

GitLab supports ruby >= 1.9.3 and 2.0.0, but some dependencies gems work better with ruby 1.9.3. Install it from the official repositories and if you bump into any trouble use rvm with latest ruby 1.9.3.

Note: If you want to use rvm be sure to check out Gitlab#Running GitLab with rvm before starting with the installation

User accounts

Add git user:

# useradd -U -m -d /home/git git
Note: git user must have its initial group set to git (not users). If the initial group is not git, then all files created by the git user will be owned by git:users which will prevent GitLab from showing you a newly created repository (it will get stucked at the page where it tells you how to push to the new repository).

gitlab-shell

GitLab Shell is an ssh access and repository management software developed specially for GitLab.

Login as git:

# su - git

Clone gitlab shell:

$ git clone https://github.com/gitlabhq/gitlab-shell.git
$ cd gitlab-shell

Switch to the right version:

$ git checkout v1.4.0

Edit config.yml and replace gitlab_url with something like http://domain.com/:

$ cp config.yml.example config.yml

Setup the environment:

$ ./bin/install

You should see this result:

Example output
mkdir -p /home/git/repositories: true
mkdir -p /home/git/.ssh: true
chmod 700 /home/git/.ssh: true
touch /home/git/.ssh/authorized_keys: true
chmod 600 /home/git/.ssh/authorized_keys: true
chmod -R ug+rwX,o-rwx /home/git/repositories: true
find /home/git/repositories -type d -print0 | xargs -0 chmod g+s: true

Database selection

Currently GitLab supports MySQL and PostgreSQL. MariaDB has not been officially tested but it works just fine.

MariaDB

Install mariadb and libmariadbclient from the official repositories and start the daemon. Create the database and do not forget to replace your_password_here with a real one.

# su - git
$ mysql -u root -p
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'your_password_here';
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
mysql> \q

Try connecting to the new database with the new user:

$ mysql -u gitlab -p -D gitlabhq_production

PostgreSQL

Install postgresql and libpqxx from the official repositories. Follow PostgreSQL#Installing_PostgreSQL to set it up and start the daemon.

Login to PostgreSQL and remember to change your_password_here to a real one:

# sudo -u postgres psql -d template1
template1=# CREATE USER git WITH PASSWORD 'your_password_here';
template1=# CREATE DATABASE gitlabhq_production OWNER git;
template1=# \q

Try connecting to the new database with the new user:

# sudo -u git -H psql -d gitlabhq_production

MySQL

If you are still in favor of mysqlAUR, follow the same commands as MariaDB.

Gitlab

Installation

Clone GitLab's repository:

# su - git
$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab
$ cd gitlab
$ git checkout 5-2-stable
Note: You can change 5-2-stable to master if you want the bleeding edge version, but do so with caution! Check github to see what is the latest stable version and replace above accordingly.

Basic configuration

First we need to rename the example file.

$ cp config/gitlab.yml.example config/gitlab.yml

The options are pretty straightforward. Open config/gitlab.yml with your favorite editor and edit where needed. Make sure to change localhost to the fully-qualified domain name of your host serving GitLab where necessary.

Make sure GitLab can write to the log/ and tmp/ directories:

$ chown -R git log/
$ chown -R git tmp/
$ chmod -R u+rwX  log/
$ chmod -R u+rwX  tmp/

Create directory for satellites:

$ mkdir /home/git/gitlab-satellites

Create directories for sockets/pids and make sure GitLab can write to them:

$ mkdir tmp/{pids,sockets}
$ chmod -R u+rwX  tmp/{pids,sockets}

Create the public/uploads directory otherwise backup will fail:

$ mkdir public/uploads
$ chmod -R u+rwX  public/uploads

Copy the example Puma config and edit to your liking:

$ cp config/puma.rb.example config/puma.rb

Configure Git global settings for git user, useful when editing via web. Edit user.email according to what is set in gitlab.yml:

$ git config --global user.name "GitLab"
$ git config --global user.email "gitlab@localhost"

Configure GitLab database settings:

  • MariaDB:
$ cp config/database.yml.mysql config/database.yml
  • PostgreSQL:
$ cp config/database.yml.postgresql config/database.yml

Make sure to update username/password in config/database.yml.


Install gems

Tip: If you do not want to download any gem documentation, add gem: --no-rdoc --no-ri to /home/git/.gemrc. Be sure to add it as the git user in order to acquire the appropriate permissions.
Note: See bug #33327 for about system-wide gems. As a temporary solution the following packages will be installed as git user, make sure /home/git/.gemrc contains gem: ... --user-install. And then add the bin path to the PATH variable like so export PATH="$PATH:~/.gem/ruby/2.0.0/bin".

Install bundler and charlock_holmes under /git/home/.gem/ (normally system wide via sudo):

# su - git
$ gem install charlock_holmes --version '0.6.9.4'
$ gem install bundler

Install gems from Gemfile:

$ cd gitlab/
Note: When executing the below and you recieve `Could not verify the SSL certificate for https://rubygems.org/` see bug #GitHub-4095 most likely because you're behind a proxy that tries to inject a local certificate for SSL domains in order to verify its content

If you used MariaDB:

$ bundle install --deployment --without development test postgres

If you used PostgreSQL:

$ bundle install --deployment --without development test mysql
Note: Using --without group_name in bundle command line will ignore required packages for the mentioned groups.

Initialize Database

Note: Make sure the redis daemon is enabled and started, otherwise the following command will fail. To check the status and see if it's running execute systemctl status redis, if it's dead start it as per usual via systemctl start redis

Initialize database and activate advanced features:

$ bundle exec rake gitlab:setup RAILS_ENV=production
Note: If you recieve a error No such file or directory - /home/git/repositories/root then most likely you've changed the default configuration for GitLab and you'll need to modify all static paths in config/gitlab.yml and run the above command again to initialize the database!

Check status

With the following commands we check if the steps we followed so far are configured properly.

$ bundle exec rake gitlab:env:info RAILS_ENV=production
$ bundle exec rake gitlab:check RAILS_ENV=production
Example output of gitlab:env:info
System information
System:		Arch Linux
Current User:	git
Using RVM:	yes
RVM Version:	1.20.3
Ruby Version:	2.0.0p0
Gem Version:	2.0.0
Bundler Version:1.3.5
Rake Version:	10.0.4

GitLab information
Version:	5.2.0.pre
Revision:	4353bab
Directory:	/home/git/gitlab
DB Adapter:	mysql2
URL:		http://gitlab.arch
HTTP Clone URL:	http://gitlab.arch/some-project.git
SSH Clone URL:	git@gitlab.arch:some-project.git
Using LDAP:	no
Using Omniauth:	no

GitLab Shell
Version:	1.4.0
Repositories:	/home/git/repositories/
Hooks:		/home/git/gitlab-shell/hooks/
Git:		/usr/bin/git
Note: gitlab:check will complain about missing initscripts. Don't worry, we will use ArchLinux' systemd to manage server start (which GitLab does not recognize).

Web server configuration

Unicorn only

Note: As of GitLab 5.1 Unicorn is no longer the default server as it got replaced by Puma. You can therefore ignore this section.

Edit /home/gitlab/gitlab/config/unicorn.rb uncomment:

listen 8080 # listen to port 8080 on all TCP interfaces

Create /etc/rc.d/unicorn-gitlab.

#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions


PID=`pidof -o %PPID /usr/bin/ruby`
case "$1" in
  start)
    stat_busy "Starting unicorn"
    [ -z "$PID" ] && sudo -u gitlab bash  -c  "source /home/gitlab/.bash_profile && cd /home/gitlab/gitlab/ && bundle exec unicorn_rails -c config/unicorn.rb -E production -D"
    if [ $? -gt 0 ]; then
      stat_fail
    else
      add_daemon unicorn
      stat_done
    fi
    ;;
  stop)
    stat_busy "Stopping unicorn"
    [ ! -z "$PID" ]  && kill $PID &> /dev/null
    if [ $? -gt 0 ]; then
      stat_fail
    else
      rm_daemon unicorn
      stat_done
    fi
    ;;
  restart)
    $0 stop
    sleep 1
    $0 start
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"
esac
exit 0

Start unicorn:

# /etc/rc.d/unicorn-gitlab start

Test it http://localhost:8080

Add it to DAEMONS array in /etc/rc.conf

Redirect http port to unicorn server

# iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

And test again, now http://localhost

Nginx and unicorn

Install nginx from the official repositories.

Run these commands to setup nginx:

# wget https://raw.github.com/gitlabhq/gitlab-recipes/master/nginx/gitlab -P /etc/nginx/sites-available/
# ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab 

Edit /etc/nginx/sites-enabled/gitlab and change YOUR_SERVER_IP and YOUR_SERVER_FQDN to the IP address and fully-qualified domain name of the host serving Gitlab. As you can see nginx needs to access /home/gitlab/gitlab/tmp/sockets/gitlab.socket socket file. You have to be able to run sudo -u http ls /home/gitlab/gitlab/tmp/sockets/gitlab.socket successfully. Otherwise setup access to the directory:

# chgrp http /home/gitlab
# chmod u=rwx,g=rx,o= /home/gitlab

Restart gitlab.service, resque.service and nginx.

Unicorn is an HTTP server for Rack applications designed to only serve fast clients on low-latency, high-bandwidth connections and take advantage of features in Unix/Unix-like kernels. First we rename the example file and then we start 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

Apache and unicorn

Install apache from the official repositories.

Configure Unicorn

Note: If the default path is not /home/git for your installation, change the below path accordingly

As the official installation guide instructs, copy the unicorn configuration file:

# sudo -u git -H cp /home/git/gitlab/config/unicorn.rb.example /home/git/gitlab/config/unicorn.rb

Now edit config/unicorn.rb and add a listening port by uncommenting the following line:

listen "127.0.0.1:8080"
Tip: You can set a custom port if you want. Just remember to also include it in Apache's virtual host. See below.

Create a virtual host for Gitlab

Create a configuration file for Gitlab’s virtual host and insert the lines below adjusted accordingly. For the ssl section see LAMP#SSL. If you do not need it, remove it. Notice that the SSL virtual host needs a specific IP instead of generic. Also if you set a custom port for Unicorn, do not forget to set it at the BalanceMember line.

# mkdir -pv /etc/httpd/conf/vhosts/
/etc/httpd/conf/vhosts/gitlab
<VirtualHost *:80>
  ServerName gitlab.myserver.com
  ServerAlias www.gitlab.myserver.com
  DocumentRoot /home/gitlab/gitlab/public
  ErrorLog /var/log/httpd/gitlab_error_log
  CustomLog /var/log/httpd/gitlab_access_log combined

  <Proxy balancer://unicornservers>
      BalancerMember http://127.0.0.1:8080
  </Proxy>

  <Directory /home/gitlab/gitlab/public>
    AllowOverride All
    Options -MultiViews
  </Directory>

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

  ProxyPass /uploads !
  ProxyPass / balancer://unicornservers/
  ProxyPassReverse / balancer://unicornservers/
  ProxyPreserveHost on

   <Proxy *>
      Order deny,allow
      Allow from all
   </Proxy>
</VirtualHost>

<VirtualHost MY_IP:443>
  ServerName gitlab.myserver.com
  ServerAlias www.gitlab.myserver.com
  DocumentRoot /home/gitlab/gitlab/public
  ErrorLog /var/log/httpd/gitlab_error_log
  CustomLog /var/log/httpd/gitlab_access_log combined

  <Proxy balancer://unicornservers>
      BalancerMember http://127.0.0.1:8080
  </Proxy>

  <Directory /home/gitlab/gitlab/public>
    AllowOverride All
    Options -MultiViews
  </Directory>

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

  ProxyPass /uploads !
  ProxyPass / balancer://unicornservers/
  ProxyPassReverse / balancer://unicornservers/
  ProxyPreserveHost on

   <Proxy *>
      Order deny,allow
      Allow from all
   </Proxy>

  SSLEngine on
  SSLCertificateFile /home/gitlab/gitlab/ssl.cert
  SSLCertificateKeyFile /home/gitlab/gitlab/ssl.key
</VirtualHost>

Enable host and start unicorn

Enable your Gitlab virtual host and reload Apache:

/etc/httpd/conf/httpd.conf
Include conf/vhosts/gitlab

Finally start unicorn:

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

systemd support

Note that you don't need the systemd units to launch shell scripts as suggested by the gitlab authors. Just make sure the ExecStart line points to the full path of the **bundle** executable.

Create:

gitlab.service

[Unit]
Description=GitLab Puma Server

[Service]
User=git
WorkingDirectory=/home/git/gitlab
Environment=RAILS_ENV=production
SyslogIdentifier=gitlab-puma
Type=forking
TimeoutStartSec=600
PIDFile=/home/git/gitlab/tmp/pids/puma.pid

ExecStart=/usr/bin/bundle exec "puma -C /home/git/gitlab/config/puma.rb -e production"
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -QUIT $MAINPID


[Install]
WantedBy=multi-user.target

gitlab-sidekiq.service
[Unit]
Description=GitLab Sidekiq Server

[Service]
User=git
WorkingDirectory=/home/git/gitlab
Environment=RAILS_ENV=production
SyslogIdentifier=gitlab-sidekiq
Type=forking
PIDFile=/home/git/gitlab/tmp/pids/sidekiq.pid


ExecStart=/usr/bin/bundle exec rake sidekiq:start
ExecStop=/usr/bin/bundle exec rake sidekiq:stop

[Install]
WantedBy=multi-user.target

Also see: https://github.com/gitlabhq/gitlab-recipes/issues/14

Useful Tips

Hook into /var

 sudo mkdir -m700 /var/log/gitlab /var/tmp/gitlab
 sudo chown gitlab:gitlab /var/log/gitlab /var/tmp/gitlab
 sudo -u gitlab -i
 cd ~/gitlab
 d=log; mv $d/* /var/$d/gitlab; rm -f $d/.gitkeep; rm -r $d && ln -s /var/$d/gitlab $d
 d=tmp; mv $d/* /var/$d/gitlab; rm -f $d/.gitkeep; rm -r $d && ln -s /var/$d/gitlab $d

Hidden options

Go to Gitlab's home directory

# cd /home/gitlab/gitlab

and run

# rake -T | grep gitlab

These are the options so far:

rake gitlab:app:backup_create      # GITLAB | Create a backup of the gitlab system
rake gitlab:app:backup_restore     # GITLAB | Restore a previously created backup
rake gitlab:app:enable_automerge   # GITLAB | Enable auto merge
rake gitlab:app:setup              # GITLAB | Setup production application
rake gitlab:app:status             # GITLAB | Check gitlab installation status
rake gitlab:gitolite:update_hooks  # GITLAB | Rewrite hooks for repos
rake gitlab:gitolite:update_keys   # GITLAB | Rebuild each key at gitolite config
rake gitlab:gitolite:update_repos  # GITLAB | Rebuild each project at gitolite config
rake gitlab:test                   # GITLAB | Run both cucumber & rspec

Backup and restore

Create a backup of the gitlab system:

# sudo -u gitlab -H rake RAILS_ENV=production gitlab:backup:create

Restore the previously created backup file /home/gitlab/gitlab/tmp/backups/20130125_11h35_1359131740_gitlab_backup.tar:

# sudo -u gitlab -H rake RAILS_ENV=production gitlab:backup:restore BACKUP=/home/gitlab/gitlab/tmp/backups/20130125_11h35_1359131740
Note: Backup folder is set in config/gitlab.yml. GitLab backup and restore is documented here.

Update Gitlab

When a new version is out follow the instructions at Github wiki. A new release is out every 22nd of a month.

Migrate from sqlite to mysql

Get latest code as described in #Update_Gitlab. Save data.

# cd /home/gitlab/gitlab
# sudo -u gitlab bundle exec rake db:data:dump RAILS_ENV=production

Follow #Mysql instructions and then setup the database.

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

Finally restore old data.

# sudo -u gitlab bundle exec rake db:data:load RAILS_ENV=production

Running GitLab with rvm

To run gitlab with rvm first you have to set up an rvm:

 curl -L https://get.rvm.io | bash -s stable --ruby=1.9.3
Note: Version 1.9.3 is currently recommended to avoid some compatibility issues.

For the complete installation you will want to be the final user (e.g. git) so make sure to switch to this user and activate your rvm:

 su - git
 source "$HOME/.rvm/scripts/rvm"

Then continue with the installation instructions from above. However, the systemd scripts will not work this way, because the environment for the rvm is not activated. The recommendation here is to create to separate shell scripts for puma and sidekiq to activate the environment and then start the service:

gitlab.sh
#!/bin/sh
source `/home/git/.rvm/bin/rvm 1.9.3 do rvm env --path`
RAILS_ENV=production bundle exec puma -C "/home/git/gitlab/config/puma.rb"
sidekiq.sh
#!/bin/sh
source `/home/git/.rvm/bin/rvm 1.9.3 do rvm env --path`
case $1 in
    start)
        bundle exec rake sidekiq:start RAILS_ENV=production
        ;;
    stop)
        bundle exec rake sidekiq:stop RAILS_ENV=production
        ;;
    *)
        echo "Usage $0 {start|stop}"
esac

Then modify the above systemd files so they use these scripts. Modify the given lines:

gitlab.service
ExecStart=/home/git/bin/gitlab.sh
sidekiq.service
ExecStart=/home/git/bin/sidekiq.sh start
ExecStop=/home/git/bin/sidekiq.sh stop

Troubleshooting

Sometimes things may not work as expected. Be sure to visit the Trouble Shooting Guide.

See also