Enable maintenance mode at system start

Is it possible to configure nextcloud to start in maintenance mode at system start (every time). Because I need to encrypt my drives first with a script and would like to disable maintenance mode manual per script also.

You can setup this in config.php

@MelBourbon: Which OS are you using?

You can do this with init.d or systemd scripts. (depends on you OS.)

Debian stretch

Ah, right. I never worked with init.d so far. But this sounds feasible. Any links which may help me. Or can I create a simple sh script?

I assume, if I set maintenance to true in config.php but then disable maintenance per occ command later the value in the config.php is set back to false after reboot. Or am I wrong?


That value in config.php will be changed automatically when you enable/disable maintenance mode. It sounds like the script method is the way to go.

If you already have a script which encrypts the drives, just add the occ maintenance:mode --on to the beginning of that script (and maybe wait a few minutes to update all connected clients). Then at the end, run occ maintenance:mode --off

As for running automatically at startup, Debian Stretch uses systemd so you’ll need to write a config file and enable that as a service:


I’ve never done this personally, but it looks pretty straightforward.

Thanks, I tried to create a systemd script (seen below) but so far it’s not working. No time so far to figure out why. Maybe because of the sudo command line. Any ideas? Need to check the logs. I prefer the systemd script. Your option with enabling it in my encryption script is also fine but I want to achieve that Maintenance is set really at the beginning.


# Maintenance aktivieren
cd /var/www/nextcloud
sudo -u www-data php occ maintenance:mode --on


Description=Enable Maintenance on Nextcloud

If you need to guarantee that nothing tries to connect to Nextcloud when the server boots, another approach might be to disable the apache service from running in systemd, and then manually start it when your script is done running. Don’t even mess around with maintenance mode.
Otherwise configure the order by using Before= or After= in systemd to make sure the maintenance mode script runs before the encryption script: https://superuser.com/questions/544399/how-do-you-make-a-systemd-service-as-the-last-service-on-boot

Thanks, I already disable Apache and start it per script only of mounting ist sucessfull. So you say this is enough? I wanted to enable maintenance additional.

Without apache, no browsers or clients can access Nextcloud, so if that’s already disabled then there’s no reason to worry about maintenance mode.