Putting Self-Managed GitLab (Free) Into Maintenance Mode

HOW-TO
Published: January 18, 2023
Last Updated: June 22, 2023

Update 2023-06-22: I was recently asked if this still worked. So I've checked! This works with v16 of GitLab but only with EE. I've had no issue switching betweeen CE and EE, you get the exact same core functionality without a license. If you do switch, make sure you back up your instance before switching, just incase.

The company I work for are heavy GitLab users. Despite this, we use a self-managed instance on the core/free tier. We use to have ultimate, the top paid for tier but found we weren't using the extra features that came with it. After a review we decided to drop to the free tier. After we downgraded, I was rather annoyed to find that some basic features like the ability to email all users was no longer available! This also included the ability to put GitLab into maintenance mode from the UI! This mode puts GitLab into a read-only state which can be handy while performing updates or other maintenance tasks. After some digging I discovered that you can put GitLab into maintenance mode from the terminal.

Connect to the terminal of your GitLab host and open the GitLab Rails Console:

gitlab-rails console
output
 Ruby:         ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5) [x86_64-linux]
 GitLab:       15.7.5-ee (677cf66582b) EE
 GitLab Shell: 14.14.0
 PostgreSQL:   12.12
------------------------------------------------------------[ booted in 45.39s ]
irb(main):001:0> 

This can take some time to start. Now run the following command

Enable
::Gitlab::CurrentSettings.update!(maintenance_mode: true)
Output
=> true

GitLabs Read-Only Banner

It may take a minute for your GitLab instance to update, but users will start to see a banner stating that the instance of GitLab is read-only.

To disable maintenance mode run the following from the GitLab Rails Console.

Disable
::Gitlab::CurrentSettings.update!(maintenance_mode: false)
Output
=> true