osixia / docker-phpLDAPadmin

phpLDAPadmin container image 🐳🌴
MIT License
842 stars 196 forks source link

How to perform a HealthCheck on phpldapadmin? #57

Open lsampaioweb opened 5 years ago

lsampaioweb commented 5 years ago

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

ChrisSamo632 commented 5 years ago

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).

williamdes commented 3 years ago

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"
      }
    ]
  }
}
saschabrockel commented 1 year ago

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...