https://wiki.archlinux.org/api.php?action=feedcontributions&user=Spoj&feedformat=atomArchWiki - User contributions [en]2024-03-28T10:27:49ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=GitLab&diff=243113GitLab2013-01-06T18:32:10Z<p>Spoj: /* Install gems */</p>
<hr />
<div>[[Category:Version Control System]]<br />
{{Article summary start}}<br />
{{Article summary text|This page gives guidelines for the installation and configuration of Gitlab on Archlinux.}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Gitolite}}<br />
{{Article summary wiki|Ruby on Rails}}<br />
{{Article summary end}}<br />
[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].<br />
<br />
{{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}}.}}<br />
<br />
==Required packages==<br />
<br />
Install the packages below as they are needed to proceed further.<br />
<br />
# pacman -Syu --needed sudo git wget curl checkinstall libxml2 libxslt mysql++ base-devel zlib icu redis openssh python2 python2-pygments python2-pip libyaml ruby<br />
<br />
==Create user accounts==<br />
<br />
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.<br />
<br />
# usermod -d /home/git git<br />
# mkdir -pv /home/git<br />
# chown -R git:git /home/git<br />
# useradd --user-group --shell /bin/bash --comment 'gitlab system' --create-home --groups git gitlab<br />
<br />
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.<br />
<br />
==Gitolite==<br />
<br />
<br />
Clone the gitolite repository from Gitlab's fork. Note that it's version 3.<br />
# cd /home/git<br />
# sudo -H -u git git clone -b gl-v304 https://github.com/gitlabhq/gitolite.git /home/git/gitolite<br />
<br />
Generate Gitlab's ssh key to be used with gitolite:<br />
<br />
{{ic|<nowiki> # sudo -H -u gitlab ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa</nowiki>}}<br />
<br />
Add the following path to git's {{ic|.bash_profile}}:<br />
# sudo -u git sh -c 'echo "export PATH=/home/git/bin:$PATH" >> /home/git/.bash_profile'<br />
# sudo -u git sh -c 'mkdir /home/git/bin'<br />
# sudo -u git -H sh -c "export PATH=/home/git/bin:$PATH; /home/git/gitolite/install -ln"<br />
<br />
Copy Gitlab's public key to gitolite's home and change permissions:<br />
# cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub<br />
# chmod 0444 /home/git/gitlab.pub<br />
<br />
Install gitolite:<br />
# sudo -u git -H sh -c "export PATH=/home/git/bin:$PATH; /home/git/gitolite/src/gitolite setup -pk /home/git/gitlab.pub"<br />
<br />
{{hc|Example output|<br />
creating gitolite-admin...<br />
Initialized empty Git repository in /home/git/repositories/gitolite-admin.git/<br />
creating testing...<br />
Initialized empty Git repository in /home/git/repositories/testing.git/<br />
[master (root-commit) 012fdf5] start<br />
2 files changed, 6 insertions(+)<br />
create mode 100644 conf/gitolite.conf<br />
create mode 100644 keydir/gitlab.pub<br />
}}<br />
<br />
Change permissions:<br />
# chmod -R g+rwX /home/git/repositories/<br />
# chmod g+x /home/git<br />
# chown -R git:git /home/git/repositories/<br />
<br />
{{Note| The next step is '''important''' to succeed. If not, do not try to proceed any further.}}<br />
<br />
Add Gitlab's ssh key to known hosts:<br />
# sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin<br />
<br />
Answer yes. At this point you should be able to clone the gitolite-admin repository. <br />
<br />
{{hc|Example output|<br />
Cloning into '/tmp/gitolite-admin'...<br />
The authenticity of host 'localhost (::1)' can't be established.<br />
ECDSA key fingerprint is 5a:50:69:47:1f:1c:61:79:08:a8:2c:fa:a1:fb:48:bf.<br />
Are you sure you want to continue connecting (yes/no)? yes<br />
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.<br />
remote: Counting objects: 6, done.<br />
remote: Compressing objects: 100% (4/4), done.<br />
Receiving objects: 100% (6/6), 712 bytes, done.<br />
remote: Total 6 (delta 0), reused 0 (delta 0)<br />
}}<br />
<br />
If the repository is cloned successfully, it is safe to remove it:<br />
# rm -rf /tmp/gitolite-admin<br />
<br />
==Gitlab==<br />
<br />
===Installation===<br />
<br />
{{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.}}<br />
<br />
Add [[ruby]] to Gitlab's {{ic|PATH}}:<br />
# sudo -u gitlab -H sh -c 'echo "export PATH=$(ruby -rubygems -e "puts Gem.user_dir")/bin:$PATH" >> /home/gitlab/.bashrc'<br />
<br />
Install bundler and charlock_holmes:<br />
# sudo -u gitlab -H gem install charlock_holmes --version '0.6.8'<br />
# sudo -u gitlab -H gem install bundler<br />
<br />
{{Note|When installing charlock_holmes don't mind any errors that might occur, that's ''normal''.}}<br />
<br />
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:<br />
# sudo -u gitlab -H mkdir /home/gitlab/bin<br />
# sudo -u gitlab -H sh -c "ln -s \$(ruby -rubygems -e 'puts Gem.user_dir')/bin/bundle /home/gitlab/bin/"<br />
# sudo -u gitlab -H sh -c 'echo "export PATH=/home/gitlab/bin:$PATH" >> /home/gitlab/.bashrc'<br />
<br />
<br />
Clone Gitlab's stable repository:<br />
# cd /home/gitlab<br />
# sudo -H -u gitlab git clone -b stable git://github.com/gitlabhq/gitlabhq.git gitlab<br />
# cd gitlab<br />
# sudo -u gitlab mkdir -pv tmp<br />
<br />
===Basic configuration===<br />
<br />
First we need to rename the example file.<br />
<br />
# sudo -u gitlab cp config/gitlab.yml.example config/gitlab.yml<br />
<br />
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.<br />
<br />
====Web application specific settings====<br />
<br />
{{hc|/home/gitlab/gitlab/config/gitlab.yml|<nowiki><br />
host: myhost.example.com<br />
port: 80<br />
https: false<br />
</nowiki>}}<br />
<br />
*{{ic|host}}: Enter your [[Wikipedia:Fully_qualified_domain_name|Fully Qualified Domain Name]].<br />
<br />
====Email used for notification====<br />
<br />
{{hc|/home/gitlab/gitlab/config/gitlab.yml|<nowiki><br />
from: notify@example.com<br />
</nowiki>}}<br />
<br />
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:<br />
<br />
# ls /usr/sbin/sendmail<br />
<br />
If you get a ‘cannot access /usr/bin/sendmail’ then install one of the above packages.<br />
<br />
====Application specific settings====<br />
<br />
{{hc|/home/gitlab/gitlab/config/gitlab.yml|<nowiki><br />
default_projects_limit: 10<br />
# backup_path: "/vol/backups" # default: Rails.root + backups/<br />
# backup_keep_time: 604800 # default: 0 (forever) (in seconds)<br />
</nowiki>}}<br />
<br />
*{{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.<br />
*{{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.<br />
*{{ic|backup_keep_time}}: Time to preserve backups. The default option is to never be deleted.<br />
<br />
Also check [[#Backup_and_restore| Backup and restore]].<br />
<br />
====Git Hosting configuration====<br />
<br />
{{hc|/home/gitlab/gitlab/config/gitlab.yml|<nowiki><br />
admin_uri: git@localhost:gitolite-admin<br />
base_path: /home/git/repositories/<br />
hooks_path: /home/git/share/gitolite/hooks/<br />
# host: localhost<br />
git_user: git<br />
upload_pack: true<br />
receive_pack: true<br />
# port: 22<br />
</nowiki>}}<br />
<br />
*{{ic|admin_uri}}: Do not change it. Leave as is.<br />
*{{ic|base_path}}: The path where gitolite's repositories reside. If the repositories directory is different than the default one, change it here.<br />
*{{ic|hooks_path}}: change default setting to /home/git/share/gitolite/hooks/<br />
*{{ic|host}}: Should point to your FQDN.<br />
*{{ic|git_user}}: Name of the git user we created.<br />
*{{ic|upload_pack}}: <br />
*{{ic|receive_pack}}: <br />
<br />
*{{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}}.<br />
<br />
{{hc|/home/gitlab/gitlab/.ssh/config|<nowiki><br />
Host localhost<br />
Port 5000<br />
</nowiki>}}<br />
<br />
====Git settings====<br />
<br />
{{hc|/home/gitlab/gitlab/config/gitlab.yml|<nowiki><br />
path: /usr/bin/git<br />
git_max_size: 5242880 # 5.megabytes<br />
git_timeout: 10<br />
</nowiki>}}<br />
<br />
*{{ic|git_max_size}}: Max size of git objects like commits, in bytes,.This value can be increased if you have very large commits.<br />
*{{ic|git_timeout}}: git timeout to read commit, in seconds.<br />
<br />
===Database selection===<br />
<br />
SQLite support in Gitlab is now deprecated. See [https://github.com/gitlabhq/gitlabhq/pull/2093 this bug report].<br />
<br />
====MySQL====<br />
<br />
[[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.<br />
# mysql -u root -p<br />
<br />
mysql> create database gitlabhq_production;<br />
mysql> create user 'gitlab'@'localhost' identified by 'your_password_here';<br />
mysql> grant all privileges on gitlabhq_production.* to 'gitlab'@'localhost' with grant option;<br />
mysql> exit;<br />
<br />
Copy the example configuration file and make sure to update username/password in {{ic|config/database.yml}} at production section:<br />
# sudo -u gitlab cp config/database.yml.mysql config/database.yml<br />
<br />
===Install gems===<br />
This could take a while as it installs all required libraries.<br />
<br />
# cd /home/gitlab/gitlab<br />
# export PATH=/home/gitlab/bin:$PATH<br />
# sudo -u gitlab -H bundle install --deployment<br />
<br />
{{Note|1= Using "--without development test" in bundle command line will ignore required packages for database backup and restore }}<br />
<br />
===Start redis server===<br />
<br />
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}}.<br />
<br />
{{Note|redis might already be running, causing a FAIL message to appear. Check if it is already running with {{ic|rc.d list redis}}.}}<br />
<br />
If you have switched to [[systemd]], there is a service file included in the official package. See [[daemon]] how to enable it.<br />
<br />
===Populate the database===<br />
<br />
# sudo -u gitlab bundle exec rake gitlab:app:setup RAILS_ENV=production<br />
<br />
===Setup gitlab hooks===<br />
<br />
# cp ./lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive<br />
# chown git:git /home/git/.gitolite/hooks/common/post-receive<br />
<br />
===Check status===<br />
<br />
With the following command we check if the steps we followed so far are conigured properly.<br />
<br />
# sudo -u gitlab bundle exec rake gitlab:app:status RAILS_ENV=production<br />
<br />
{{hc|Example output|<br />
Starting diagnostic<br />
config/database.yml............exists<br />
config/gitlab.yml............exists<br />
/home/git/repositories/............exists<br />
/home/git/repositories/ is writable?............YES<br />
remote: Counting objects: 6, done.<br />
remote: Compressing objects: 100% (4/4), done.<br />
Receiving objects: 100% (6/6), 712 bytes, done.<br />
remote: Total 6 (delta 0), reused 0 (delta 0)<br />
Can clone gitolite-admin?............YES<br />
UMASK for .gitolite.rc is 0007? ............YES<br />
/home/git/share/gitolite/hooks/common/post-receive exists? ............YES<br />
<br />
Finished<br />
}}<br />
<br />
===Server testing and resque process===<br />
<br />
[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].<br />
<br />
Run resque process for processing queue:<br />
# sudo -u gitlab bundle exec rake environment resque:work QUEUE=* RAILS_ENV=production BACKGROUND=yes<br />
<br />
or use Gitlab's start script:<br />
# sudo -u gitlab ./resque.sh<br />
<br />
{{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}}<br />
<br />
Gitlab application can be started with the next command:<br />
# sudo -u gitlab bundle exec rails s -e production<br />
<br />
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:<br />
<br />
login.........admin@local.host<br />
password......5iveL!fe<br />
<br />
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.<br />
<br />
==Web server configuration==<br />
<br />
<br />
===Unicorn only===<br />
<br />
Edit {{ic|/home/gitlab/gitlab/config/unicorn.rb}} uncomment:<br />
<br />
listen 8080 # listen to port 8080 on all TCP interfaces<br />
<br />
Create {{ic|/etc/rc.d/unicorn-gitlab}}.<br />
<pre><br />
#!/bin/bash<br />
<br />
. /etc/rc.conf<br />
. /etc/rc.d/functions<br />
<br />
<br />
PID=`pidof -o %PPID /usr/bin/ruby`<br />
case "$1" in<br />
start)<br />
stat_busy "Starting unicorn"<br />
[ -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"<br />
if [ $? -gt 0 ]; then<br />
stat_fail<br />
else<br />
add_daemon unicorn<br />
stat_done<br />
fi<br />
;;<br />
stop)<br />
stat_busy "Stopping unicorn"<br />
[ ! -z "$PID" ] && kill $PID &> /dev/null<br />
if [ $? -gt 0 ]; then<br />
stat_fail<br />
else<br />
rm_daemon unicorn<br />
stat_done<br />
fi<br />
;;<br />
restart)<br />
$0 stop<br />
sleep 1<br />
$0 start<br />
;;<br />
*)<br />
echo "usage: $0 {start|stop|restart}"<br />
esac<br />
exit 0<br />
</pre><br />
<br />
Start '''unicorn''':<br />
<br />
# /etc/rc.d/unicorn-gitlab start<br />
<br />
Test it http://localhost:8080<br />
<br />
Add it to DAEMONS array in /etc/rc.conf<br />
<br />
Redirect http port to unicorn server<br />
<br />
# iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080<br />
<br />
And test again, now http://localhost<br />
<br />
===Nginx and unicorn===<br />
<br />
[[pacman|Install]] {{Pkg|nginx}} from the [[official repositories]].<br />
<br />
Edit {{ic|/etc/nginx/nginx.conf}}. In the {{ic|http}} section add:<br />
<br />
upstream gitlab {<br />
server unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket;<br />
}<br />
<br />
server {<br />
listen YOUR_SERVER_IP:80; # e.g., listen 192.168.1.1:80;<br />
server_name YOUR_SERVER_FQDN; # e.g., server_name source.example.com;<br />
root /home/gitlab/gitlab/public;<br />
<br />
# individual nginx logs for this gitlab vhost<br />
access_log /var/log/nginx/gitlab_access.log;<br />
error_log /var/log/nginx/gitlab_error.log;<br />
<br />
location / {<br />
# serve static files from defined root folder;.<br />
# @gitlab is a named location for the upstream fallback, see below<br />
try_files $uri $uri/index.html $uri.html @gitlab;<br />
}<br />
<br />
# if a file, which is not found in the root folder is requested, <br />
# then the proxy pass the request to the upsteam (gitlab unicorn)<br />
location @gitlab {<br />
proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694<br />
proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694<br />
proxy_redirect off;<br />
<br />
proxy_set_header X-FORWARDED_PROTO $scheme;<br />
proxy_set_header Host $http_host;<br />
proxy_set_header X-Real-IP $remote_addr;<br />
<br />
proxy_pass <nowiki>http://gitlab</nowiki>;<br />
}<br />
}<br />
<br />
Change YOUR_SERVER_IP and YOUR_SERVER_FQDN to the IP address and fully-qualified domain name of the host serving Gitlab and restart nginx.<br />
<br />
[http://unicorn.bogomips.org/ 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:<br />
<br />
# cd /home/gitlab/gitlab<br />
# sudo -u gitlab cp config/unicorn.rb.orig config/unicorn.rb<br />
# sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D<br />
<br />
===Apache and unicorn===<br />
<br />
[[pacman|Install]] {{Pkg|apache}} from the [[official repositories]]. <br />
<br />
====Configure Unicorn====<br />
<br />
As the official installation guide instructs, copy the unicorn configuration file:<br />
# sudo -u gitlab -H cp /home/gitlab/gitlab/config/unicorn.rb.example /home/gitlab/gitlab/config/unicorn.rb<br />
<br />
Now edit {{ic|config/unicorn.rb}} and add a listening port by uncommenting the following line:<br />
listen "127.0.0.1:8080"<br />
<br />
{{Tip| You can set a custom port if you want. Just remember to also include it in Apache's virtual host. See below.}}<br />
<br />
====Create a virtual host for Gitlab====<br />
<br />
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.<br />
<br />
# mkdir -pv /etc/httpd/conf/vhosts/<br />
<br />
{{hc|/etc/httpd/conf/vhosts/gitlab|<br />
<VirtualHost *:80><br />
ServerName gitlab.myserver.com<br />
ServerAlias www.gitlab.myserver.com<br />
DocumentRoot /home/gitlab/gitlab/public<br />
ErrorLog /var/log/httpd/gitlab_error_log<br />
CustomLog /var/log/httpd/gitlab_access_log combined<br />
<br />
<Proxy balancer://unicornservers><br />
BalancerMember http://127.0.0.1:8080<br />
</Proxy><br />
<br />
<Directory /home/gitlab/gitlab/public><br />
AllowOverride All<br />
Options -MultiViews<br />
</Directory><br />
<br />
RewriteEngine on<br />
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f<br />
RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]<br />
<br />
ProxyPass /uploads !<br />
ProxyPass / balancer://unicornservers/<br />
ProxyPassReverse / balancer://unicornservers/<br />
ProxyPreserveHost on<br />
<br />
<Proxy *><br />
Order deny,allow<br />
Allow from all<br />
</Proxy><br />
</VirtualHost><br />
<br />
<VirtualHost MY_IP:443><br />
ServerName gitlab.myserver.com<br />
ServerAlias www.gitlab.myserver.com<br />
DocumentRoot /home/gitlab/gitlab/public<br />
ErrorLog /var/log/httpd/gitlab_error_log<br />
CustomLog /var/log/httpd/gitlab_access_log combined<br />
<br />
<Proxy balancer://unicornservers><br />
BalancerMember http://127.0.0.1:8080<br />
</Proxy><br />
<br />
<Directory /home/gitlab/gitlab/public><br />
AllowOverride All<br />
Options -MultiViews<br />
</Directory><br />
<br />
RewriteEngine on<br />
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f<br />
RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]<br />
<br />
ProxyPass /uploads !<br />
ProxyPass / balancer://unicornservers/<br />
ProxyPassReverse / balancer://unicornservers/<br />
ProxyPreserveHost on<br />
<br />
<Proxy *><br />
Order deny,allow<br />
Allow from all<br />
</Proxy><br />
<br />
SSLEngine on<br />
SSLCertificateFile /home/gitlab/gitlab/ssl.cert<br />
SSLCertificateKeyFile /home/gitlab/gitlab/ssl.key<br />
</VirtualHost><br />
}}<br />
<br />
====Enable host and start unicorn====<br />
<br />
Enable your Gitlab virtual host and reload [[Apache]]:<br />
{{hc|/etc/httpd/conf/httpd.conf|Include conf/vhosts/gitlab}}<br />
<br />
Finally start unicorn:<br />
<br />
# cd /home/gitlab/gitlab<br />
# sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D<br />
<br />
==SystemD support==<br />
<br />
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. <br />
<br />
Create:<br />
{{hc|/etc/systemd/system/gitlab.service|<nowiki><br />
[Unit]<br />
Description=Gitlab Unicorn Rails server<br />
<br />
[Service]<br />
Type=simple<br />
SyslogIdentifier=gl-unicorn<br />
User=gitlab<br />
PIDFile=/home/gitlab/gitlab/tmp/pids/unicorn.pid<br />
WorkingDirectory=/home/gitlab/gitlab<br />
TimeoutStartSec=600<br />
<br />
ExecStart=/home/gitlab/bin/bundle exec unicorn_rails -c /home/gitlab/gitlab/config/unicorn.rb -E production -D<br />
ExecReload=/bin/kill -HUP $MAINPID<br />
ExecStop=/bin/kill -QUIT $MAINPID<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki>}}<br />
<br />
{{hc|/etc/systemd/system/resque.service|<nowiki><br />
<br />
[Unit]<br />
Description=Gitlab Resque<br />
<br />
[Service]<br />
Type=simple<br />
SyslogIdentifier=gl-resque<br />
User=gitlab<br />
PIDFile=/home/gitlab/gitlab/tmp/pids/resque_worker.pid<br />
WorkingDirectory=/home/gitlab/gitlab<br />
TimeoutStartSec=600<br />
<br />
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<br />
ExecReload=/bin/kill -HUP $MAINPID<br />
ExecStop=/bin/kill -QUIT $MAINPID<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Also see: https://github.com/gitlabhq/gitlab-recipes/issues/14<br />
<br />
==Useful Tips==<br />
===Hook into /var===<br />
sudo mkdir -m700 /var/log/gitlab /var/tmp/gitlab<br />
sudo chown gitlab:gitlab /var/log/gitlab /var/tmp/gitlab<br />
sudo -u gitlab -i<br />
cd ~/gitlab<br />
d=log; mv $d/* /var/$d/gitlab; rm -f $d/.gitkeep; rm -r $d && ln -s /var/$d/gitlab $d<br />
d=tmp; mv $d/* /var/$d/gitlab; rm -f $d/.gitkeep; rm -r $d && ln -s /var/$d/gitlab $d<br />
<br />
===Hidden options===<br />
Go to Gitlab's home directory<br />
# cd /home/gitlab/gitlab<br />
<br />
and run<br />
# rake -T | grep gitlab<br />
<br />
These are the options so far:<br />
rake gitlab:app:backup_create # GITLAB | Create a backup of the gitlab system<br />
rake gitlab:app:backup_restore # GITLAB | Restore a previously created backup<br />
rake gitlab:app:enable_automerge # GITLAB | Enable auto merge<br />
rake gitlab:app:setup # GITLAB | Setup production application<br />
rake gitlab:app:status # GITLAB | Check gitlab installation status<br />
rake gitlab:gitolite:update_hooks # GITLAB | Rewrite hooks for repos<br />
rake gitlab:gitolite:update_keys # GITLAB | Rebuild each key at gitolite config<br />
rake gitlab:gitolite:update_repos # GITLAB | Rebuild each project at gitolite config<br />
rake gitlab:test # GITLAB | Run both cucumber & rspec<br />
<br />
===Backup and restore===<br />
<br />
Create a backup of the gitlab system.<br />
# cd /home/gitlab/gitlab<br />
# sudo -u gitlab rake gitlab:app:backup_create<br />
<br />
Restore a previously created backup.<br />
# cd /home/gitlab/gitlab<br />
# sudo -u gitlab rake gitlab:app:backup_restore<br />
<br />
{{Note| Backup folder is set in {{ic|conig.yml}}. Check [[#Application_specific_settings]].}}<br />
<br />
===Update Gitlab===<br />
<br />
When a new version is out follow the instructions at [https://github.com/gitlabhq/gitlabhq/wiki Github wiki]. A new release is out every 22nd of a month.<br />
<br />
===Migrate from sqlite to mysql===<br />
<br />
Get latest code as described in [[#Update_Gitlab]].<br />
Save data.<br />
# cd /home/gitlab/gitlab<br />
# sudo -u gitlab bundle exec rake db:data:dump RAILS_ENV=production<br />
<br />
Follow [[#Mysql]] instructions and then setup the database.<br />
# sudo -u gitlab bundle exec rake db:setup RAILS_ENV=production<br />
<br />
Finally restore old data.<br />
# sudo -u gitlab bundle exec rake db:data:load RAILS_ENV=production<br />
<br />
==Troubleshooting==<br />
<br />
Sometimes things may not work as expected. Be sure to visit the [https://github.com/gitlabhq/gitlab-public-wiki/wiki/Trouble-Shooting-Guide Trouble Shooting Guide].<br />
<br />
==See also==<br />
*[https://github.com/gitlabhq/gitlabhq/blob/stable/doc/install/installation.md Official Documentation]<br />
*[https://github.com/gitlabhq/gitlab-recipes Gitlab recipes for setup on different platforms, update etc.]<br />
*[http://www.andmarios.com/en/2012/06/gitlab-on-an-ubuntu-10-04-server-with-apache/ GitLab on an Ubuntu 10.04 server with Apache]<br />
*[http://blog.phusion.nl/2012/04/21/tutorial-setting-up-gitlab-on-debian-6/ Setting up gitlab on Debian 6]<br />
*[http://howto.basjes.nl/linux/installing-gitlab-on-centos-6 Installing Gitlab on CentOS 6]<br />
*[https://gist.github.com/2440768 Gist: Install Gitlab on Debian Squeeze]<br />
*[https://gist.github.com/3305554 Gist: Install Gitlab on Archlinux]</div>Spojhttps://wiki.archlinux.org/index.php?title=GitLab&diff=243111GitLab2013-01-06T18:05:49Z<p>Spoj: /* MySQL */</p>
<hr />
<div>[[Category:Version Control System]]<br />
{{Article summary start}}<br />
{{Article summary text|This page gives guidelines for the installation and configuration of Gitlab on Archlinux.}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Gitolite}}<br />
{{Article summary wiki|Ruby on Rails}}<br />
{{Article summary end}}<br />
[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].<br />
<br />
{{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}}.}}<br />
<br />
==Required packages==<br />
<br />
Install the packages below as they are needed to proceed further.<br />
<br />
# pacman -Syu --needed sudo git wget curl checkinstall libxml2 libxslt mysql++ base-devel zlib icu redis openssh python2 python2-pygments python2-pip libyaml ruby<br />
<br />
==Create user accounts==<br />
<br />
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.<br />
<br />
# usermod -d /home/git git<br />
# mkdir -pv /home/git<br />
# chown -R git:git /home/git<br />
# useradd --user-group --shell /bin/bash --comment 'gitlab system' --create-home --groups git gitlab<br />
<br />
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.<br />
<br />
==Gitolite==<br />
<br />
<br />
Clone the gitolite repository from Gitlab's fork. Note that it's version 3.<br />
# cd /home/git<br />
# sudo -H -u git git clone -b gl-v304 https://github.com/gitlabhq/gitolite.git /home/git/gitolite<br />
<br />
Generate Gitlab's ssh key to be used with gitolite:<br />
<br />
{{ic|<nowiki> # sudo -H -u gitlab ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa</nowiki>}}<br />
<br />
Add the following path to git's {{ic|.bash_profile}}:<br />
# sudo -u git sh -c 'echo "export PATH=/home/git/bin:$PATH" >> /home/git/.bash_profile'<br />
# sudo -u git sh -c 'mkdir /home/git/bin'<br />
# sudo -u git -H sh -c "export PATH=/home/git/bin:$PATH; /home/git/gitolite/install -ln"<br />
<br />
Copy Gitlab's public key to gitolite's home and change permissions:<br />
# cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub<br />
# chmod 0444 /home/git/gitlab.pub<br />
<br />
Install gitolite:<br />
# sudo -u git -H sh -c "export PATH=/home/git/bin:$PATH; /home/git/gitolite/src/gitolite setup -pk /home/git/gitlab.pub"<br />
<br />
{{hc|Example output|<br />
creating gitolite-admin...<br />
Initialized empty Git repository in /home/git/repositories/gitolite-admin.git/<br />
creating testing...<br />
Initialized empty Git repository in /home/git/repositories/testing.git/<br />
[master (root-commit) 012fdf5] start<br />
2 files changed, 6 insertions(+)<br />
create mode 100644 conf/gitolite.conf<br />
create mode 100644 keydir/gitlab.pub<br />
}}<br />
<br />
Change permissions:<br />
# chmod -R g+rwX /home/git/repositories/<br />
# chmod g+x /home/git<br />
# chown -R git:git /home/git/repositories/<br />
<br />
{{Note| The next step is '''important''' to succeed. If not, do not try to proceed any further.}}<br />
<br />
Add Gitlab's ssh key to known hosts:<br />
# sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin<br />
<br />
Answer yes. At this point you should be able to clone the gitolite-admin repository. <br />
<br />
{{hc|Example output|<br />
Cloning into '/tmp/gitolite-admin'...<br />
The authenticity of host 'localhost (::1)' can't be established.<br />
ECDSA key fingerprint is 5a:50:69:47:1f:1c:61:79:08:a8:2c:fa:a1:fb:48:bf.<br />
Are you sure you want to continue connecting (yes/no)? yes<br />
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.<br />
remote: Counting objects: 6, done.<br />
remote: Compressing objects: 100% (4/4), done.<br />
Receiving objects: 100% (6/6), 712 bytes, done.<br />
remote: Total 6 (delta 0), reused 0 (delta 0)<br />
}}<br />
<br />
If the repository is cloned successfully, it is safe to remove it:<br />
# rm -rf /tmp/gitolite-admin<br />
<br />
==Gitlab==<br />
<br />
===Installation===<br />
<br />
{{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.}}<br />
<br />
Add [[ruby]] to Gitlab's {{ic|PATH}}:<br />
# sudo -u gitlab -H sh -c 'echo "export PATH=$(ruby -rubygems -e "puts Gem.user_dir")/bin:$PATH" >> /home/gitlab/.bashrc'<br />
<br />
Install bundler and charlock_holmes:<br />
# sudo -u gitlab -H gem install charlock_holmes --version '0.6.8'<br />
# sudo -u gitlab -H gem install bundler<br />
<br />
{{Note|When installing charlock_holmes don't mind any errors that might occur, that's ''normal''.}}<br />
<br />
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:<br />
# sudo -u gitlab -H mkdir /home/gitlab/bin<br />
# sudo -u gitlab -H sh -c "ln -s \$(ruby -rubygems -e 'puts Gem.user_dir')/bin/bundle /home/gitlab/bin/"<br />
# sudo -u gitlab -H sh -c 'echo "export PATH=/home/gitlab/bin:$PATH" >> /home/gitlab/.bashrc'<br />
<br />
<br />
Clone Gitlab's stable repository:<br />
# cd /home/gitlab<br />
# sudo -H -u gitlab git clone -b stable git://github.com/gitlabhq/gitlabhq.git gitlab<br />
# cd gitlab<br />
# sudo -u gitlab mkdir -pv tmp<br />
<br />
===Basic configuration===<br />
<br />
First we need to rename the example file.<br />
<br />
# sudo -u gitlab cp config/gitlab.yml.example config/gitlab.yml<br />
<br />
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.<br />
<br />
====Web application specific settings====<br />
<br />
{{hc|/home/gitlab/gitlab/config/gitlab.yml|<nowiki><br />
host: myhost.example.com<br />
port: 80<br />
https: false<br />
</nowiki>}}<br />
<br />
*{{ic|host}}: Enter your [[Wikipedia:Fully_qualified_domain_name|Fully Qualified Domain Name]].<br />
<br />
====Email used for notification====<br />
<br />
{{hc|/home/gitlab/gitlab/config/gitlab.yml|<nowiki><br />
from: notify@example.com<br />
</nowiki>}}<br />
<br />
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:<br />
<br />
# ls /usr/sbin/sendmail<br />
<br />
If you get a ‘cannot access /usr/bin/sendmail’ then install one of the above packages.<br />
<br />
====Application specific settings====<br />
<br />
{{hc|/home/gitlab/gitlab/config/gitlab.yml|<nowiki><br />
default_projects_limit: 10<br />
# backup_path: "/vol/backups" # default: Rails.root + backups/<br />
# backup_keep_time: 604800 # default: 0 (forever) (in seconds)<br />
</nowiki>}}<br />
<br />
*{{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.<br />
*{{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.<br />
*{{ic|backup_keep_time}}: Time to preserve backups. The default option is to never be deleted.<br />
<br />
Also check [[#Backup_and_restore| Backup and restore]].<br />
<br />
====Git Hosting configuration====<br />
<br />
{{hc|/home/gitlab/gitlab/config/gitlab.yml|<nowiki><br />
admin_uri: git@localhost:gitolite-admin<br />
base_path: /home/git/repositories/<br />
hooks_path: /home/git/share/gitolite/hooks/<br />
# host: localhost<br />
git_user: git<br />
upload_pack: true<br />
receive_pack: true<br />
# port: 22<br />
</nowiki>}}<br />
<br />
*{{ic|admin_uri}}: Do not change it. Leave as is.<br />
*{{ic|base_path}}: The path where gitolite's repositories reside. If the repositories directory is different than the default one, change it here.<br />
*{{ic|hooks_path}}: change default setting to /home/git/share/gitolite/hooks/<br />
*{{ic|host}}: Should point to your FQDN.<br />
*{{ic|git_user}}: Name of the git user we created.<br />
*{{ic|upload_pack}}: <br />
*{{ic|receive_pack}}: <br />
<br />
*{{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}}.<br />
<br />
{{hc|/home/gitlab/gitlab/.ssh/config|<nowiki><br />
Host localhost<br />
Port 5000<br />
</nowiki>}}<br />
<br />
====Git settings====<br />
<br />
{{hc|/home/gitlab/gitlab/config/gitlab.yml|<nowiki><br />
path: /usr/bin/git<br />
git_max_size: 5242880 # 5.megabytes<br />
git_timeout: 10<br />
</nowiki>}}<br />
<br />
*{{ic|git_max_size}}: Max size of git objects like commits, in bytes,.This value can be increased if you have very large commits.<br />
*{{ic|git_timeout}}: git timeout to read commit, in seconds.<br />
<br />
===Database selection===<br />
<br />
SQLite support in Gitlab is now deprecated. See [https://github.com/gitlabhq/gitlabhq/pull/2093 this bug report].<br />
<br />
====MySQL====<br />
<br />
[[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.<br />
# mysql -u root -p<br />
<br />
mysql> create database gitlabhq_production;<br />
mysql> create user 'gitlab'@'localhost' identified by 'your_password_here';<br />
mysql> grant all privileges on gitlabhq_production.* to 'gitlab'@'localhost' with grant option;<br />
mysql> exit;<br />
<br />
Copy the example configuration file and make sure to update username/password in {{ic|config/database.yml}} at production section:<br />
# sudo -u gitlab cp config/database.yml.mysql config/database.yml<br />
<br />
===Install gems===<br />
This could take a while as it installs all required libraries.<br />
<br />
# cd /home/gitlab/gitlab<br />
# source /home/gitlab/.bash_profile<br />
# sudo -u gitlab -H bundle install --deployment<br />
<br />
{{Note|1= Using "--without development test" in bundle command line will ignore required packages for database backup and restore }}<br />
<br />
===Start redis server===<br />
<br />
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}}.<br />
<br />
{{Note|redis might already be running, causing a FAIL message to appear. Check if it is already running with {{ic|rc.d list redis}}.}}<br />
<br />
If you have switched to [[systemd]], there is a service file included in the official package. See [[daemon]] how to enable it.<br />
<br />
===Populate the database===<br />
<br />
# sudo -u gitlab bundle exec rake gitlab:app:setup RAILS_ENV=production<br />
<br />
===Setup gitlab hooks===<br />
<br />
# cp ./lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive<br />
# chown git:git /home/git/.gitolite/hooks/common/post-receive<br />
<br />
===Check status===<br />
<br />
With the following command we check if the steps we followed so far are conigured properly.<br />
<br />
# sudo -u gitlab bundle exec rake gitlab:app:status RAILS_ENV=production<br />
<br />
{{hc|Example output|<br />
Starting diagnostic<br />
config/database.yml............exists<br />
config/gitlab.yml............exists<br />
/home/git/repositories/............exists<br />
/home/git/repositories/ is writable?............YES<br />
remote: Counting objects: 6, done.<br />
remote: Compressing objects: 100% (4/4), done.<br />
Receiving objects: 100% (6/6), 712 bytes, done.<br />
remote: Total 6 (delta 0), reused 0 (delta 0)<br />
Can clone gitolite-admin?............YES<br />
UMASK for .gitolite.rc is 0007? ............YES<br />
/home/git/share/gitolite/hooks/common/post-receive exists? ............YES<br />
<br />
Finished<br />
}}<br />
<br />
===Server testing and resque process===<br />
<br />
[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].<br />
<br />
Run resque process for processing queue:<br />
# sudo -u gitlab bundle exec rake environment resque:work QUEUE=* RAILS_ENV=production BACKGROUND=yes<br />
<br />
or use Gitlab's start script:<br />
# sudo -u gitlab ./resque.sh<br />
<br />
{{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}}<br />
<br />
Gitlab application can be started with the next command:<br />
# sudo -u gitlab bundle exec rails s -e production<br />
<br />
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:<br />
<br />
login.........admin@local.host<br />
password......5iveL!fe<br />
<br />
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.<br />
<br />
==Web server configuration==<br />
<br />
<br />
===Unicorn only===<br />
<br />
Edit {{ic|/home/gitlab/gitlab/config/unicorn.rb}} uncomment:<br />
<br />
listen 8080 # listen to port 8080 on all TCP interfaces<br />
<br />
Create {{ic|/etc/rc.d/unicorn-gitlab}}.<br />
<pre><br />
#!/bin/bash<br />
<br />
. /etc/rc.conf<br />
. /etc/rc.d/functions<br />
<br />
<br />
PID=`pidof -o %PPID /usr/bin/ruby`<br />
case "$1" in<br />
start)<br />
stat_busy "Starting unicorn"<br />
[ -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"<br />
if [ $? -gt 0 ]; then<br />
stat_fail<br />
else<br />
add_daemon unicorn<br />
stat_done<br />
fi<br />
;;<br />
stop)<br />
stat_busy "Stopping unicorn"<br />
[ ! -z "$PID" ] && kill $PID &> /dev/null<br />
if [ $? -gt 0 ]; then<br />
stat_fail<br />
else<br />
rm_daemon unicorn<br />
stat_done<br />
fi<br />
;;<br />
restart)<br />
$0 stop<br />
sleep 1<br />
$0 start<br />
;;<br />
*)<br />
echo "usage: $0 {start|stop|restart}"<br />
esac<br />
exit 0<br />
</pre><br />
<br />
Start '''unicorn''':<br />
<br />
# /etc/rc.d/unicorn-gitlab start<br />
<br />
Test it http://localhost:8080<br />
<br />
Add it to DAEMONS array in /etc/rc.conf<br />
<br />
Redirect http port to unicorn server<br />
<br />
# iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080<br />
<br />
And test again, now http://localhost<br />
<br />
===Nginx and unicorn===<br />
<br />
[[pacman|Install]] {{Pkg|nginx}} from the [[official repositories]].<br />
<br />
Edit {{ic|/etc/nginx/nginx.conf}}. In the {{ic|http}} section add:<br />
<br />
upstream gitlab {<br />
server unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket;<br />
}<br />
<br />
server {<br />
listen YOUR_SERVER_IP:80; # e.g., listen 192.168.1.1:80;<br />
server_name YOUR_SERVER_FQDN; # e.g., server_name source.example.com;<br />
root /home/gitlab/gitlab/public;<br />
<br />
# individual nginx logs for this gitlab vhost<br />
access_log /var/log/nginx/gitlab_access.log;<br />
error_log /var/log/nginx/gitlab_error.log;<br />
<br />
location / {<br />
# serve static files from defined root folder;.<br />
# @gitlab is a named location for the upstream fallback, see below<br />
try_files $uri $uri/index.html $uri.html @gitlab;<br />
}<br />
<br />
# if a file, which is not found in the root folder is requested, <br />
# then the proxy pass the request to the upsteam (gitlab unicorn)<br />
location @gitlab {<br />
proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694<br />
proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694<br />
proxy_redirect off;<br />
<br />
proxy_set_header X-FORWARDED_PROTO $scheme;<br />
proxy_set_header Host $http_host;<br />
proxy_set_header X-Real-IP $remote_addr;<br />
<br />
proxy_pass <nowiki>http://gitlab</nowiki>;<br />
}<br />
}<br />
<br />
Change YOUR_SERVER_IP and YOUR_SERVER_FQDN to the IP address and fully-qualified domain name of the host serving Gitlab and restart nginx.<br />
<br />
[http://unicorn.bogomips.org/ 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:<br />
<br />
# cd /home/gitlab/gitlab<br />
# sudo -u gitlab cp config/unicorn.rb.orig config/unicorn.rb<br />
# sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D<br />
<br />
===Apache and unicorn===<br />
<br />
[[pacman|Install]] {{Pkg|apache}} from the [[official repositories]]. <br />
<br />
====Configure Unicorn====<br />
<br />
As the official installation guide instructs, copy the unicorn configuration file:<br />
# sudo -u gitlab -H cp /home/gitlab/gitlab/config/unicorn.rb.example /home/gitlab/gitlab/config/unicorn.rb<br />
<br />
Now edit {{ic|config/unicorn.rb}} and add a listening port by uncommenting the following line:<br />
listen "127.0.0.1:8080"<br />
<br />
{{Tip| You can set a custom port if you want. Just remember to also include it in Apache's virtual host. See below.}}<br />
<br />
====Create a virtual host for Gitlab====<br />
<br />
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.<br />
<br />
# mkdir -pv /etc/httpd/conf/vhosts/<br />
<br />
{{hc|/etc/httpd/conf/vhosts/gitlab|<br />
<VirtualHost *:80><br />
ServerName gitlab.myserver.com<br />
ServerAlias www.gitlab.myserver.com<br />
DocumentRoot /home/gitlab/gitlab/public<br />
ErrorLog /var/log/httpd/gitlab_error_log<br />
CustomLog /var/log/httpd/gitlab_access_log combined<br />
<br />
<Proxy balancer://unicornservers><br />
BalancerMember http://127.0.0.1:8080<br />
</Proxy><br />
<br />
<Directory /home/gitlab/gitlab/public><br />
AllowOverride All<br />
Options -MultiViews<br />
</Directory><br />
<br />
RewriteEngine on<br />
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f<br />
RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]<br />
<br />
ProxyPass /uploads !<br />
ProxyPass / balancer://unicornservers/<br />
ProxyPassReverse / balancer://unicornservers/<br />
ProxyPreserveHost on<br />
<br />
<Proxy *><br />
Order deny,allow<br />
Allow from all<br />
</Proxy><br />
</VirtualHost><br />
<br />
<VirtualHost MY_IP:443><br />
ServerName gitlab.myserver.com<br />
ServerAlias www.gitlab.myserver.com<br />
DocumentRoot /home/gitlab/gitlab/public<br />
ErrorLog /var/log/httpd/gitlab_error_log<br />
CustomLog /var/log/httpd/gitlab_access_log combined<br />
<br />
<Proxy balancer://unicornservers><br />
BalancerMember http://127.0.0.1:8080<br />
</Proxy><br />
<br />
<Directory /home/gitlab/gitlab/public><br />
AllowOverride All<br />
Options -MultiViews<br />
</Directory><br />
<br />
RewriteEngine on<br />
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f<br />
RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]<br />
<br />
ProxyPass /uploads !<br />
ProxyPass / balancer://unicornservers/<br />
ProxyPassReverse / balancer://unicornservers/<br />
ProxyPreserveHost on<br />
<br />
<Proxy *><br />
Order deny,allow<br />
Allow from all<br />
</Proxy><br />
<br />
SSLEngine on<br />
SSLCertificateFile /home/gitlab/gitlab/ssl.cert<br />
SSLCertificateKeyFile /home/gitlab/gitlab/ssl.key<br />
</VirtualHost><br />
}}<br />
<br />
====Enable host and start unicorn====<br />
<br />
Enable your Gitlab virtual host and reload [[Apache]]:<br />
{{hc|/etc/httpd/conf/httpd.conf|Include conf/vhosts/gitlab}}<br />
<br />
Finally start unicorn:<br />
<br />
# cd /home/gitlab/gitlab<br />
# sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D<br />
<br />
==SystemD support==<br />
<br />
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. <br />
<br />
Create:<br />
{{hc|/etc/systemd/system/gitlab.service|<nowiki><br />
[Unit]<br />
Description=Gitlab Unicorn Rails server<br />
<br />
[Service]<br />
Type=simple<br />
SyslogIdentifier=gl-unicorn<br />
User=gitlab<br />
PIDFile=/home/gitlab/gitlab/tmp/pids/unicorn.pid<br />
WorkingDirectory=/home/gitlab/gitlab<br />
TimeoutStartSec=600<br />
<br />
ExecStart=/home/gitlab/bin/bundle exec unicorn_rails -c /home/gitlab/gitlab/config/unicorn.rb -E production -D<br />
ExecReload=/bin/kill -HUP $MAINPID<br />
ExecStop=/bin/kill -QUIT $MAINPID<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki>}}<br />
<br />
{{hc|/etc/systemd/system/resque.service|<nowiki><br />
<br />
[Unit]<br />
Description=Gitlab Resque<br />
<br />
[Service]<br />
Type=simple<br />
SyslogIdentifier=gl-resque<br />
User=gitlab<br />
PIDFile=/home/gitlab/gitlab/tmp/pids/resque_worker.pid<br />
WorkingDirectory=/home/gitlab/gitlab<br />
TimeoutStartSec=600<br />
<br />
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<br />
ExecReload=/bin/kill -HUP $MAINPID<br />
ExecStop=/bin/kill -QUIT $MAINPID<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Also see: https://github.com/gitlabhq/gitlab-recipes/issues/14<br />
<br />
==Useful Tips==<br />
===Hook into /var===<br />
sudo mkdir -m700 /var/log/gitlab /var/tmp/gitlab<br />
sudo chown gitlab:gitlab /var/log/gitlab /var/tmp/gitlab<br />
sudo -u gitlab -i<br />
cd ~/gitlab<br />
d=log; mv $d/* /var/$d/gitlab; rm -f $d/.gitkeep; rm -r $d && ln -s /var/$d/gitlab $d<br />
d=tmp; mv $d/* /var/$d/gitlab; rm -f $d/.gitkeep; rm -r $d && ln -s /var/$d/gitlab $d<br />
<br />
===Hidden options===<br />
Go to Gitlab's home directory<br />
# cd /home/gitlab/gitlab<br />
<br />
and run<br />
# rake -T | grep gitlab<br />
<br />
These are the options so far:<br />
rake gitlab:app:backup_create # GITLAB | Create a backup of the gitlab system<br />
rake gitlab:app:backup_restore # GITLAB | Restore a previously created backup<br />
rake gitlab:app:enable_automerge # GITLAB | Enable auto merge<br />
rake gitlab:app:setup # GITLAB | Setup production application<br />
rake gitlab:app:status # GITLAB | Check gitlab installation status<br />
rake gitlab:gitolite:update_hooks # GITLAB | Rewrite hooks for repos<br />
rake gitlab:gitolite:update_keys # GITLAB | Rebuild each key at gitolite config<br />
rake gitlab:gitolite:update_repos # GITLAB | Rebuild each project at gitolite config<br />
rake gitlab:test # GITLAB | Run both cucumber & rspec<br />
<br />
===Backup and restore===<br />
<br />
Create a backup of the gitlab system.<br />
# cd /home/gitlab/gitlab<br />
# sudo -u gitlab rake gitlab:app:backup_create<br />
<br />
Restore a previously created backup.<br />
# cd /home/gitlab/gitlab<br />
# sudo -u gitlab rake gitlab:app:backup_restore<br />
<br />
{{Note| Backup folder is set in {{ic|conig.yml}}. Check [[#Application_specific_settings]].}}<br />
<br />
===Update Gitlab===<br />
<br />
When a new version is out follow the instructions at [https://github.com/gitlabhq/gitlabhq/wiki Github wiki]. A new release is out every 22nd of a month.<br />
<br />
===Migrate from sqlite to mysql===<br />
<br />
Get latest code as described in [[#Update_Gitlab]].<br />
Save data.<br />
# cd /home/gitlab/gitlab<br />
# sudo -u gitlab bundle exec rake db:data:dump RAILS_ENV=production<br />
<br />
Follow [[#Mysql]] instructions and then setup the database.<br />
# sudo -u gitlab bundle exec rake db:setup RAILS_ENV=production<br />
<br />
Finally restore old data.<br />
# sudo -u gitlab bundle exec rake db:data:load RAILS_ENV=production<br />
<br />
==Troubleshooting==<br />
<br />
Sometimes things may not work as expected. Be sure to visit the [https://github.com/gitlabhq/gitlab-public-wiki/wiki/Trouble-Shooting-Guide Trouble Shooting Guide].<br />
<br />
==See also==<br />
*[https://github.com/gitlabhq/gitlabhq/blob/stable/doc/install/installation.md Official Documentation]<br />
*[https://github.com/gitlabhq/gitlab-recipes Gitlab recipes for setup on different platforms, update etc.]<br />
*[http://www.andmarios.com/en/2012/06/gitlab-on-an-ubuntu-10-04-server-with-apache/ GitLab on an Ubuntu 10.04 server with Apache]<br />
*[http://blog.phusion.nl/2012/04/21/tutorial-setting-up-gitlab-on-debian-6/ Setting up gitlab on Debian 6]<br />
*[http://howto.basjes.nl/linux/installing-gitlab-on-centos-6 Installing Gitlab on CentOS 6]<br />
*[https://gist.github.com/2440768 Gist: Install Gitlab on Debian Squeeze]<br />
*[https://gist.github.com/3305554 Gist: Install Gitlab on Archlinux]</div>Spoj