Skip to content

Instantly share code, notes, and snippets.

@rjmoggach
Last active October 8, 2023 08:39
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rjmoggach/5da4b5ed8f994a036607 to your computer and use it in GitHub Desktop.
Save rjmoggach/5da4b5ed8f994a036607 to your computer and use it in GitHub Desktop.
Webfaction GitLab Install

Install Gitlab on webfaction

November 2014

I wanted to install gitlab on my shared hosting server at webfaction and here's how I did it. Be warned it's a memory hog. I couldn't get it below 450Mb. Also... this is for their newer 64 bit servers. I tried on a 32 bit server and didn't want to waste a day tracking down dependencies.

Create app for gitlab

Create a new app (using python)

python
import xmlrpclib
MAIN_USER='ACCTNAME'
MAIN_PASS='ACCTPASS'
APP_NAME='gitlab'
server = xmlrpclib.ServerProxy('https://api.webfaction.com/')
session_id, account = server.login(MAIN_USER, MAIN_PASS)
server.create_app(session_id, APP_NAME, 'rails-4.1.1')
exit()

Setup/Install Gitlab and dependencies

Install sqlite

(required for gem install)

cd ~/webapps/gitlab
mkdir -p src
cd src
wget http://sqlite.org/2014/sqlite-autoconf-3080701.tar.gz
tar xvzf sqlite-autoconf-3080701.tar.gz
cd sqlite-autoconf-3080701
./configure --prefix=/home/ACCTNAME/webapps/gitlab
make
make install

Create postgres database (using python)

python
import xmlrpclib
MAIN_USER='ACCTNAME'
MAIN_PASS='ACCTPASS'
DB_NAME='gitlab'
server = xmlrpclib.ServerProxy('https://api.webfaction.com/')
session_id, account = server.login(MAIN_USER, MAIN_PASS)
server.create_db(session_id, DB_NAME, 'postgresql', MAIN_PASS)
exit()

Install Redis

Create a custom app

python
import xmlrpclib
MAIN_USER='ACCTNAME'
MAIN_PASS='ACCTPASS'
APP_NAME='gitlab_redis'
server = xmlrpclib.ServerProxy('https://api.webfaction.com/')
session_id, account = server.login(MAIN_USER, MAIN_PASS)
server.create_app(session_id, APP_NAME, 'custom_app_with_port')
exit()

Make a note of the port number... you'll need it below. (eg. 99999)

cd ~/webapps/gitlab_redis/
mkdir src
cd src
wget http://download.redis.io/releases/redis-2.8.17.tar.gz
tar xvzf redis-2.8.17.tar.gz
cd redis-2.8.17
make PREFIX="/home/ACCTNAME/webapps/gitlab_redis"
make install
cd ~/webapps/gitlab_redis
cp src/redis-2.8.17/src/{redis-server,redis-cli,redis-sentinel,redis-benchmark} ./
cp src/redis-2.8.17/redis.conf ./

Edit the config and change the following...

daemonize yes
pidfile /home/ACCTNAME/webapps/gitlab_redis/redis.pid
port 99999

Start the server

./redis-server redis.conf

Install Gitlab

Install dependencies

We need cmake installed to build some of the gitlab dependencies... we'll put this in our home directory

mkdir ~/src && cd ~/src
wget http://www.cmake.org/files/v3.0/cmake-3.0.2.tar.gz
tar xvzf cmake-3.0.2.tar.gz
cd cmake-3.0.2
./bootstrap --prefix=/home/ACCTNAME/webapps/gitlab
gmake
gmake install

We also need libgit for the rugged ruby git bindings...

cd /home/ACCTNAME/src
wget https://github.com/libgit2/libgit2/archive/v0.21.2.tar.gz
mv v0.21.2.tar.gz libgit2-0.21.2.tar.gz
tar xvzf libgit_v0.21.2.tar.gz
cd libgit2-0.21.2
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/home/ACCTNAME
cmake --build . --target install

Now install rubygems for local gems- is this required???

cd /home/ACCTNAME/webapps/gitlab
export GEM_HOME=/home/ACCTNAME/webapps/gitlab/gems
export RUBYLIB=/home/ACCTNAME/webapps/gitlab/lib:$RUBYLIB
export PATH=/home/ACCTNAME/webapps/gitlab/bin:$PATH
cd /home/ACCTNAME/webapps/gitlab/src
wget http://production.cf.rubygems.org/rubygems/rubygems-2.4.2.tgz
tar xvzf rubygems-2.4.2.tgz
cd rubygems-2.4.2
ruby setup.rb install --prefix=/home/ACCTNAME/webapps/gitlab

We'll need libgit for some of the ruby bundles so set the ld path

export C_INCLUDE_PATH=/home/ACCTNAME/include:/home/ACCTNAME/webapps/gitlab/include:$C_INCLUDE_PATH
export LD_LIBRARY_PATH=/home/ACCTNAME/lib:/home/ACCTNAME/webapps/gitlab/lib:$LD_LIBRARY_PATH

gem2.0 install bundler
gem2.0 install sidekiq
gem2.0 install actionmailer

Configure Gitlab

git clone https://github.com/gitlabhq/gitlabhq.git -b 7-4-stable gitlabhq
cd gitlabhq

Copy the example config files and edit them to suit our environment.

main config file...

cp config/gitlab.yml.example config/gitlab.yml
vi config/gitlab.yml

database config...

cp config/database.yml.postgresql config/database.yml
vi config/database.yml

redis config... (you want the url to start with redis://)

cp config/resque.yml.example config/resque.yml
vi config/resque.yml

install gitlab

Install all the dependencies... we're using postgresql so we want the without mysql option

bundle install --deployment --without development test mysql aws

Install gitlab-shell... remember the redis port!

bundle exec rake gitlab:shell:install[v2.0.1] REDIS_URL=redis://localhost:99999 RAILS_ENV=production

Run the setup... and set the initial password for admin login... you'll reset this when you login

bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=ACCTPASS

Check application status... ignore the errors about the init scripts... we'll fix that with our startup scripts

bundle exec rake gitlab:env:info RAILS_ENV=production

Compile Assets

bundle exec rake assets:precompile RAILS_ENV=production

Edit your nginx.conf to point it at gitlabhq - you need to change the root and rails_env values:

root               /home/ACCTNAME/webapps/gitlab/gitlabhq/public;
rails_env          production;

If you want to limit the number of passenger instance launched (equivalent to NUM_WEBS option), you need to change these lines :

worker_processes  1;
passenger_max_pool_size 1;

In my case i change the default passenger_max_pool_size 2; to passenger_max_pool_size 1; to limit memory consumption.

Modify launching of nginx to add performance RUBY_GC_MALLOC_LIMIT, see into bash file here /home/ACCTNAME/webapps/gitlab/bin/start in my case...

Also adding the sidekiq startup because that normally gets done with the init scripts...

#!/bin/bash

cd /home/ACCTNAME/webapps/gitlab/gitlabhq

RUBY_GC_MALLOC_LIMIT=90000000 \
PATH=/home/ACCTNAME/webapps/gitlab/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/ACCTNAME/bin \
RUBYLIB=/home/ACCTNAME/webapps/gitlab/lib:$RUBYLIB \
TMPDIR=/home/ACCTNAME/webapps/gitlab/tmp \
PASSENGER_TMPDIR=/home/ACCTNAME/webapps/gitlab/tmp \
GEM_HOME=/home/ACCTNAME/webapps/gitlab/gems \
bundle exec sidekiq -L /home/ACCTNAME/logs/user/sidekiq.log \
-d -P /home/ACCTNAME/webapps/gitlab/sidekiq.pid \
-e production -c 3 \
> /home/ACCTNAME/logs/user/sidekiq.log 2>&1

RUBY_GC_MALLOC_LIMIT=90000000 \
PATH=/home/ACCTNAME/webapps/gitlab/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/ACCTNAME/bin \
RUBYLIB=/home/ACCTNAME/webapps/gitlab/lib:$RUBYLIB \
TMPDIR=/home/ACCTNAME/webapps/gitlab/tmp \
PASSENGER_TMPDIR=/home/ACCTNAME/webapps/gitlab/tmp \
GEM_HOME=/home/ACCTNAME/webapps/gitlab/gems \
/home/ACCTNAME/webapps/gitlab/nginx/sbin/nginx \
-p /home/ACCTNAME/webapps/gitlab/nginx/

and change the /home/ACCTNAME/webapps/gitlab/bin/stop script to :

#!/bin/bash
pid_file=/home/ACCTNAME/webapps/gitlab/nginx/logs/nginx.pid
sidekiq_pid_file=/home/ACCTNAME/webapps/gitlab/sidekiq.pid

if [ -f $pid_file ]
then
    kill $( cat $pid_file )
fi
if [ -f $sidekiq_pid_file ]
then
    kill $( cat $sidekiq_pid_file )
fi
sleep 3
rm -rf /home/ACCTNAME/webapps/gitlab/tmp/*

Restart your app...

~/webapps/gitlab/bin/restart

Configure email

This relies on sidekiq running. Gitlab will run without sidekiq but you won't have email sending and it's a pain to debug. So if your settings aren't working it's likely because sidekiq isn't running.

Out of the box on webfaction sendmail should work so unless you want to use smtp you can probably just configure the from email and be done.

@lesaff
Copy link

lesaff commented Nov 11, 2014

I am getting a "make install error" when I tried to compile the redis portion.

install: cannot create regular file `/usr/local/bin/redis-server': Permission denied

I tried running 'make test' and everything passed without errors.
Thx

@KK7NZY
Copy link

KK7NZY commented Nov 14, 2014

I ran into the same problem. Used the following snippet below to get it to install.
make PREFIX="/home/ACCTNAME/webapps/gitlab_redis" install

Unfortunately could not get passed bundle install --deployment --without development test mysql aws

@lesaff
Copy link

lesaff commented Nov 15, 2014

Try this. It got me through the install process.

make --PREFIX=$HOME

@qunabu
Copy link

qunabu commented Jan 11, 2016

Im no ruby expert and tried everything i could google but for me installation stops after
bundle install --deployment --without development test mysql aws
when gitlab tries to install rugged gem
my server is CentOS 7 (64-bit)

@PawelBogdan
Copy link

Do anybody knows how to solve problem with command:

bundle exec rake gitlab:shell:install[v2.0.1] REDIS_URL=redis://localhost:99999 RAILS_ENV=production

I got the following error:

Warning
You are running as user dicellas, we hope you know what you are doing.
Things may work/fail for the wrong reasons.
For correct results you should run this as user git.

rake aborted!
Gitlab::TaskFailedError: fatal: could not create leading directories of '/home/git/gitlab-shell': Access denied

Unfortunatelly there is no such a user as git and I am not allowed to create it. Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment