Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

GitLab Patch & Safe Restart Guide

· 4 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide walks you through patching a self-managed GitLab instance and restarting it safely, minimizing downtime and avoiding data corruption. You'll learn how to back up, apply updates, restart services correctly, and recover if something goes wrong.

What You'll Need

  • Root or sudo access to the GitLab server.
  • SSH access to the server (or a console session).
  • Enough disk space for backups and the new package (check with df -h).
  • The latest GitLab package or repository URL for your OS (CentOS/RHEL, Ubuntu/Debian, etc.).
  • A maintenance window, especially if you have many users.

Step-by-Step

  1. Read the release notes and upgrade path. Check the GitLab website for the version you're moving to. If you're upgrading across multiple major versions, you may need to upgrade incrementally (e.g., 14.x → 15.x → 16.x). Skipping major versions can break the database.
  2. Notify users and schedule downtime. Even though GitLab supports zero-downtime upgrades, it's safer to schedule a brief maintenance window. Announce it via email or chat.
  3. Take a full backup. Run sudo gitlab-backup create (or sudo gitlab-rake gitlab:backup:create on older versions). This creates a tar.gz file in /var/opt/gitlab/backups. Also backup the configuration files: sudo tar -czf /tmp/gitlab-config.tgz /etc/gitlab. Verify the backup files exist and are non-empty.
  4. Check the current version. Run sudo gitlab-rake gitlab:env:info or look at /opt/gitlab/version. Note your current version.
  5. Update the package repository. For Ubuntu/Debian: sudo apt update. For CentOS/RHEL: sudo yum check-update or sudo dnf check-update.
  6. Install the new GitLab package. Use sudo apt install gitlab-ce or sudo yum install gitlab-ce (or gitlab-ee if you use Enterprise Edition). This will automatically run migrations and restart services. If you're using an offline package, download the .deb or .rpm file and install it with sudo dpkg -i gitlab-ce-*.deb or sudo rpm -Uvh gitlab-ce-*.rpm.
  7. Run sudo gitlab-ctl reconfigure. This ensures all configuration files are up to date and services are started correctly. It's safe to run multiple times.
  8. Check the status of all services. Run sudo gitlab-ctl status to ensure all services (e.g., postgresql, redis, puma, sidekiq) are running. If any are down, start them with sudo gitlab-ctl start.
  9. Verify the upgrade. Visit your GitLab URL and log in. Check a few projects, issues, and the admin area. Also run sudo gitlab-rake gitlab:check to verify the installation is healthy.
  10. If you need to restart GitLab manually (e.g., after a config change), use sudo gitlab-ctl restart. For a full stop and start, use sudo gitlab-ctl stop followed by sudo gitlab-ctl start. Avoid using reboot unless necessary.

Common Mistakes

  • Skipping backups. Always back up before patching. A failed migration can corrupt data.
  • Upgrading across major versions directly. This often leads to database errors. Follow the upgrade path.
  • Ignoring disk space. GitLab needs space for backups, packages, and new data. Running out of disk mid-upgrade can break everything.
  • Using gitlab-ctl restart after a config change but not running reconfigure. Some changes require reconfigure to apply.
  • Not checking service status after the upgrade. A service might silently fail, causing intermittent issues.

Tips

  • Use a staging environment that mirrors production to test the upgrade first.
  • For large instances, consider a rolling upgrade using gitlab-ctl deploy (for EE) or manually restarting services one by one.
  • Set up monitoring (e.g., Prometheus) to watch for issues after the upgrade.
  • Read the specific upgrade notes for your version—they often include manual steps.
  • Keep a copy of the previous package (e.g., in /opt/gitlab/backups) in case you need to roll back.

Troubleshooting

  • GitLab won't start after upgrade. Check logs: sudo gitlab-ctl tail. Look for errors related to database migrations or configuration. If migrations failed, run sudo gitlab-rake db:migrate manually.
  • Database connection errors. Ensure PostgreSQL is running: sudo gitlab-ctl status postgresql. If not, start it and then reconfigure.
  • 500 errors on pages. This often indicates a background job issue. Restart Sidekiq: sudo gitlab-ctl restart sidekiq.
  • Disk full. Free up space by removing old backups (keep at least one) and cleaning logs. Then retry the upgrade.
  • Rollback. If you have a backup, you can restore it: sudo gitlab-backup restore BACKUP_TIMESTAMP. This will revert the database and files, but you'll need to reinstall the previous package version.

Frequently Asked Questions

How long does a GitLab patch take?

It depends on your instance size and version gap. A minor patch can take 10-30 minutes; a major upgrade might take an hour or more.

Can I skip versions when upgrading?

No, you should upgrade one major version at a time. Skipping can cause database migration errors.

What is zero-downtime upgrade?

It's a method where you upgrade one service at a time, so GitLab keeps serving requests. It's available for EE and CE, but requires careful steps (see the official docs).

Do I need to take a backup if I'm only patching a security fix?

Yes, always take a backup before any package change. Even small patches can introduce issues.

How do I know if my backup is valid?

Check the backup file size and timestamp. You can also restore it to a test instance to verify.

What should I do if the upgrade fails halfway?

Don't panic. Check the logs, try to resolve the specific error, and if needed, restore from backup. It's better to roll back than to force a broken upgrade.