Maintenance mode not working

Nextcloud version: 27.1.0
Operating system and version: Debian12
Apache version: Apache/2.4.57
PHP version: 8.2.7

Enabling maintenance mode doesn’t take effect until I restart the service.

This is the first time I notice this bug.

Steps to replicate it:

  1. With root access I enable maintenance mode with command php occ maintenance:mode --on which gives me the message: “Maintenance mode enabled”

  2. When I go on instance’s website I see that maintenance mode is not enabled.

  3. Maintenance mode is only activated after restarting Apache2 (But this is not what I want)

At the moment of running php occ maintenance:mode --on I see this message written in Nextcloud’s logs:

{"reqId":"xxxxxxxxx","level":0,"time":"2023-09-19T04:32:29+00:00","remoteAddr":"","user":"--","app":"serverDI","method":"","url":"--","message":"The requested alias \"SystemConfig\" is deprecated. Please request \"OC\\SystemConfig\" directly. This alias will be removed in a future Nextcloud version.","userAgent":"--","version":"27.1.0.7","data":{"app":"serverDI"}}

In my config.php file I have:

'maintenance' => true,

I don’t see any errors in Apache2 logs

Hi, I see there is a Please request \"OC\\SystemConfig\" directly
and you are attempting this as root when Nextcloud is using www-data from Debian and Ubuntu.

Try issuing the occ command as www-data with sudo for proper permissions. Also read these docs for more info Using the occ command — Nextcloud latest Administration Manual latest documentation

You can also check the ownership and permissions of nextcloud system folder on the server with ls -la to confirm whether it is owned by some variation or root instead of www-data:www-data

I’m accessing Nexctloud server with root and running the occ command using www-data like so: sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on

ls -la of Nextcloud’s directory gives the ownership: www-data:www-data

2 Likes

This one worked for me, first enable maintenance mode, then (check PHP version and) restart php

sudo -u www-data php occ maintenance:mode --on
php -v
systemctl restart php8.1-fpm

1 Like

for my case I found the reason behind maintenance mode not getting enabled.

In the configuration of my opcache I have: opcache.validate_timestamps = 0

and the command php occ maintenance:mode --on does a change to config.php; it changes the parameter maintenance to true : 'maintenance' => true,

while by setting opcache.validate_timestamps = 0 opcache doesn’t check the updated version of config.php and maintenance mode doesn’t get enabled.

In the documentation they talk about this:
https://docs.nextcloud.com/server/latest/admin_manual/installation/server_tuning.html#enable-php-opcache

So, the solution is either to change the value of opcache.validate_timestamps or each time restart PHP, manually clear the cache, or invalidate this particular script in opcache.

2 Likes