From 3ba81b44973475765bb2bc7000d8d5cc9b38ec1a Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 13 Apr 2022 21:45:00 +0100 Subject: more on ha.pl and rexification --- openbsd/frontends/usr/local/bin/ha.pl | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 openbsd/frontends/usr/local/bin/ha.pl (limited to 'openbsd/frontends/usr') diff --git a/openbsd/frontends/usr/local/bin/ha.pl b/openbsd/frontends/usr/local/bin/ha.pl new file mode 100644 index 0000000..d227a86 --- /dev/null +++ b/openbsd/frontends/usr/local/bin/ha.pl @@ -0,0 +1,43 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Sys::Hostname; +use Getopt::Long; + +use constant STATUS_FILE => '/var/run/failover.status'; +use constant PARTNERS => qw(blowfish.buetow.org twofish.buetow.org); + +sub slurp { + my $file_path = shift; + open my $fd, $file_path or die $!; + my $data = <$fd>; + close $fd; + return $data; +} + +sub score { + for (PARTNERS) { + next if $_ eq hostname; # Ignore self + print "Trying $_\n"; + } +} + +sub inetd_response { + my $hostname = hostname; + print "OK: All is fine on $hostname itself!\n"; + print slurp STATUS_FILE if -f STATUS_FILE; +} + +sub main { + my ($inetd, $score) = (0, 0); + GetOptions('inetd' => \$inetd, + 'score' => \$score) + or die "Error in command line arguments!\n"; + + score if $score; + inetd_response if $inetd; +} + +main; -- cgit v1.2.3