Gitlabアップデート 6.0 -> 7.2

===========================

[Gitlab 5.0のインストール (CentOS 6.5)](http://qiita.com/shufo/items/6fb1bd067ec7e5d47902)
[Gitlabアップデート 5.0 -> 6.0](http://qiita.com/shufo/items/f27e62e23b048a5721c0)

の後に行った作業です。

## Requirements

- CentOS (Tested on 6.5)
- ruby (Tested on 2.1.2)

## Upgrade

- gitlab停止

```
service gitlab stop
```

- バックアップ

```
su - git
cd /home/git/gitlab
mkdir /home/git/gitlab/public/uploads
chown git:git /home/git/gitlab/public/uploads
bundle exec rake gitlab:backup:create RAILS_ENV=production
```

- rubyをアップグレード

```bash
su - git
curl -sSL https://get.rvm.io | bash -s stable
rvm install 2.1.2
cd /home/git/gitlab
echo ruby-2.1.2 > .ruby-version
```

- /etc/init.d/gitlabに以下を追記

```
export GEM_HOME=/home/git/.rvm/gems/ruby-2.1.2
export MY_RUBY_HOME=/home/git/.rvm/rubies/ruby-2.1.2
export PATH=/home/git/.rvm/gems/ruby-2.1.2/bin:/home/git/.rvm/gems/ruby-2.1.2@global/bin:/home/git/.rvm/rubies/ruby-2.1.2/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/git/.rvm/bin:/home/git/bin:/home/git/.rvm/bin
export GEM_PATH=/home/git/gitlab/vendor/bundle:/home/git/.rvm/gems/ruby-2.1.2:/home/git/.rvm/gems/ruby-2.1.2@global
export RUBY_VERSION=ruby-2.1.2
```

- bashrcにも追記

```
export GEM_HOME=/home/git/.rvm/gems/ruby-2.1.2
export MY_RUBY_HOME=/home/git/.rvm/rubies/ruby-2.1.2
export PATH=/home/git/.rvm/gems/ruby-2.1.2/bin:/home/git/.rvm/gems/ruby-2.1.2@global/bin:/home/git/.rvm/rubies/ruby-2.1.2/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/git/.rvm/bin:/home/git/bin:/home/git/.rvm/bin
export GEM_PATH=/home/git/gitlab/vendor/bundle:/home/git/.rvm/gems/ruby-2.1.2:/home/git/.rvm/gems/ruby-2.1.2@global
export RUBY_VERSION=ruby-2.1.2
```

- rootユーザにもrvmをシングルモードでインストール

```
echo 'export rvm_prefix="$HOME"' > /root/.rvmrc
echo 'export rvm_path="$HOME/.rvm"' >> /root/.rvmrc
curl -sSL https://get.rvm.io | bash -s stable
rvm install 1.9.3
echo 'source "$HOME/.rvm/scripts/rvm"' >> /root/.bashrc
```

- gitlab最新のコードを取得&チェックアウト

```
git fetch --all
git checkout 7-2-stable
```

- gitlab-shellのアップグレード

```bash
cd /home/git/gitlab-shell
sudo -u git -H git fetch
sudo -u git -H git checkout v1.9.7
```

- 依存パッケージのインストール、マイグレーション、その他

```
yum install cmake
bundle install --verbose --without development test postgres --deployment
bundle exec rake migrate_iids RAILS_ENV=production
bundle exec rake db:migrate RAILS_ENV=production
bundle exec rake assets:clean assets:precompile cache:clear RAILS_ENV=production
chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites
```

- コンフィグファイルの更新

```
cd /home/git/gitlab/config
cp gitlab.yml{,.bak}
curl -L -O  https://gitlab.com/gitlab-org/gitlab-ce/raw/7-2-stable/config/gitlab.yml.example
cp gitlab.yml.example gitlab.yml
vim gitlab.yml
環境に合わせて編集

cp unicorn.rb{,.bak}
curl -L -O https://gitlab.com/gitlab-org/gitlab-ce/raw/7-2-stable/config/unicorn.rb.example
cp unicorn.rb.example unicorn.rb
vim unicorn.rb
環境に合わせて編集
```

```
cd /home/git/gitlab
cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
```

```
cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
```

```
# initスクリプト更新
cp lib/support/init.d/gitlab /etc/init.d/gitlab
```

- gitlab起動

```
service gitlab start
```