How to detect programatically (i.e. in bash) if NC is in manitenance mode?

Nextcloud version: 23.0.2
Operating system and version: Ubuntu 20.04
Apache or nginx version (eg, Apache 2.4.25): replace me
PHP version (eg, 7.4): replace me

The issue you are facing:

I have a nightly backup script. In this script I put NC into maintenance mode before making a backup of the database. Occasionally there is some minor issue which means NC gets left in maintenance mode. My issue is that I would like to detect that Nextcloud is in maintenance mode using a cron job, and notify me by email that there is an issue.

My question is therefore, how can I detect in bash that NC is in maintenance mode?

You can run occ config:system:get maintenance command

perfect, thanks!

the following script might be useful for others


#!/bin/bash

result=$(sudo -u www-data php /var/www/nextcloud/occ config:system:get maintenance)

if [ "$result" == "false" ]
then
    echo "on"
else
    echo "off"
fi

because if NC is in maintenance mode it returns this:

Nextcloud is in maintenance mode, hence the database isn't accessible.
Cannot perform any command except 'maintenance:mode --off'

true