When I do something bigger to a WordPress site, like a database search-replace or a batch of plugin updates, I don’t want visitors clicking around a half-changed site. WP-CLI has a command for maintenance mode, so you don’t need a plugin for it.
wp maintenance-mode activate
# do the work
wp maintenance-mode deactivate
The command has four subcommands: activate, deactivate, status and is-active. status prints a line you can read, and is-active answers with an exit code, so a script can check it. In the WP-CLI docs example, is-active returns 1 on a site that isn’t in maintenance.
A small script I’d use around updates:
wp maintenance-mode activate
wp plugin update --all
wp maintenance-mode deactivate
wp maintenance-mode status
The last line is there so you see with your own eyes that the site is back.
Caveat: if the script stops halfway, nothing switches maintenance off again. The site stays on hold until you run deactivate yourself, so in a script, make sure the deactivate step runs even when an update fails. There’s also a --force option on activate; the docs don’t say much more about it, so I’d leave it alone unless a plain activate refuses.
Further reading: WP-CLI: wp maintenance-mode