Last Updated: February 25, 2016
·
2.198K
· jlferrer

Update Gitlab via cron

Starting with Gitlab version 7.0 the upgrade script has moved to bin/upgrade.rb. The upgrading proccess is pretty well documented.

As Gitlab is released on 22nd of every month, the following shell script can be added to cron in order to be executed monthly that updated gitlab and gitlab shell. It supposes that GitLab Community Edition runs in production mode in a single host and it has been already configured in the standard folders.


#!/bin/sh

cd /home/git/gitlab

# Backup database and stop the service
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
sudo service gitlab stop

# Run the Upgrade
if [ -f bin/upgrade.rb ]; then sudo -u git -H ruby bin/upgrade.rb -y; else sudo -u git -H ruby script/upgrade.rb -y; fi

# Restart the services
sudo service gitlab start
sudo service nginx restart

# Run this command to check gitlab status
# sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

cd /home/git/gitlab-shell
sudo -u git -H git fetch

#Automatic way to upgrade gitlab-shell
# Rake task to upgrade gitlab-shell
cd /home/git/gitlab
GITLAB_SHELL_CURRENT=`sudo -u git -H cat /home/git/gitlab-shell/VERSION`
GITLAB_SHELL_VERSION=`sudo -u git -H cat /home/git/gitlab/GITLAB_SHELL_VERSION`

if [ $GITLAB_SHELL_VERSION != $GITLAB_SHELL_CURRENT ]; then
    sudo -u git -H bundle exec rake gitlab:shell:install[v$GITLAB_SHELL_VERSION] REDIS_URL=redis://localhost:6379 RAILS_ENV=production  
# Customize configuration for gitlab shell, accept self_signed certificate
# not configured via gitlab/config/gitlab.yml
# Uncomment the line if required
# sudo -u git -H sed -i 's/self_signed_cert: false/self_signed_cert: true/g' /home/git/gitlab-shell/config.yml

fi

For example, to run the script at 00:05 of every 23rd day of month, update your crontab file:

# m h dom mon dow user  command
05 0    23 * *  root    ( cd /home/git && sh ./upgrade_gitlab.sh )