installation.md 8.16 KB
Newer Older
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
1
## Platform requirements: 
Valery Sizov's avatar
Valery Sizov committed
2

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
**The project is designed for the Linux operating system. **

It may work on FreeBSD and Mac OS, but we don't test our application for these systems and can't guarantee stability and full functionality.

We officially support next Linux Distributions:

- Ubuntu
- Debian

It should work on:

- Fedora
- CentOs
- Red Hat

It can work on:

 - Mac Os
 - FreeBSD

It 100% **wont** work on  Windows


## This installation guide created for Debian/Ubuntu and properly tested. 

The installation consists of 6 steps:
Valery Sizov's avatar
Valery Sizov committed
29 30 31 32 33 34 35 36

1. install packeges.
2. install ruby
3. install gitolite
4. install gitlab and configuration. Check status configuration.
5. server up.
6. run resque process (for processing queue).

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
37
** Before submit an installation issue - please check if you followed all steps **
Valery Sizov's avatar
Valery Sizov committed
38

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
39 40 41 42 43 44 45 46 47 48 49
> - - -
> First 3 steps can be easily skipped with simply install script:
> 
>     # Install curl and sudo 
>     apt-get install curl sudo
>     
>     # 3 steps in 1 command :)
>     curl http://dl.dropbox.com/u/936096/debian_ubuntu.sh | sh
> 
> Now you can go to step 4"
> - - -
Valery Sizov's avatar
Valery Sizov committed
50 51 52

# 1. Install packages

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
53
*Keep in mind that `sudo` is not installed for debian by default. You should install it with as root:*     **apt-get update && apt-get upgrade && apt-get install sudo**
Valery Sizov's avatar
Valery Sizov committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

    sudo apt-get update
    sudo apt-get upgrade

    sudo apt-get install -y git-core wget curl gcc checkinstall libxml2-dev libxslt-dev sqlite3 libsqlite3-dev libcurl4-openssl-dev libreadline-dev libc6-dev libssl-dev libmysql++-dev make build-essential zlib1g-dev libicu-dev redis-server openssh-server git-core python-dev python-pip sendmail

# 2. Install ruby

    wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p290.tar.gz
    tar xfvz ruby-1.9.2-p290.tar.gz
    cd ruby-1.9.2-p290
    ./configure
    make
    sudo make install

# 3. Install gitolite

Create user for git:
    
    sudo adduser \
      --system \
      --shell /bin/sh \
      --gecos 'git version control' \
      --group \
      --disabled-password \
      --home /home/git \
      git

    

Create user for gitlab:
85

Valery Sizov's avatar
Valery Sizov committed
86 87 88 89
    # ubuntu/debian
    sudo adduser --disabled-login --gecos 'gitlab system' gitlab    

Add your user to git group:
90

Valery Sizov's avatar
Valery Sizov committed
91 92 93
    sudo usermod -a -G git gitlab

Generate key:
94

Valery Sizov's avatar
Valery Sizov committed
95 96
    sudo -H -u gitlab ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
97
Get gitolite source code:
98

Valery Sizov's avatar
Valery Sizov committed
99 100 101 102
    cd /home/git
    sudo -H -u git git clone git://github.com/gitlabhq/gitolite /home/git/gitolite    

Setup:
103

Valery Sizov's avatar
Valery Sizov committed
104 105 106 107 108 109
    sudo -u git -H /home/git/gitolite/src/gl-system-install
    sudo cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub
    sudo chmod 777 /home/git/gitlab.pub

    sudo -u git -H sed -i 's/0077/0007/g' /home/git/share/gitolite/conf/example.gitolite.rc
    sudo -u git -H sh -c "PATH=/home/git/bin:$PATH; gl-setup -q /home/git/gitlab.pub"
110
    
Valery Sizov's avatar
Valery Sizov committed
111
Permissions:
112

Valery Sizov's avatar
Valery Sizov committed
113 114 115 116 117 118 119 120 121 122 123 124
    sudo chmod -R g+rwX /home/git/repositories/
    sudo chown -R git:git /home/git/repositories/

#### CHECK: Logout & login again to apply git group to your user
    
    # clone admin repo to add localhost to known_hosts
    # & be sure your user has access to gitolite
    sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin 

    # if succeed  you can remove it
    sudo rm -rf /tmp/gitolite-admin 

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
125 126
** IMPORTANT! If you cant clone `gitolite-admin` repository - DONT PROCEED INSTALLATION**

Valery Sizov's avatar
Valery Sizov committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140

# 4. Install gitlab and configuration. Check status configuration.

    sudo gem install charlock_holmes
    sudo pip install pygments
    sudo gem install bundler
    cd /home/gitlab
    sudo -H -u gitlab git clone git://github.com/gitlabhq/gitlabhq.git gitlab
    cd gitlab

    # Rename config files
    sudo -u gitlab cp config/gitlab.yml.example config/gitlab.yml

#### Select db you want to use
141

Valery Sizov's avatar
Valery Sizov committed
142 143 144 145 146 147
    # SQLite
    sudo -u gitlab cp config/database.yml.sqlite config/database.yml

    # Or 
    # Mysql
    sudo -u gitlab cp config/database.yml.example config/database.yml
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
148
    # Change username/password of config/database.yml  to real one
Valery Sizov's avatar
Valery Sizov committed
149 150

#### Install gems
151

Valery Sizov's avatar
Valery Sizov committed
152 153 154
    sudo -u gitlab -H bundle install --without development test --deployment

#### Setup DB
155

Valery Sizov's avatar
Valery Sizov committed
156 157 158 159
    sudo -u gitlab bundle exec rake db:setup RAILS_ENV=production
    sudo -u gitlab bundle exec rake db:seed_fu RAILS_ENV=production
    
Checking status:
160

Valery Sizov's avatar
Valery Sizov committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
    sudo -u gitlab bundle exec rake gitlab_status


    # OUTPUT EXAMPLE
    Starting diagnostic
    config/database.yml............exists
    config/gitlab.yml............exists
    /home/git/repositories/............exists
    /home/git/repositories/ is writable?............YES
    remote: Counting objects: 603, done.
    remote: Compressing objects: 100% (466/466), done.
    remote: Total 603 (delta 174), reused 0 (delta 0)
    Receiving objects: 100% (603/603), 53.29 KiB, done.
    Resolving deltas: 100% (174/174), done.
    Can clone gitolite-admin?............YES
    UMASK for .gitolite.rc is 0007? ............YES

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
178
If you got all YES - congrats! You can go to next step.  
Valery Sizov's avatar
Valery Sizov committed
179 180 181

# 5. Server up

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
182
Application can be started with next command:
183

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
184
    # For test purposes 
Valery Sizov's avatar
Valery Sizov committed
185 186
    sudo -u gitlab bundle exec rails s -e production

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
187 188
    # As daemon
    sudo -u gitlab bundle exec rails s -e production -d
Valery Sizov's avatar
Valery Sizov committed
189 190 191 192 193 194 195 196 197

#  6. Run resque process (for processing queue).

    # Manually
    sudo -u gitlab bundle exec rake environment resque:work QUEUE=* RAILS_ENV=production BACKGROUND=yes

    # Gitlab start script
    ./resque.sh

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
198 199 200 201

** Ok - we have a working application now. **
** But keep going - there are some thing that should be done **

Valery Sizov's avatar
Valery Sizov committed
202 203 204 205 206 207 208
# Nginx && Unicorn

### Install Nginx

    sudo apt-get install nginx

## Unicorn
209

Valery Sizov's avatar
Valery Sizov committed
210 211
    cd /home/gitlab/gitlab
    sudo -u gitlab cp config/unicorn.rb.orig config/unicorn.rb
Valeriy Sizov's avatar
Valeriy Sizov committed
212
    sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D
Valery Sizov's avatar
Valery Sizov committed
213

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
214 215
Edit /etc/nginx/nginx.conf. Add next code to **http** section:

Valery Sizov's avatar
Valery Sizov committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
    upstream gitlab {
        server unix:/tmp/gitlab.socket;
    }

    server {
        listen 80;
        server_name mygitlab.com;

        location / {

            root /home/gitlab/gitlab/public;

            if (!-f $request_filename) {
                proxy_pass http://gitlab; 
                break;
            }
        }

    }

mygitlab.com - change to your domain.
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
237

Valery Sizov's avatar
Valery Sizov committed
238
Restart nginx:
239

Valery Sizov's avatar
Valery Sizov committed
240
    /etc/init.d/nginx restart
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
241

Valery Sizov's avatar
Valery Sizov committed
242
Create init script in /etc/init.d/gitlab:
243

Valery Sizov's avatar
Valery Sizov committed
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
    #! /bin/bash
    ### BEGIN INIT INFO
    # Provides:          unicorn
    # Required-Start:    $local_fs $remote_fs $network $syslog
    # Required-Stop:     $local_fs $remote_fs $network $syslog
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: starts the unicorn web server
    # Description:       starts unicorn
    ### END INIT INFO
    
    DAEMON_OPTS="-c /home/gitlab/gitlab/config/unicorn.rb -E production -D"
    NAME=unicorn
    DESC="Gitlab service"
    PID=/home/gitlab/gitlab/tmp/pids/unicorn.pid
259
    RESQUE_PID=/home/gitlab/gitlab/tmp/pids/resque_worker.pid
Valery Sizov's avatar
Valery Sizov committed
260 261 262 263 264

    case "$1" in
      start)
            CD_TO_APP_DIR="cd /home/gitlab/gitlab"
            START_DAEMON_PROCESS="bundle exec unicorn_rails $DAEMON_OPTS"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
265
            START_RESQUE_PROCESS="./resque.sh"
Valery Sizov's avatar
Valery Sizov committed
266 267 268

            echo -n "Starting $DESC: "
            if [ `whoami` = root ]; then
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
269
              sudo -u gitlab sh -c "$CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS && $START_RESQUE_PROCESS"
Valery Sizov's avatar
Valery Sizov committed
270
            else
271
              $CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS && $START_RESQUE_PROCESS
Valery Sizov's avatar
Valery Sizov committed
272 273 274 275 276 277
            fi
            echo "$NAME."
            ;;
      stop)
            echo -n "Stopping $DESC: "
            kill -QUIT `cat $PID`
278
            kill -QUIT `cat $RESQUE_PID`
Valery Sizov's avatar
Valery Sizov committed
279 280 281 282 283
            echo "$NAME."
            ;;
      restart)
            echo -n "Restarting $DESC: "
            kill -USR2 `cat $PID`
284
            kill -USR2 `cat $RESQUE_PID`
Valery Sizov's avatar
Valery Sizov committed
285 286 287 288 289
            echo "$NAME."
            ;;
      reload)
            echo -n "Reloading $DESC configuration: "
            kill -HUP `cat $PID`
290
            kill -HUP `cat $RESQUE_PID`
Valery Sizov's avatar
Valery Sizov committed
291 292 293 294 295 296 297 298 299 300
            echo "$NAME."
            ;;
      *)
            echo "Usage: $NAME {start|stop|restart|reload}" >&2
            exit 1
            ;;
    esac

    exit 0

Valery Sizov's avatar
Valery Sizov committed
301
Adding permission:
302

Valery Sizov's avatar
Valery Sizov committed
303 304
    sudo chmod +x /etc/init.d/gitlab

Valery Sizov's avatar
Valery Sizov committed
305
When server is rebooted then gitlab must starting:
306

Valery Sizov's avatar
Valery Sizov committed
307 308
    sudo update-rc.d gitlab defaults

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
309
Now you can start/restart/stop gitlab like:
310

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
311
    sudo /etc/init.d/gitlab restart