-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: only load available commands in maintenance mode #37178
Conversation
* Implement if a core command is available in maintenance mode. | ||
* | ||
* A core command is a command registered in core/register_command.php. | ||
* Don't implement the interface if the command is registered in IBootstrap or info.xml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not? Talk has commands that could be run while maintenance is on?
Similar for files and others, maybe an admin restored a folder from a backup and wants to run file scan before sync clients interfere?
support:system-report, transfer-ownership, user-migration and others are also good examples for commands that could (maybe even should) be run in maintenance-mode.
As mentioned in #37365 also all the db:* commands are recommended to run in maintenance mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would even argue to default to "is available in maintenance mode" and have commands opt out of it.
But at the same time I would not know which command I would opt-out of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I updated the pull request description to add some more context.
To opt out is indeed much better than opt in here. Most commands in register_commands.php are okay to run in maintenance mode.
* | ||
*/ | ||
|
||
namespace OC\Console; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should definitely be in OCP for better usage.
a2e623a
to
22c6c28
Compare
lib/private/Console/Application.php
Outdated
* @return Command|null The registered command if enabled or null | ||
*/ | ||
public function add(Command $command) { | ||
if ($this->maintenanceMode && in_array(IUnavailableInMaintenanceMode::class, class_implements($command, false))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ($this->maintenanceMode && in_array(IUnavailableInMaintenanceMode::class, class_implements($command, false))) { | |
if ($this->maintenanceMode && $command instanceof IUnavailableInMaintenanceMode) { |
???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand your puzzlement ;)
class_implements is a leftover from an experiment. My idea was to change Command
to Command|string
and use the dependency injection to build the class when a string is given to clean up register_command.php a bit.
Will use instanceof for now and submit another pr sometime for the dependency injection feature.
core/register_command.php
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't find any changes apart from s/$application/$this/
correct?
The new interface is not being added anywhere (totally okay, just asking)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep.
8edc702
to
ae9457d
Compare
ae9457d
to
0f32ed8
Compare
Signed-off-by: Daniel Kesselberg <[email protected]>
0f32ed8
to
19ddc24
Compare
So if that is the reason, I would change the other half and also make sure to load all apps in CLI? Since we are approaching the next deadline in light speed maybe we can merge the interface and Application change in a single PR and discuss the implementing this quite restrictive behaviour in another one. |
As reference: owncloud/core#20939
You put your instance in maintenance mode to delete a user 🤔
I see your concern, we don't need to rush. Let's continue the work on this feature when 27 is done. My next task is to update the documentation: nextcloud/documentation#10063 |
Summary
In maintenance mode, the above message is printed for every command.
A customer brought to our attention that the message is misleading.
"isn't accessible" is a simplified statement.
Technically, the database is accessible, but it's probably unsafe to run commands that modify the system.
server/lib/base.php
Lines 1032 to 1053 in bb4b34f
server/lib/private/Console/Application.php
Lines 116 to 121 in 426c034
In maintenance mode, only a minimum set of apps is loaded.
The commands available in maintenance mode are mainly related to system operations.
It's fine and for some even recommended to run those commands in maintenance mode.
However, some commands are difficult:
user:delete
will emitBeforeUserDeletedEvent
andUserRemovedEvent
. We have a couple of apps listening for those events: https://github.com/search?q=org%3Anextcloud+%28UserRemovedEvent+OR+BeforeUserDeleted%29&type=codeuser:add
user:resetpassword
group:add
group:delete
group:adduser
group:removeuser
Just to name some examples.
My thought is, if we already know that a command is potentially unsafe, we should prevent the execution.
TODO
Checklist