docker-phpLDAPadmin icon indicating copy to clipboard operation
docker-phpLDAPadmin copied to clipboard

How to perform a HealthCheck on phpldapadmin?

Open lsampaioweb opened this issue 6 years ago • 3 comments

I'm running openldap and phpldapadmin from a docker-compose file, for the openldap I was able to configure a healthcheck with "test: ldapwhoami -xH ldapi:// || exit 1". Is this the best way?

How can I perform a HealthCheck on phpldapadmin if you guys removed curl and wget?

I would like to run: test: curl --fail -s http://localhost/ || exit 1

lsampaioweb avatar Feb 12 '19 01:02 lsampaioweb

Maybe not ideal, but I've used pgrep:

    healthcheck:
      test: ["CMD-SHELL", "[ $$(pgrep -u www-data -c -f /usr/sbin/apache2) -gt 0 ] || exit 1"]

Doesn't prove the UI is actually available, but at least confirms the Apache httpd process is running (which should be service the PHP, but it could have errored and not shutdown).

ChrisSamo632 avatar Mar 01 '19 12:03 ChrisSamo632

I use this PHP script It connects and checks the ssl fingerprint and exists+echo 0 if the contents where received, else exit+echo 1

        healthcheck:
            test: 'php -r ''$$c = is_string(file_get_contents("https://localhost?ping=pong", false, stream_context_create(["ssl" => ["verify_peer"=> false, "verify_peer_name"=> true, "peer_name"=> "${DOMAIN_NAME}", "peer_fingerprint" => openssl_x509_fingerprint(file_get_contents("/container/service/phpldapadmin/assets/apache2/certs/fullchain.cer")) ]]))); echo $$c; exit($$c === true ? 0 : 1);'''
            interval: 30s
            timeout: 3s
            retries: 3

$ docker inspect phpldapadmin | jq '.[0].State'

{
  "Status": "running",
  "Running": true,
  "Paused": false,
  "Restarting": false,
  "OOMKilled": false,
  "Dead": false,
  "Pid": 470473,
  "ExitCode": 0,
  "Error": "",
  "StartedAt": "2020-12-27T18:15:12.513689311Z",
  "FinishedAt": "0001-01-01T00:00:00Z",
  "Health": {
    "Status": "healthy",
    "FailingStreak": 0,
    "Log": [
      {
        "Start": "2020-12-27T19:33:17.885448755+01:00",
        "End": "2020-12-27T19:33:18.033460367+01:00",
        "ExitCode": 0,
        "Output": "1"
      },
      {
        "Start": "2020-12-27T19:33:48.043926373+01:00",
        "End": "2020-12-27T19:33:48.14391669+01:00",
        "ExitCode": 0,
        "Output": "1"
      },
      {
        "Start": "2020-12-27T19:34:18.154210888+01:00",
        "End": "2020-12-27T19:34:18.311065497+01:00",
        "ExitCode": 0,
        "Output": "1"
      },
      {
        "Start": "2020-12-27T19:34:48.321082568+01:00",
        "End": "2020-12-27T19:34:48.475726883+01:00",
        "ExitCode": 0,
        "Output": "1"
      },
      {
        "Start": "2020-12-27T19:35:18.485696749+01:00",
        "End": "2020-12-27T19:35:18.647521269+01:00",
        "ExitCode": 0,
        "Output": "1"
      }
    ]
  }
}

williamdes avatar Dec 27 '20 18:12 williamdes

Maybe not ideal, but I've used pgrep:

    healthcheck:
      test: ["CMD-SHELL", "[ $$(pgrep -u www-data -c -f /usr/sbin/apache2) -gt 0 ] || exit 1"]

Doesn't prove the UI is actually available, but at least confirms the Apache httpd process is running (which should be service the PHP, but it could have errored and not shutdown).

I have used your command for a long time now in a docker-compose and it worked well. I'm trying to use the same command in docker run and it seems to be impossible. I have no idea what is wrong but the syntax will always complain. I tried like 10 different variants of this command but it won't work. I need docker run for my UNRAID system...

saschabrockel avatar Jun 17 '23 01:06 saschabrockel