Skip to content
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

Unable to enable maintenance mode when env.php is read only #24229

Closed
ihor-sviziev opened this issue Aug 22, 2019 · 11 comments
Closed

Unable to enable maintenance mode when env.php is read only #24229

ihor-sviziev opened this issue Aug 22, 2019 · 11 comments
Assignees
Labels
Component: Developer Event: cd-cologne19 Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Aug 22, 2019

Preconditions (*)

  1. Magento 2.3.2 & 2.3-develop
  2. Make env.php file read only: chmod -w app/etc/env.php or chmod 754 app/etc/env.php

Steps to reproduce (*)

  1. Run php bin/magento maintenance:enable -v

Expected result (*)

  1. Maintenance mode should be enabled

Actual result (*)

  1. Maintenance mode is not enabled
  2. Command fails with following output
    image
In PathValidator.php line 63:
                                                                                                          
  [Magento\Framework\Exception\ValidatorException]                                                        
  Path "/var/www/html/magento2/app/etc/" cannot be used with directory "/var/www/html/magento2/app/etc/"  
                                                                                                          

Exception trace:
 () at /var/www/html/magento2/vendor/magento/framework/Filesystem/Directory/PathValidator.php:63
 Magento\Framework\Filesystem\Directory\PathValidator->validate() at /var/www/html/magento2/vendor/magento/framework/Filesystem/Directory/Read.php:82
 Magento\Framework\Filesystem\Directory\Read->validatePath() at /var/www/html/magento2/vendor/magento/framework/Filesystem/Directory/Read.php:111
 Magento\Framework\Filesystem\Directory\Read->getAbsolutePath() at /var/www/html/magento2/vendor/magento/framework/Filesystem/Directory/Write.php:57
 Magento\Framework\Filesystem\Directory\Write->assertWritable() at /var/www/html/magento2/vendor/magento/framework/Filesystem/Directory/Write.php:326
 Magento\Framework\Filesystem\Directory\Write->openFile() at /var/www/html/magento2/vendor/magento/framework/Filesystem/Directory/Write.php:343
 Magento\Framework\Filesystem\Directory\Write->writeFile() at /var/www/html/magento2/vendor/magento/framework/App/DeploymentConfig/Writer.php:146
 Magento\Framework\App\DeploymentConfig\Writer->saveConfig() at /var/www/html/magento2/vendor/magento/framework/App/Cache/State.php:104
 Magento\Framework\App\Cache\State->persist() at /var/www/html/magento2/vendor/magento/framework/App/Cache/Manager.php:77
 Magento\Framework\App\Cache\Manager->setEnabled() at /var/www/html/magento2/vendor/magento/module-page-cache/Observer/SwitchPageCacheOnMaintenance.php:73
 Magento\PageCache\Observer\SwitchPageCacheOnMaintenance->turnOffFullPageCache() at /var/www/html/magento2/vendor/magento/module-page-cache/Observer/SwitchPageCacheOnMaintenance.php:55
 Magento\PageCache\Observer\SwitchPageCacheOnMaintenance->execute() at /var/www/html/magento2/vendor/magento/framework/Event/Invoker/InvokerDefault.php:88
 Magento\Framework\Event\Invoker\InvokerDefault->_callObserverMethod() at /var/www/html/magento2/vendor/magento/framework/Event/Invoker/InvokerDefault.php:74
 Magento\Framework\Event\Invoker\InvokerDefault->dispatch() at /var/www/html/magento2/vendor/magento/framework/Event/Manager.php:66
 Magento\Framework\Event\Manager->dispatch() at /var/www/html/magento2/vendor/magento/framework/App/MaintenanceMode.php:82
 Magento\Framework\App\MaintenanceMode->set() at /var/www/html/magento2/setup/src/Magento/Setup/Console/Command/AbstractMaintenanceCommand.php:90
 Magento\Setup\Console\Command\AbstractMaintenanceCommand->execute() at /var/www/html/magento2/vendor/symfony/console/Command/Command.php:255
 Symfony\Component\Console\Command\Command->run() at /var/www/html/magento2/vendor/symfony/console/Application.php:893
 Symfony\Component\Console\Application->doRunCommand() at /var/www/html/magento2/vendor/symfony/console/Application.php:262
 Symfony\Component\Console\Application->doRun() at /var/www/html/magento2/vendor/magento/framework/Console/Cli.php:105
 Magento\Framework\Console\Cli->doRun() at /var/www/html/magento2/vendor/symfony/console/Application.php:145
 Symfony\Component\Console\Application->run() at /var/www/html/magento2/bin/magento:23

maintenance:enable [--ip IP] [--magento-init-params MAGENTO-INIT-PARAMS]
  1. Exception message isn't saying anything, message not valid at all.

Additional info

Why it's important to keep env.php file read only - on production servers it's the only one way to make sure that no one will disable cache --> website will work fine.

My investigation shown that this issue appeared in 0e37353.
If i'll remove following observer - it works fine:

<event name="maintenance_mode_changed">
<observer name="page_cache_switcher_for_maintenance" instance="Magento\PageCache\Observer\SwitchPageCacheOnMaintenance"/>
</event>

I reviewed this commit and actually it's ok that FPC should not cache pages in maintenance mode, but disabling FPC at all- the wrong way.

What I would suggest - revert changes that were done in 0e37353 and add checking for maintenance flag in when we're sending public Cache-Control headers

@m2-assistant
Copy link

m2-assistant bot commented Aug 22, 2019

Hi @ihor-sviziev. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@ihor-sviziev do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Aug 22, 2019
@engcom-Charlie engcom-Charlie added Component: Developer Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Aug 23, 2019
@ghost ghost unassigned engcom-Charlie Aug 23, 2019
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Charlie
Thank you for verifying the issue. Based on the provided information internal tickets MC-19601 were created

Issue Available: @engcom-Charlie, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Aug 23, 2019
@irving0mar
Copy link

#cd19latam

@m2-assistant
Copy link

m2-assistant bot commented Aug 23, 2019

Hi @irving0mar. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


@irving0mar
Copy link

We can't reproduce this issue on Centos 7 and Magento 2.3-develop, give us more information please. For example, what is the OS you are using.

@ihor-sviziev
Copy link
Contributor Author

We can't reproduce this issue on Centos 7 and Magento 2.3-develop, give us more information please. For example, what is the OS you are using.

I had this issue on Ubuntu 18.04 and on Amazon Linux (Cent OS based). I don’t think it’s related.
I think main issue - you have to run bin/magento not from root user, because even without permissions root user could write to all files

@theCapypara
Copy link
Member

#cd-cologne19

@magento-engcom-team
Copy link
Contributor

@Parakoopa thank you for joining. Please accept team invitation here and self-assign the issue.

@m2-assistant
Copy link

m2-assistant bot commented Nov 28, 2019

Hi @Parakoopa. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


@theCapypara
Copy link
Member

theCapypara commented Nov 28, 2019

This issue is somewhat related to #4955. The best solution for the future would probably to solve that issue, this will also allow changing any cache state with a read-only env.php.

As a simple solution for this issue I will remove the observer Magento\PageCache\Observer\SwitchPageCacheOnMaintenance, which tries to disable the FPC when running maintenance mode to prevent pages being cached. Instead I will change it so, that the PageCache module does not generate cache entries during maintenance mode.

theCapypara added a commit to theCapypara/magento2 that referenced this issue Nov 29, 2019
…ublic cache headers

- Removes the observer for disabling and re-enabling the FPC during
  maintenande mode switch

- Disables setting public cache headers, if maintenance mode is enabled

- phpcs:ignore entries were added in places where no actual code was
  changed by this commit, but static tests failed
theCapypara added a commit to theCapypara/magento2 that referenced this issue Nov 29, 2019
@VladimirZaets
Copy link
Contributor

Hi @ihor-sviziev. Thank you for your report.
The issue has been fixed in #25790 by @Parakoopa in 2.4-develop branch
Related commit(s):

The fix will be available with the upcoming 2.4.0 release.

@VladimirZaets VladimirZaets added the Fixed in 2.4.x The issue has been fixed in 2.4-develop branch label Dec 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Developer Event: cd-cologne19 Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

6 participants