Use command line bin/directus maintenance:on and bin/directus maintenance:off to put the api into maintenance mode.
When maintenance mode is active, decline all requests with HTTP 503: Service unavailable. The App and other clients could then display a proper message to the user informing him of the maintenance state.
This prevents data changes via api during updates of the database.
The command line toggle sets a flag in the filesystem or the config. The router checks before dispatching the request and returns the status code if maintenance mode is active.
Shure i would love to.
The API currently already has a production and development mode (see https://github.com/directus/api/blob/master/config/api_sample.php#L5). I think adding a third option maintenance would be really useful 🙂
The only thing that's a bit tricky is that this flag is set in the php config file, and can't be updated by the API directly (yet). That means that the cli would have to write this in the actual config file 🤔
Or ...
I dont fully understand the difference between development and production mode. But in both modes you want the api to answer requests, while in maintenance you want to block requests. So using the same config option for all three seems unwise.
In addition you should not have to modify the configuration to enable/disable maintenance.
I would suggest another approach. cli writes/deletes a file in the logs/ directory (as you should already have write permission there) to enable/disable write permission. The router checks the presence/absence of the file to allow/deny requests. This also opens other approaches tools/scripts/whatever to create/remove the file and leaves the configuration untouched and unmodified.
Smart. Maintenance is definitely an _additional_ mode, not just a third. Is this _flag file_ in the logs better than saving a flag record in the database (eg: directus_settings)? Maybe the DB is a bad idea since it may be offline and unreadable?
If the flag file is in a writeable location (thats why i suggested logs/) you can enable/disable maintenance mode from shell, ftp or any other outside mechanism that is able to create/remove the file. This makes it very easy to integrate this into any deployment tool.
Having it in the database requires database access.
Therefore router has to validate the flag by looking it up in the database, which can become a performance issue. Just having to make a file_exists() check is significant faster.
💯 — I'm on board with this. @rijkvanzanten how about you?
Works for me!
To achieve better clarity/visibility, we are now tracking feature requests within the Feature Request project board.
This issue being closed does not mean it's not being considered.
This was implemented in https://github.com/directus/api/pull/889
Most helpful comment
If the flag file is in a writeable location (thats why i suggested logs/) you can enable/disable maintenance mode from shell, ftp or any other outside mechanism that is able to create/remove the file. This makes it very easy to integrate this into any deployment tool.
Having it in the database requires database access.
Therefore router has to validate the flag by looking it up in the database, which can become a performance issue. Just having to make a file_exists() check is significant faster.