Skip to content
This repository has been archived by the owner on May 12, 2018. It is now read-only.

Debian Squeeze complete Installation 'script' with RVM

Blackskyliner edited this page Mar 6, 2013 · 8 revisions

As I reviewed the installation of my gitlab I created this script for users somehow more advanced on the topic.

So I don't have to read the installation.md of the public doc's and need to scroll and think all the way :) I also did removed the unnecessary sudo callling all the time and su'ed to the user instead, as I also had problems getting sudo and rvm working correctly for executing the rake commands, as I would have need to cd in the gitlab, as the -i switch, which I would have needed to execute the RVM environment sourcing, will kick me to the ~ home path of the user. So I there would be the need of an script doing the work. Scripts however should not be executed via sudo as the application the script calls maybe don't get executed in the sudo context and so on and so of, thats why I replaced sudo with su in most cases.

Next addition: I use RVM for all ruby projects to keep the public server space clean of ruby (or if you have redmine installed via debian packages and don't want to mess with it etc.). So I added this to Gitlab's installation proccess, similiar as the Gitlab-CI uses RVM.

The script implies that you are the 'root' user. If commands are executed as another user (su'ed), or in some custom-shell (like mysql) it is visually indented. sudo however was not indented.

Do not copy this in a .sh and execute it. It is intended to be used as copy-paste script. It would be too complex and easily broken by updates @master if I would add more magic to do the whole configuration stuff automatically

Ohh yea, the script installs the @master branch as it offers the most features (like redmine integration) in a somewhat usable state. If you want to change the version just look at the available branches after cloning the gitlab project with git branch -a and select one with git checkout branch-name-here

The Script:

# Enable backports
echo "deb http://backports.debian.org/debian-backports squeeze-backports main" >> /etc/apt/sources.list

# System up-to-date
apt-get update && apt-get dist-upgrade
apt-get install sudo

# Install all packages we need (nginx will be installed later... see :156)
apt-get install -y \
                vim \
                \
                build-essential \
                checkinstall \
                gcc \
                make \
                automake \
                \
                wget \
                curl \
                \
                openssh-server \
                \
                git-core \
                \
                mysql-server \
                mysql-client \
                sqlite3 \
                \
                libsqlite3-dev \
                zlib1g-dev \
                libyaml-dev \
                libssl-dev \
                libgdbm-dev \
                libreadline-dev \
                libncurses5-dev \
                libffi-dev \
                libxml2-dev \
                libxslt-dev \
                libcurl4-openssl-dev \
                libicu-dev \
                libxml2-dev \
                libxslt-dev \
                libcurl4-openssl-dev \
                libreadline6-dev \
                libc6-dev \
                libssl-dev \
                libmysql++-dev \
                zlib1g-dev \
                libyaml-dev \
                libpq-dev \
                libmysqlclient-dev

# Install Postfix for mail sending (optional)
apt-get install postfix

# Redis from backports 2.x +
apt-get install -y -t squeeze-backports redis-server

# Install python (2.x preferable, if python --version is 3.x+ use python27)
apt-get install python

# Ensure python2 exists (needed by gitlab)
which python2 || ln -s /usr/bin/python /usr/bin/python2

# Add Gitlab user
adduser --disabled-login --gecos 'GitLab' git
su git
    # Set git username and email
    git config --global user.name  "GitLab"
    git config --global user.email "gitlab@localhost"

    # Install Ruby RVM with ruby1.9.3
    \curl -L https://get.rvm.io | bash -s stable
    source ~/.profile
    rvm
    rvm get head
    rvm reload
    rvm install 1.9.3
    rvm --default use 1.9.3
    echo "source /home/git/.rvm/scripts/rvm" >> .bashrc
    source /home/git/.rvm/scripts/rvm

    # Install bundler
    gem install bundler

    # Clone & Install GitlabShell
    git clone https://github.com/gitlabhq/gitlab-shell.git
    cd gitlab-shell
    cp config.yml.example config.yml
    vim config.yml
    ./bin/install

    exit

# Create Database
mysql -u root -p

    CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'YOUR GITLAB PASSWORD HERE';
    CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
    GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
    \q


# Test SQL (need to enter YOUR GITLAB PASSWORD)
sudo -u git -H mysql -u gitlab -p -D gitlabhq_production

cd /home/git

# Clone gitlab
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
cd /home/git/gitlab
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
vim config/gitlab.yml


# 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
sudo -u git -H mkdir /home/git/gitlab-satellites

# Create temp and make sure its wirtable
sudo -u git -H mkdir tmp/pids/
sudo chmod -R u+rwX  tmp/pids/

# Copy config templates
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
sudo -u git cp config/database.yml.mysql config/database.yml

# Configure database
vim config/database.yml

# Setup gitlab dependencies and database
su git
    gem install charlock_holmes --version '0.6.9'
    bundle install --deployment --without development test postgres

    bundle exec rake db:setup RAILS_ENV=production
    bundle exec rake db:seed_fu RAILS_ENV=production
    bundle exec rake gitlab:setup RAILS_ENV=production

    # Check configuration
    bundle exec rake gitlab:env:info RAILS_ENV=production

    exit

# Install init.d-script and run gitlab's sidekiq and unicorn
curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab
chmod +x /etc/init.d/gitlab
/etc/init.d/gitlab start
update-rc.d gitlab defaults 21

# Install nginx and install gitlab site-config
apt-get install nginx
curl --output /etc/nginx/sites-available/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/nginx/gitlab
ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
vim /etc/nginx/sites-available/gitlab
service nginx restart

# Check if everything works
su git
cd /home/git/gitlab
bundle exec rake gitlab:check RAILS_ENV=production