App-bwk-mn
view release on metacpan or search on metacpan
lib/App/bwk/mn.pm view on Meta::CPAN
Resync-ing from scratch will take at least 1-2 hours, and if this happens on
each masternode every few days then resync-ing will waste a lot of time. Thus
the ZFS snapshot. Snapshots will of course need to be created regularly for this
setup to benefit.
_
args => {
},
deps => {
all => [
{prog => 'systemctl'},
{prog => 'bulwark-cli'},
{prog => 'zfs'},
],
},
};
sub restore_from_zfs_snapshot {
my %args = @_;
my $res = _newest_bulwark_zfs_snapshots();
return $res unless $res->[0] == 200;
my $newest;
system({log=>1, die=>1}, "systemctl", "stop", "bulwarkd");
system({log=>1, die=>1}, "zfs", "rollback", $res->[2]);
system({log=>1, die=>1}, "systemctl", "start", "bulwarkd");
# TODO: wait until fully sync-ed
[200];
}
$SPEC{new_zfs_snapshot} = {
v => 1.1,
summary => 'Create a new ZFS snapshot',
description => <<'_',
This subcommand will:
1. stop bulwarkd
2. create a new ZFS snapshot
3. restart bulwarkd again
See `restore_from_zfs_snapshot` for more details.
_
args => {
},
deps => {
all => [
{prog => 'systemctl'},
{prog => 'bulwark-cli'},
{prog => 'zfs'},
],
},
};
sub new_zfs_snapshot {
require DateTime;
my %args = @_;
my $res = _newest_bulwark_zfs_snapshots();
return $res unless $res->[0] == 200;
my $snapshots = $res->[3]{'func.all_snapshots'};
my $s = $res->[3]{'func.raw'};
my $today = DateTime->now->ymd;
my $new_snapshot;
my $i = 0;
while (1) {
$new_snapshot = sprintf(
"%s/%s\@%s%s",
$s->{pool}, $s->{fs},
$today,
$i++ ? sprintf("_%03d", $i) : "",
);
last unless $snapshots->{$new_snapshot};
}
system({log=>1, die=>1}, "systemctl", "stop", "bulwarkd");
system({log=>1, die=>1}, "zfs", "snapshot", $new_snapshot);
system({log=>1, die=>1}, "systemctl", "start", "bulwarkd");
# TODO: wait until fully sync-ed
[200];
}
1;
# ABSTRACT: Some commands to manage Bulwark masternode
__END__
=pod
=encoding UTF-8
=head1 NAME
App::bwk::mn - Some commands to manage Bulwark masternode
=head1 VERSION
This document describes version 0.001 of App::bwk::mn (from Perl distribution App-bwk-mn), released on 2019-07-22.
=head1 SYNOPSIS
Please see included script L<bwk-mn>.
=head1 FUNCTIONS
=head2 new_zfs_snapshot
Usage:
new_zfs_snapshot() -> [status, msg, payload, meta]
Create a new ZFS snapshot.
This subcommand will:
=over
=item 1. stop bulwarkd
( run in 0.699 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )