Skip to content

Commit

Permalink
Add lightweight healtcheck script
Browse files Browse the repository at this point in the history
To be used for e.g. loadbalancer control, just pings the server
  • Loading branch information
oliwel committed Nov 18, 2020
1 parent 672fe9f commit 2e05c16
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/server/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ cgi-bin/soap.fcgi
cgi-bin/download.fcgi
cgi-bin/rpc.fcgi
cgi-bin/est.fcgi
cgi-bin/healthcheck.fcgi

# Client UI
htdocs/img/logo.png
Expand Down
43 changes: 43 additions & 0 deletions core/server/cgi-bin/healthcheck.fcgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/perl

use strict;
use warnings;

use CGI;
use CGI::Fast;
use CGI::Carp qw (fatalsToBrowser);

use English;
use JSON;
use OpenXPKI::Client;
use Log::Log4perl qw(:easy);

Log::Log4perl->easy_init($ERROR);

my $client;
my $json = new JSON();

my $socketfile = $ENV{OPENXPKI_CLIENT_SOCKETFILE} || '/var/openxpki/openxpki.socket';

while (my $cgi = CGI::Fast->new()) {

if (!$client) {
eval{
$client = OpenXPKI::Client->new({
SOCKETFILE => $socketfile,
});
$client->init_session();
};
}

if (!$client || !$client->is_connected()) {
print $cgi->header( -type => 'text/plain', charset => 'utf8', -status => 500 );
print $json->encode({ ping => 0 });
$client = undef;
} else {
print $cgi->header( -type => 'text/plain', charset => 'utf8', -status => 200 );
print $json->encode({ ping => 1 });
}
}

$client->close_connection() if ($client);
1 change: 1 addition & 0 deletions package/debian/core/libopenxpki-perl.install
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ cgi-bin/soap.fcgi usr/lib/cgi-bin
cgi-bin/rpc.fcgi usr/lib/cgi-bin
cgi-bin/est.fcgi usr/lib/cgi-bin
cgi-bin/download.fcgi usr/lib/cgi-bin
cgi-bin/healthcheck.fcgi usr/lib/cgi-bin
htdocs/* var/www/openxpki/

0 comments on commit 2e05c16

Please sign in to comment.