Last active
June 27, 2017 10:20
-
-
Save pida42/86313c10a01b40b1529bb02a354f5467 to your computer and use it in GitHub Desktop.
Basic GitLab update script (from sources)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## | |
# Usage: | |
# $ cd /home/git/gitlab | |
# $ CURRENT_VERSION=8-9-stable TARGET_VERSION=8-10-stable SHELL_VERSION=v3.2.3 WORKHOUSE_VERSION=v0.7.8 sh update.sh | |
## | |
cd /home/git/gitlab/ | |
set +x | |
CURRENT_VERSION=${CURRENT_VERSION:-'8-2-stable'} | |
TARGET_VERSION=${TARGET_VERSION:-'8-3-stable'} | |
SHELL_VERSION=${SHELL_VERSION:-'v2.6.8'} | |
WORKHOUSE_VERSION=${WORKHOUSE_VERSION:-'0.4.2'} | |
echo -n "\n--- START UPDATE ---\n" | |
echo -n "\n" | |
echo -n "CURRENT_VERSION : $CURRENT_VERSION\n" | |
echo -n "TARGET_VERSION : $TARGET_VERSION\n" | |
echo -n "SHELL_VERSION : $SHELL_VERSION\n" | |
echo -n "WORKHOUSE_VERSION : $WORKHOUSE_VERSION\n" | |
echo -n "\n" | |
# ----------------------------------------------------------------------------------------- | |
read -r -p "Continue: Stop services [y|n] ? " REPLY | |
if [ "$REPLY" != "y" ] | |
then | |
echo -n "\nEnd ...\n" | |
exit 1 | |
fi | |
# Stop services | |
echo -n "Stopping services\n\n" | |
sudo service gitlab stop | |
# Fix permissions | |
echo -n "Trying to fix permissions\n\n" | |
chown -R git:git ../gitlab ../gitlab-shell/ ../gitlab-workhorse/ ../repositories/ /home/git/.config | |
read -r -p "Continue: Make backup [y|n] ? " REPLY | |
if [ "$REPLY" != "y" ] | |
then | |
echo -n "\nEnd ...\n" | |
exit 1 | |
fi | |
# Make backup | |
echo -n "Making backup\n\n" | |
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production | |
read -r -p "Continue: gitlab: Fetch latest version [y|n] ? " REPLY | |
if [ "$REPLY" != "y" ] | |
then | |
echo -n "\nEnd ...\n" | |
exit 1 | |
fi | |
# Get latest code | |
echo -n "gitlab: Fetching latest version\n\n" | |
sudo -u git -H git fetch --all | |
sudo -u git -H git add public/check.txt update.sh | |
sudo -u git -H git commit -m "check.txt and update.sh save" public/check.txt update.sh | |
sudo -u git -H git checkout -- db/schema.rb | |
sudo -u git -H git checkout $TARGET_VERSION | |
read -r -p "Continue: gitlab-shell: Fetch latest version [y|n] ? " REPLY | |
if [ "$REPLY" != "y" ] | |
then | |
echo -n "\nEnd ...\n" | |
exit 1 | |
fi | |
# Update gitlab-shell | |
echo -n "gitlab-shell: Fetching latest version\n\n" | |
cd ../gitlab-shell | |
sudo -u git -H git fetch --all | |
sudo -u git -H git checkout $SHELL_VERSION | |
read -r -p "Continue: gitlab-workhouse: Fetch latest version [y|n] ? " REPLY | |
if [ "$REPLY" != "y" ] | |
then | |
echo -n "\nEnd ...\n" | |
exit 1 | |
fi | |
# Replace gitlab-git-http-server with gitlab-workhorse | |
echo -n "gitlab-workhouse: Fetching latest version\n\n" | |
cd ../gitlab-workhorse | |
sudo -u git -H git fetch --all | |
sudo -u git -H git checkout $WORKHOUSE_VERSION | |
sudo -u git -H make | |
# Fix permissions | |
echo -n "Trying to fix permissions\n\n" | |
chown -R git:git ../gitlab ../gitlab-shell/ ../gitlab-workhorse/ ../repositories/ /home/git/.config | |
read -r -p "Continue: Install libs, migrations, etc. [y|n] ? " REPLY | |
if [ "$REPLY" != "y" ] | |
then | |
echo -n "\nEnd ...\n" | |
exit 1 | |
fi | |
# Install libs, migrations, etc. | |
echo -n "Installing libs, migrations, etc.\n\n" | |
cd ../gitlab | |
sudo -u git -H bundle install --without mysql development test --deployment | |
sudo -u git -H bundle clean | |
sudo -u git -H bundle exec rake db:migrate RAILS_ENV=production | |
sudo -u git -H bundle exec rake assets:clean assets:precompile cache:clear RAILS_ENV=production | |
read -r -p "Continue: Update configurations [y|n] ? " REPLY | |
if [ "$REPLY" != "y" ] | |
then | |
echo -n "\nEnd ...\n" | |
exit 1 | |
fi | |
# Update configuration files | |
echo -n "Updating configurations\n\n" | |
sudo -u git -H git config --global gc.auto 0 | |
git diff origin/$CURRENT_VERSION:config/gitlab.yml.example origin/$TARGET_VERSION:config/gitlab.yml.example | |
git diff origin/$CURRENT_VERSION:lib/support/init.d/gitlab.default.example origin/$TARGET_VERSION:lib/support/init.d/gitlab.default.example | |
#git diff origin/$CURRENT_VERSION:lib/support/nginx/gitlab origin/$TARGET_VERSION:lib/support/nginx/gitlab | |
read -r -p "Continue: Update init script [y|n] ? " REPLY | |
if [ "$REPLY" != "y" ] | |
then | |
echo -n "\nEnd ...\n" | |
exit 1 | |
fi | |
# Init script | |
echo -n "Updating init script\n\n" | |
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab | |
read -r -p "Continue: (re)start services [y|n] ? " REPLY | |
if [ "$REPLY" != "y" ] | |
then | |
echo -n "\nEnd ...\n" | |
exit 1 | |
fi | |
# Systemctl daemon reload | |
echo -n "Reloading systemctl daemon\n\n" | |
sudo systemctl daemon-reload | |
# Start application | |
echo -n "Starting gitlab\n\n" | |
sudo service gitlab start | |
echo -n "Restarting nginx\n\n" | |
sudo service nginx restart | |
read -r -p "Continue: Show info and make test [y|n] ? " REPLY | |
if [ "$REPLY" != "y" ] | |
then | |
echo -n "\nEnd ...\n" | |
exit 1 | |
fi | |
# Check application status | |
echo -n "Fetching informations\n\n" | |
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production | |
echo -n "Making final test\n\n" | |
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production | |
echo -n "\n\n--- END UPDATE ---\n" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment