Skip to content

Commit

Permalink
added health check
Browse files Browse the repository at this point in the history
The check runs the standard DokuWiki initialization, fatal errors should
get caught and be reported back to docker
  • Loading branch information
splitbrain committed Jun 2, 2024
1 parent 8d33e0f commit 9a12b5c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ RUN /bin/bash /build-setup.sh
VOLUME /storage
EXPOSE 8080

HEALTHCHECK --timeout=5s \
CMD curl --silent --fail-with-body http://localhost:8080/health.php || exit 1

RUN chmod +x /dokuwiki-entrypoint.sh
ENTRYPOINT ["/dokuwiki-entrypoint.sh"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ On first run, use DokuWiki's [installer](https://www.dokuwiki.org/installer) to
* imagemagick installed and enabled
* nice URLs via rewriting configured and enabled
* farming support via the [farmer plugin](https://www.dokuwiki.org/plugin:farmer)
* docker health check running basic DokuWiki checks (every 30 seconds, 3 retries)

Note: This image does **not** include a mail server. You need to configure DokuWiki to use an external mail server, this
is most easily achieved using the [SMTP plugin](https://www.dokuwiki.org/plugin:smtp).
Expand Down
25 changes: 25 additions & 0 deletions root/var/www/html/health.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

define('DOKU_UNITTEST', 1);
define('DOKU_INC', __DIR__ . '/');

header('Content-Type: text/plain; charset=utf-8');
try {
ob_start();
require DOKU_INC . 'inc/init.php';
ob_end_clean();
# if init didn't fail, DokuWiki should be generally okay
echo 'ok';
} catch (\Exception $e) {
ob_end_clean();
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);

// ensure we have a good status message on failure
$msg = $e->getMessage();
$msg = strip_tags($msg);
$msg = preg_replace('/^nice_die:/', '', $msg);
$msg = preg_replace('/\s+/', ' ', $msg);
$msg = trim($msg);
echo $msg;
}

0 comments on commit 9a12b5c

Please sign in to comment.