diff options
| author | Paul Buetow <paul@buetow.org> | 2022-04-13 21:45:00 +0100 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2022-04-13 21:45:00 +0100 |
| commit | 3ba81b44973475765bb2bc7000d8d5cc9b38ec1a (patch) | |
| tree | b59e6604ced9ef457a245a2cd25495bf8f62f593 | |
| parent | 5fb38230b986bef238c74a670a678e2488bea507 (diff) | |
more on ha.pl and rexification
| -rw-r--r-- | openbsd/frontends/Rexfile | 22 | ||||
| -rw-r--r-- | openbsd/frontends/etc/inetd.conf | 1 | ||||
| -rw-r--r-- | openbsd/frontends/usr/local/bin/ha.pl | 43 |
3 files changed, 62 insertions, 4 deletions
diff --git a/openbsd/frontends/Rexfile b/openbsd/frontends/Rexfile index 0ef0bfa..8f95339 100644 --- a/openbsd/frontends/Rexfile +++ b/openbsd/frontends/Rexfile @@ -1,5 +1,5 @@ use Rex -feature => ['1.4']; - +use File::Slurp; group frontends => 'blowfish.buetow.org', 'twofish.buetow.org'; group dnsmaster => 'blowfish.buetow.org'; @@ -7,6 +7,7 @@ group dnsslaves => 'twofish.buetow.org'; user 'rex'; sudo TRUE; +sudo_password read_file "$ENV{'HOME'}/.ssh/rex_password"; parallelism 5; @@ -16,7 +17,7 @@ task 'id', group => 'frontends', say $output; }; -task 'dump-info', group => 'frontends', +task 'dump_info', group => 'frontends', sub { dump_system_information }; desc 'Get the uptime of all servers'; @@ -29,8 +30,21 @@ task 'uptime', group => 'frontends', desc 'Setup inetd'; task 'inetd', group => 'frontends', sub { - my $output = run 'cat /etc/inetd.conf'; - say $output; + file '/etc/inetd.conf', + source => "./etc/inetd.conf", + on_change => sub { + service 'inetd' => 'restart'; + }; + }; + +desc 'Setup failover'; +task 'failover', group => 'frontends', + sub { + file '/usr/local/bin/ha.pl', + source => "./usr/local/bin/ha.pl", + owner => 'root', + group => 'wheel', + mode => '755'; }; 1; diff --git a/openbsd/frontends/etc/inetd.conf b/openbsd/frontends/etc/inetd.conf index d070ad4..5f88aa3 100644 --- a/openbsd/frontends/etc/inetd.conf +++ b/openbsd/frontends/etc/inetd.conf @@ -1 +1,2 @@ 127.0.0.1:11965 stream tcp nowait www /usr/local/bin/vger vger -v +*:4242 stream tcp nowait www /usr/local/bin/ha.pl ha.pl --inetd 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; |
