This provides a _ping.php file which can be used in load balancers to check if the instance is ok
MIT License
This script can be used for Drupal8 and Drupal9 health-checks.
composer.json
:{
"extra": {
"dropin-paths": {
"web/": [
"type:web-dropin",
"package:wunderio/drupal-ping:_ping.php"
]
}
}
}
composer require wunderio/drupal-ping:^2
_ping.php
into the main project's .gitignore
.See Releases.
/_ping.php
to get a system status?debug=token
additional status check table and time profiling information is displayed
token
valueUser #1 record is fetched from the database.
Assumes $settings['memcache']['servers']
presence in the settings.php
.
Following statuses are issued:
disabled
- No memcached servers defined in settingssuccess
- All connections succeedwarning
- At least one connection succeeds, at least one connection failserror
- All connections failBasic networking is used, no Memcached
or Memcache
class.
By using Redis
class, connection is established to the server.
In settings.php
following has to be defined:
$settings['redis.connection']['host']
$settings['redis.connection']['port']
This test works on both TCP and Unix Sockets.
For the latter only host
has to be defined as path.
In settings.php
following has to be defined:
$settings['ping_elasticsearch_connections'] = [
[
'host' => 'hostname',
'port' => 1234,
'proto' => 'http', // http or https
'severity' => 'warning', // warning or error
],
];
Elasticsearch check requires separate setting, because there are too many ways
how Elasticsearch config can be defined in the settings.php
file, depending
on many factors.
The connection is establised by PHP curl
, and then /_cluster/health
is
being visited. The check expects to get green
status in the response.
Following statuses are issued:
disabled
- No Elasticsearch servers defined in settingssuccess
- All connections succeedwarning
- At least one connection failed, and all failed connections have been configured with 'severity' = 'warning'error
- At least one connection failed, and at least one of the failed connections have been configured with 'severity' = 'error'Consists of 3 tests:
If a site needs any custom checks, then just create _ping.custom.php
.
Use of $status->setName()
and $status->set()
to define the result.
The PHP file does not need to contain functions, just plain PHP is enough.
Check it out how other checks are created in the _ping.php
.
_ping.php
can be accessed over the web.
For example https://example.com/_ping.php
.
It can also be accessed from the shell cd /path/web ; php _ping.php
.
From the shell output the debug token can be attained.
Then visit the ping again with https://example.com/_ping.php?debug=token
.
The token is generated in one of the following ways. These methods are listed by precedance. If earlier fails (is empty), then next one is tried.
$settings['ping_token']
PING_TOKEN
/^(DB|ENVIRONMENT_NAME|GIT|PHP|PROJECT_NAME|S+MTP|VARNISH|WARDEN)/
- NB! This method assumes environment variable consistency between webserver and shell.$settings['hash_salt']
git clone [email protected]:wunderio/drupal-project.git ~/projects/drupal-ping
drupal-ping
.cd drupal-ping/
git clone [email protected]:wunderio/drupal-ping.git
drupal-ping
too, inside the folder of the same name. It is the actual repo we are going to work with..lando.yml
rm -f .lando.yml
- at the top-level folder, remove the Lando conf file.ln drupal-ping/.lando.yml
- link the Lando conf from the ping repo folder. Don't create this as a soft (-s
) link because Lando would mount the project where the original file is. Therefore create the hard link which is indistinguishable for Lando..lando/
rm -rf .lando
- at the top-level folder, remove the Lando folder.ln -s drupal-ping/.lando
- link the Lando scripts folder from the ping repo folder.lando start
settings.php
a bit, don't commit.lando scan
lando test
lando test
- Execute phpunit testslando scan
- Run coding standard checksMIT