Skip to content

Instantly share code, notes, and snippets.

@bigbigbang
Created July 29, 2013 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigbigbang/6104593 to your computer and use it in GitHub Desktop.
Save bigbigbang/6104593 to your computer and use it in GitHub Desktop.
Install gitlab 5.3-stable with ruby 2.0.0-p247
#!/bin/bash
# Installer for GitLab on RHEL 6 (Red Hat Enterprise Linux and CentOS)
#
##Export proxy settings
# or not ...
# Define the public hostname
export GL_HOSTNAME=$HOSTNAME
# Install from this GitLab branch
export GL_GIT_BRANCH="5-3-stable"
# Define the version of ruby the environment that we are installing for
export RUBY_VERSION="2.0.0-p247"
## Install epel-release
yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# Exit on error
die()
{
# $1 - the exit code
# $2 $... - the message string
retcode=$1
shift
printf >&2 "%s\n" "$@"
exit $retcode
}
echo "### Check OS (we check if the kernel release contains el6)"
uname -r | grep "el6" || die 1 "Not RHEL or CentOS 6 (el6)"
## work in /tmp
cd /tmp/
yum -y groupinstall 'Development Tools'
### 'Additional Development'
yum -y install vim-enhanced httpd readline readline-devel ncurses-devel gdbm-devel glibc-devel \
tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc \
sqlite-devel gcc-c++ libyaml libyaml-devel libffi libffi-devel \
libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel \
system-config-firewall-tui python-devel redis sudo mysql-server wget \
mysql-devel crontabs logwatch logrotate sendmail-cf qtwebkit qtwebkit-devel \
perl-Time-HiRes perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
yum remove -y git
chkconfig redis on
service redis start
chkconfig mysqld on
service mysqld start
## Install git 1.8.1.2
wget -O v1.8.1.2.tar.gz https://github.com/git/git/archive/v1.8.1.2.tar.gz
tar -xzvf ./v1.8.1.2.tar.gz
cd git-1.8.1.2/
make prefix=/usr/local all
make prefix=/usr/local install
## Httpd
chkconfig httpd on
touch /etc/httpd/conf.d/gitlab.conf
## Configure
cat > /etc/httpd/conf.d/gitlab.conf << EOF
ServerName servername.com
ProxyRequests Off
Order deny,allow
Allow from all
ProxyPreserveHost On
ProxyPass / http://localhost:9292/
ProxyPassReverse / http://localhost:9292/
EOF
setsebool -P httpd_can_network_connect on
# Ruby
## packages (from rvm install message):
yum -y install patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel
## Install rvm (instructions from https://rvm.io)
curl -L get.rvm.io | bash -s stable
## Load RVM
source /etc/profile.d/rvm.sh
## Fix for missing psych
## *It seems your ruby installation is missing psych (for YAML output).
## *To eliminate this warning, please install libyaml and reinstall your ruby.
## Run rvm pkg and add --with-libyaml-dir
rvm pkg install libyaml
## Install Ruby (use command to force non-interactive mode)
command rvm install $RUBY_VERSION --with-libyaml-dir=/usr/local/rvm/usr
rvm --default use $RUBY_VERSION
## Install core gems
gem install bundler
## Create a git user for Gitlab
adduser --system --shell /bin/bash --create-home --comment 'GitLab' git
service mysqld start
# Create a user for GitLab. (change supersecret to a real password)
echo "CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'supersecret';" | mysql -u root
### Create the database
echo "CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;" | mysql -u root
# Grant the GitLab user necessary permissopns on the table.
echo "GRANT SELECT,LOCK TABLES,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,ALTER ON gitlabhq_production.* TO 'gitlab'@'localhost';"\
| mysql -u root
# GitLab shell
cd /home/git/
## Clone GitLab
su - git -c "git clone https://github.com/gitlabhq/gitlab-shell.git"
## Checkout
su - git -c "cd gitlab-shell;git checkout v1.4.0"
## configure
su - git -c "cp /home/git/gitlab-shell/config.yml.example /home/git/gitlab-shell/config.yml"
sed -i "s|gitlab_url: http://localhost/|gitlab_url: http://cheftest-1.labs.arkea.com/|" /home/git/gitlab-shell/config.yml
## Run setup
su - git -c "/home/git/gitlab-shell/bin/install"
# GitLab
su - git -c "cd /home/git/"
## Clone GitLab
su - git -c "git clone https://github.com/gitlabhq/gitlabhq.git /home/git/gitlab"
## Checkout
su - git -c "cd gitlab;git checkout $GL_GIT_BRANCH"
## Configure GitLab
su - git -c "cd /home/git/gitlab"
### Copy the example GitLab config
su git -c "cp /home/git/gitlab/config/gitlab.yml.example /home/git/gitlab/config/gitlab.yml"
### Change gitlabhq hostname to GL_HOSTNAME
sed -i "s|host: localhost|host: $GL_HOSTNAME|" /home/git/gitlab/config/gitlab.yml
### Change the from email address
sed -i "s|from: gitlab@localhost|from: gitlab@$GL_HOSTNAME|" /home/git/gitlab/config/gitlab.yml
# Make sure GitLab can write to the log/ and tmp/ directories
chown -R git /home/git/gitlab/log/
chown -R git /home/git/gitlab/tmp/
chmod -R u+rwX /home/git/gitlab/log/
chmod -R u+rwX /home/git/gitlab/tmp/
#Create directory for satellites
su git -c "mkdir /home/git/gitlab-satellites"
# Create directories for sockets/pids and make sure GitLab can write to them
su git -c "mkdir /home/git/gitlab/tmp/pids/"
su git -c "mkdir /home/git/gitlab/tmp/sockets/"
chmod -R u+rwX /home/git/gitlab/tmp/pids/
chmod -R u+rwX /home/git/gitlab/tmp/sockets/
# Create public/uploads directory otherwise backup will fail
su git -c "mkdir /home/git/gitlab/public/uploads"
chmod -R u+rwX /home/git/gitlab/public/uploads
# Copy the example Puma config
su git -c "cp /home/git/gitlab/config/puma.rb.example /home/git/gitlab/config/puma.rb "
## Configure
cat > /home/git/gitlab/config/puma.rb << EOF
#!/usr/bin/env puma
# Start Puma with next command:
# RAILS_ENV=production bundle exec puma -C ./config/puma.rb
# uncomment and customize to run in non-root path
# note that config/gitlab.yml web path should also be changed
# ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"
application_path = '/home/git/gitlab'
directory application_path
environment 'production'
daemonize true
pidfile "#{application_path}/tmp/pids/puma.pid"
state_path "#{application_path}/tmp/pids/puma.state"
stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log"
# Configure “min” to be the minimum number of threads to use to answer
# requests and “max” the maximum.
#
# The default is “0, 16”.
#
# threads 0, 16
# Bind the server to “url”. “tcp://”, “unix://” and “ssl://” are the only
# accepted protocols.
#
# The default is “tcp://0.0.0.0:9292”.
#
bind 'tcp://127.0.0.1:9292'
# bind 'unix:///var/run/puma.sock'
# bind 'unix:///var/run/puma.sock?umask=0777'
# bind 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
# bind "unix://#{application_path}/tmp/sockets/gitlab.socket"
# Instead of “bind 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'” you
# can also use the “ssl_bind” option.
#
# ssl_bind '127.0.0.1', '9292', { key: path_to_key, cert: path_to_cert }
# Code to run before doing a restart. This code should
# close log files, database connections, etc.
#
# This can be called multiple times to add code each time.
#
# on_restart do
# puts 'On restart...'
# end
# Command to use to restart puma. This should be just how to
# load puma itself (ie. 'ruby -Ilib bin/puma'), not the arguments
# to puma, as those are the same as the original process.
#
# restart_command '/u/app/lolcat/bin/restart_puma'
# === Cluster mode ===
# How many worker processes to run.
#
# The default is “0”.
#
# workers 2
# GitLab cluster mode recommendations
# If you have more than 1 GB RAM, uncomment one of the following lines:
#
# workers 2 # if you have at least 1.5 GB RAM
# workers 3 # if you have at least 2 GB RAM
# workers 4 # if you have at least 2.5 GB RAM
# Code to run when a worker boots to setup the process before booting
# the app.
#
# This can be called multiple times to add hooks.
#
# on_worker_boot do
# puts 'On worker boot...'
# end
# === Puma control rack application ===
# Start the puma control rack application on “url”. This application can
# be communicated with to control the main server. Additionally, you can
# provide an authentication token, so all requests to the control server
# will need to include that token as a query parameter. This allows for
# simple authentication.
#
# Check out https://github.com/puma/puma/blob/master/lib/puma/app/status.rb
# to see what the app has availabhttp://alvinalexander.com/blog/post/mysql/show-users-i-ve-created-in-mysql-databasele.
#
# activate_control_app 'unix:///var/run/pumactl.sock'
# activate_control_app 'unix:///var/run/pumactl.sock', { auth_token: '12345' }
# activate_control_app 'unix:///var/run/pumactl.sock', { no_token: true }
EOF
### Copy database congiguration
su git -c "cp /home/git/gitlab/config/database.yml.mysql /home/git/gitlab/config/database.yml"
### Set MySQL root password in configuration file
sed -i "s|password|supersecret|" /home/git/gitlab/config/database.yml
## Install Charlock holmes
yum -y install libicu-devel
gem install charlock_holmes --version '0.6.9.4'
## For MySQL
cd /home/git/gitlab/
yum -y install mysql-devel
su git -c "bundle install --deployment --without development test postgres"
# Initialise Database and Activate Advanced Features
# Force it to be silent (issue 31)
export force=yes
su git -c "bundle exec rake gitlab:setup RAILS_ENV=production"
## Install init script
curl https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab-centos > /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab
## Fix for issue 30
# bundle not in path (edit init-script).
# Add after ". /etc/rc.d/init.d/functions" (row 17).
sed -i "17 a source /etc/profile.d/rvm.sh\nrvm use $RUBY_VERSION" /etc/init.d/gitlab
chkconfig --add gitlab
chkconfig gitlab on
service gitlab start
service httpd restart
echo "### Done ###############################################"
echo "#"
echo "#"
echo "# Point your browser to:"
echo "# http://$GL_HOSTNAME (or: http://)"
echo "# Default admin username: admin@local.host"
echo "# Default admin password: 5iveL!fe"
echo "#"
echo "###"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment