dokuwiki / docker

The official Docker image for DokuWiki
https://hub.docker.com/r/dokuwiki/dokuwiki
35 stars 4 forks source link

Healthcheck fails due to undefined constant #15

Closed Maffsie closed 1 month ago

Maffsie commented 1 month ago

Hi!

I migrated from the bitnami/dokuwiki image after finding out that it was deprecated, unmaintained and broken (would sure be nice if bitnami said this somewhere other than on their github issue tracker..) and almost everything worked, however the healthcheck never seems to actually pass.

If I shell into the container and replace the contents of /var/www/html/health.php with just ok then I can stop the service from restarting, but that's obviously no fix. It looks like the inclusion of define('DOKU_UNITTEST', 1); in the included health.php causes the logger to attempt to log to dokuwiki\STDERR when it fails to load a plugin, but that constant isn't defined.

Stack trace:

PHP Warning:  Uncaught Error: Undefined constant "dokuwiki\STDERR" in /var/www/html/inc/Logger.php:231
Stack trace:
#0 /var/www/html/inc/Logger.php(152): dokuwiki\Logger->writeLogLines()
#1 /var/www/html/inc/ErrorHandler.php(135): dokuwiki\Logger->log()
#2 /var/www/html/inc/ErrorHandler.php(93): dokuwiki\ErrorHandler::logException()
#3 /var/www/html/inc/Extension/PluginController.php(132): dokuwiki\ErrorHandler::showExceptionMsg()
#4 /var/www/html/inc/pluginutils.php(55): dokuwiki\Extension\PluginController->load()
#5 /var/www/html/inc/Extension/EventHandler.php(32): plugin_load()
#6 /var/www/html/inc/init.php(230): dokuwiki\Extension\EventHandler->__construct()
#7 /var/www/html/health.php(9): require('...')
#8 {main}
  thrown in /var/www/html/inc/Logger.php on line 231

Interestingly, I'm unable to identify what plugin it's failing to load; no log is generated otherwise. Tried disabling every single non-bundled plugin other than the ADFS plugin, but no dice, and the ADFS plugin is demonstrably working fine.

As a work-around, I have a slightly-edited health.php mounted on top of the shipped file.

xme commented 1 month ago

Working on the same task (migrating from the bitnami image) and facing the same situation! If you disable the health check in the compose file, it works (another workaround)

splitbrain commented 1 month ago

Interesting. Can you try changing STDERR to php://stderr in /var/www/html/inc/Logger.php:231 and report if that works?

splitbrain commented 1 month ago

actually you probably need this:

            $stderr = fopen('php://stderr', 'w');
            fwrite($stderr, "\n[" . $this->facility . '] ' . implode("\n", $lines) . "\n");
            fclose($stderr);
Maffsie commented 1 month ago

@splitbrain Will patch it and see if that works

Maffsie commented 1 month ago

actually you probably need this:

            $stderr = fopen('php://stderr', 'w');
            fwrite($stderr, "\n[" . $this->facility . '] ' . implode("\n", $lines) . "\n");
            fclose($stderr);

Adding this to my Logger.php did indeed allow the shipped health.php to work normally. It logged:

[deprecated] 2024-08-26 14:16:09        utf8_strtolower() is deprecated. It was called from auth_plugin_adfs::cleanUser() in /storage/lib/plugins/adfs/auth.php:155 dokuwiki\Utf8\PhpString::strtolower() should be used instead!

So it looks like the plugin causing this issue to appear was ADFS after all.

splitbrain commented 1 month ago

just to make sure it works as intended. health.php returns OK and the message above is logged to the apache log only, right?

Could you quickly check something else? Could you undo the changes and instead add the following at the top of health.php to see if that would work:

define('STDERR', fopen('php://stderr', 'w'));

(because I could ship this kind of fix in the docker image, while the other fix would need to wait for the next dokuwiki release)

Maffsie commented 1 month ago

@splitbrain Checked, no dice - the "Undefined constant" errors return if I revert and do that instead.

splitbrain commented 1 month ago

damn. okay. thanks for checking

Maffsie commented 1 month ago

just to make sure it works as intended. health.php returns OK and the message above is logged to the apache log only, right?

Could you quickly check something else? Could you undo the changes and instead add the following at the top of health.php to see if that would work:

define('STDERR', fopen('php://stderr', 'w'));

(because I could ship this kind of fix in the docker image, while the other fix would need to wait for the next dokuwiki release)

@splitbrain My mistake - I messed up something while changing the health.php file - the above does work. Sorry for the false-negative!

splitbrain commented 1 month ago

ohh. nice. I was racking my head here why it shouldn't work :-)