Skip to content

Commit

Permalink
adding log rotation ability ... fix for issue #587 (#598)
Browse files Browse the repository at this point in the history
* adding logrotation ability ... fix for issue #587
  • Loading branch information
oetiker authored Dec 20, 2022
1 parent 710055e commit 78d95e2
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 154 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: Build Docker

on:
push:
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test
name: Run Tests

on:
push:
Expand All @@ -17,19 +17,21 @@ jobs:
- "5.32"
- "5.30"
- "5.26"
- "5.36"
# - "5.22"
# - "5.18"
# - "5.10"
name: Perl ${{ matrix.perl }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup perl
uses: shogo82148/actions-setup-perl@v1
with:
perl-version: ${{ matrix.perl }}
- run: ./bootstrap.sh
- run: ./configure --prefix=$HOME/znapzend
- run: make install
- run: cat cpanfile.test >> cpanfile && make
- run: ./test.sh
- run: make install
- run: "echo \"repo_token: ${{ secrets.GITHUB_TOKEN }}\" > .coveralls.yml"
- run: perl -I./thirdparty/lib/perl5 thirdparty/bin/cover -report coveralls
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- clear log handle on receiving a USR1 signal @oetiker
- removed depencency on ForkCall @fdd-rev
- Fix regex in splitHostDataSet to understand dataset names with colons @jimklimov
- Fix deletion of many snaps for many datasets, and handle several not-"enabled" sub-trees under one schedule @jimklimov
Expand Down
4 changes: 4 additions & 0 deletions bin/znapzend
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use FindBin; use lib "$FindBin::RealBin/../lib", "$FindBin::RealBin/../thirdpart

use Getopt::Long qw(:config posix_default no_ignore_case);
use Pod::Usage;
use Role::Tiny;

use ZnapZend;
my $VERSION = '0.dev'; #VERSION
Expand Down Expand Up @@ -180,6 +181,7 @@ B<znapzend> [I<options>...]
--forbidDestRollback forbids forcing destination dataset rollback and
removal of datasets/snapshots not present on source
--logto=x select where to log (syslog::<facility> or <filepath>)
when logging to a file, send USR1 to re-open the filehandle
--loglevel=x define the log level
--pidfile=x write a pid file when running in daemon mode
--daemonize fork into the background
Expand Down Expand Up @@ -256,6 +258,8 @@ send logs out to either syslog or a logfile. Default is to send logs to
B<syslog::daemon> when running daemonized. When running in debug mode, the
logs will go to STDERR by default.
When logging to a file, send USR1 to repoen the file handle after log rotation.
Examples:
--logto=/var/log/znapzend.log
Expand Down
48 changes: 11 additions & 37 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Author: Tobi Oetiker <[email protected]>
# License: Public Domain

AC_INIT([znapzend],m4_esyscmd([tr -d '\n' < VERSION]),[[email protected]])
AC_PREREQ([2.59])
AC_INIT([znapzend],[m4_esyscmd(tr -d '\n' < VERSION)],[[email protected]])
AC_PREREQ([2.69])
AC_CONFIG_AUX_DIR(conftools)

AC_MSG_CHECKING(in to see how you are doing)
Expand All @@ -28,10 +28,8 @@ AC_PATH_PROG(POD2MAN, pod2man, no)
# TODO: with some respect to legacy, split such settings to be named
# after respective service management framework; code supports several
AC_ARG_ENABLE(svcinstall,
AC_HELP_STRING(
[--enable-svcinstall=DIR],
[install svc manifest into given directory]
),
AS_HELP_STRING([--enable-svcinstall=DIR],[install svc manifest into given directory
]),
[SVCINSTALLDIR=$enableval],
[SVCINSTALLDIR=no]
)
Expand All @@ -40,10 +38,8 @@ AM_CONDITIONAL(ENABLE_SVCINSTALL,[test $SVCINSTALLDIR != no])

SVCNAME_SMF="oep/znapzend"
AC_ARG_WITH(svcname-smf,
AC_HELP_STRING(
[--with-svcname-smf=SMF_FMRI],
[use specified SMF FMRI in manifest (defaults to oep/znapzend)]
),
AS_HELP_STRING([--with-svcname-smf=SMF_FMRI],[use specified SMF FMRI in manifest (defaults to oep/znapzend)
]),
[AC_MSG_CHECKING([user-provided SMF service name of '$withval'])
SVCNAME_SMF="`echo "$withval" | sed -e 's,^svc:,,' -e 's,^/*,,' -e 's,:.*$,,'`"
],[AC_MSG_CHECKING([default SMF service name])]
Expand All @@ -57,10 +53,8 @@ DEFAULT_URL_CAT_CURL="$CURL --location --insecure"
DEFAULT_URL_CAT_WGET="$WGET -O -"

AC_ARG_WITH(url-cat,
AC_HELP_STRING(
[--with-url-cat=(curl|wget)],
[use specified program (with further predefined arguments added as needed) to cat URLs]
),
AS_HELP_STRING([--with-url-cat=(curl|wget)],[use specified program (with further predefined arguments added as needed) to cat URLs
]),
[AS_CASE("$withval",
[curl],[AS_IF([test -n "$CURL" && test -x "$CURL"],
[URL_CAT="$DEFAULT_URL_CAT_CURL"],
Expand All @@ -70,10 +64,8 @@ AC_ARG_WITH(url-cat,
[AC_MSG_ERROR([Asked to preconfigure use of $withval but one is not in PATH])])],
[*],[AC_MSG_ERROR([Asked to preconfigure use of $withval which is not an URL cat-er we support])])],
[AC_ARG_WITH(url-cat-program,
AC_HELP_STRING(
[--with-url-cat-program=(/path/name --args)],
[use specified custom program with arguments to cat URLs]
),
AS_HELP_STRING([--with-url-cat-program=(/path/name --args)],[use specified custom program with arguments to cat URLs
]),
[URL_CAT="$withval"],
[
AS_IF([test -x "$WGET"],[URL_CAT="$DEFAULT_URL_CAT_WGET"],
Expand All @@ -98,22 +90,6 @@ if test "x$PERL" != "x"; then
if test $? -ne 0; then
AC_MSG_RESULT(no);
AC_MSG_WARN(at least version $ac_perl_version is required to run modern mojolicious)

# re-check for older distributions minimal support
ac_perl_version="5.10.1"

AC_MSG_CHECKING(for perl version greater than or equal to $ac_perl_version)
$PERL -e "use $ac_perl_version;" >/dev/null 2>&1
if test $? -ne 0; then
AC_MSG_RESULT(no);
AC_MSG_ERROR(at least version $ac_perl_version is required to run mojolicious at all)
exit 1
else
MOJOLICIOUS_VERSION_CONSTRAINT=", '< 8.44'"
fi
else
AC_MSG_RESULT(ok);
MOJOLICIOUS_VERSION_CONSTRAINT=", '>= 8.73'"
fi
else
AC_MSG_ERROR(could not find perl)
Expand Down Expand Up @@ -160,8 +136,7 @@ else
fi

AC_ARG_ENABLE(pkgonly,
AC_HELP_STRING([--enable-pkgonly],
[Skip all checking]))
AS_HELP_STRING([--enable-pkgonly],[Skip all checking]))
AC_SUBST(enable_pkgonly)

# TODO: Is this block needed? No code seems to refer this varname...
Expand Down Expand Up @@ -235,7 +210,6 @@ AC_DEFINE_UNQUOTED(LIBDIR, "${conftemp}", [Default path for system libraries])
AC_SUBST(LIBDIR)

AC_CONFIG_FILES([
cpanfile
Makefile
thirdparty/Makefile
lib/Makefile
Expand Down
6 changes: 2 additions & 4 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
requires 'Mojolicious' , '>= 8.73, <9.0';
requires 'Mojolicious';
requires 'Scalar::Util', '>= 1.45';
requires 'Test::SharedFork';
requires 'Test::Exception';
requires 'Test::More';
requires 'Mojo::Log::Role::Clearable';
5 changes: 0 additions & 5 deletions cpanfile.in

This file was deleted.

6 changes: 6 additions & 0 deletions cpanfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
requires 'Test::SharedFork';
requires 'Test::Exception';
requires 'Test::More';
requires 'Devel::Cover';
requires "Devel::Cover::Report::Coveralls";
requires "Pod::Coverage";
9 changes: 6 additions & 3 deletions lib/ZnapZend.pm
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ has zLog => sub {
: $self->logto,
level => $level
);

$syslog && do {
if ($syslog) {
$log->unsubscribe('message');
#add syslog handler if either syslog is explicitly specified or no logfile is given
openlog(basename($0), 'cons,pid', $syslog);
Expand All @@ -111,7 +110,11 @@ has zLog => sub {
syslog($logLevels{$level}, @lines) if $log->is_level($level);
}
);
};
}
else {
$log->with_roles('+Clearable');
$SIG{USR1} = sub { $log->clear_handle };
}

return $log;
};
Expand Down
5 changes: 4 additions & 1 deletion man/znapzend.1
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "ZNAPZEND 1"
.TH ZNAPZEND 1 "2021-06-29" "0.21.1" "znapzend"
.TH ZNAPZEND 1 "2022-12-19" "0.21.1" "znapzend"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
Expand All @@ -155,6 +155,7 @@ znapzend \- znapzend daemon
\& \-\-forbidDestRollback forbids forcing destination dataset rollback and
\& removal of datasets/snapshots not present on source
\& \-\-logto=x select where to log (syslog::<facility> or <filepath>)
\& when logging to a file, send USR1 to re\-open the filehandle
\& \-\-loglevel=x define the log level
\& \-\-pidfile=x write a pid file when running in daemon mode
\& \-\-daemonize fork into the background
Expand Down Expand Up @@ -223,6 +224,8 @@ send logs out to either syslog or a logfile. Default is to send logs to
\&\fBsyslog::daemon\fR when running daemonized. When running in debug mode, the
logs will go to \s-1STDERR\s0 by default.
.Sp
When logging to a file, send \s-1USR1\s0 to repoen the file handle after log rotation.
.Sp
Examples:
.Sp
.Vb 2
Expand Down
10 changes: 5 additions & 5 deletions t/znapzend-daemonize.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ use strict;
use warnings;

use FindBin;
$ENV{PATH} = "$FindBin::Bin:$ENV{PATH}";
$ENV{PATH} = $FindBin::RealBin.':'.$ENV{PATH};
my $buildDir;

BEGIN {
$buildDir = shift @ARGV // "$FindBin::Bin/../";
$buildDir = shift @ARGV // $FindBin::Bin."/../";
}

# Track child PIDs spawned by test
our @test_arr_children = ();
sub test_arr_children { \@test_arr_children };

# PERL5LIB
use lib "$FindBin::Bin/../lib";
use lib "$FindBin::RealBin/../lib";
use lib "$buildDir/thirdparty/lib/perl5";
#place bin path to lib so it is stored in @INC
use lib "$FindBin::Bin/../bin";
use lib "$FindBin::RealBin/../bin";

unshift @INC, sub {
my (undef, $filename) = @_;
Expand Down Expand Up @@ -95,7 +95,7 @@ use_ok 'ZnapZend';

#load program
@ARGV = qw(--help);
do 'znapzend' or die "ERROR: loading program znapzend\n";
do 'znapzend' or die "ERROR: loading program znapzend $@\n";

# For tests below we run the real forking and daemonization and test how it
# behaves. Thanks to Test::SharedFork above these are counted correctly -
Expand Down
6 changes: 3 additions & 3 deletions t/znapzend.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use strict;
use warnings;

use FindBin;
$ENV{PATH} = "$FindBin::Bin:$ENV{PATH}";
$ENV{PATH} = $FindBin::RealBin . ':' . $ENV{PATH};
my $buildDir;

BEGIN {
$buildDir = shift @ARGV // "$FindBin::Bin/../";
$buildDir = shift @ARGV // $FindBin::RealBin.'/../';
}

# PERL5LIB
Expand Down Expand Up @@ -86,7 +86,7 @@ use_ok 'ZnapZend';

#load program
@ARGV = qw(--help);
do 'znapzend' or die "ERROR: loading program znapzend\n";
do 'znapzend' or die "ERROR: loading program znapzend $@\n";

# seems to allow tests to continue so why not?
is (runCommand('--help'), 1, 'znapzend help');
Expand Down
6 changes: 3 additions & 3 deletions t/znapzendzetup.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use strict;
use warnings;

use FindBin;
$ENV{PATH} = "$FindBin::Bin:$ENV{PATH}";
$ENV{PATH} = $FindBin::RealBin.':'.$ENV{PATH};
my $buildDir;

BEGIN {
$buildDir = shift @ARGV // "$FindBin::Bin/../";
$buildDir = shift @ARGV // $FindBin::RealBin."/../";
}

# PERL5LIB
Expand Down Expand Up @@ -80,7 +80,7 @@ use_ok 'ZnapZend';

#load program
@ARGV = qw(help);
do 'znapzendzetup' or die "ERROR: loading program znapzendzetup\n";
do 'znapzendzetup' or die "ERROR: loading program znapzendzetup $@\n";

is (runCommand('help'), 1, 'znapzendzetup help');

Expand Down
10 changes: 5 additions & 5 deletions t/znapzendztatz.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ use strict;
use warnings;

use FindBin;
$ENV{PATH} = "$FindBin::Bin:$ENV{PATH}";
$ENV{PATH} = $FindBin::RealBin.':'.$ENV{PATH};
my $buildDir;

BEGIN {
$buildDir = shift @ARGV // "$FindBin::Bin/../";
$buildDir = shift @ARGV // $FindBin::RealBin."/../";
}

# PERL5LIB
use lib "$FindBin::Bin/../lib";
use lib "$FindBin::RealBin/../lib";
use lib "$buildDir/thirdparty/lib/perl5";
#place bin path to lib so it is stored in @INC
use lib "$FindBin::Bin/../bin";
use lib "$FindBin::RealBin/../bin";

unshift @INC, sub {
my (undef, $filename) = @_;
Expand Down Expand Up @@ -76,7 +76,7 @@ use_ok 'ZnapZend';

#load program
@ARGV = qw(--help);
do 'znapzendztatz' or die "ERROR: loading program znapzendztatz\n";
do 'znapzendztatz' or die "ERROR: loading program znapzendztatz $@\n";

is (runCommand('--help'), 1, 'znapzendztatz help');

Expand Down
17 changes: 7 additions & 10 deletions test.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
#!/bin/bash

PERL_CPANM_HOME="`pwd`/thirdparty" \
PERL_CPANM_OPT='--notest --local-lib '"`pwd`/thirdparty" \
perl ./thirdparty/bin/cpanm Devel::Cover::Report::Coveralls
#!/bin/sh

# Fail on a test line that dies so we can notice it
set -e

perl -I./thirdparty/lib/perl5 \
-MDevel::Cover=+ignore,thirdparty ./t/znapzend.t ./bin/znapzend || test $? == 1
-MDevel::Cover=+ignore,thirdparty ./t/znapzend.t
perl -I./thirdparty/lib/perl5 \
-MDevel::Cover=+ignore,thirdparty ./t/znapzend-daemonize.t ./bin/znapzend || test $? == 1
-MDevel::Cover=+ignore,thirdparty ./t/znapzend-daemonize.t
perl -I./thirdparty/lib/perl5 \
-MDevel::Cover=+ignore,thirdparty ./t/znapzendzetup.t ./bin/znapzend || test $? == 1
-MDevel::Cover=+ignore,thirdparty ./t/znapzendzetup.t
perl -I./thirdparty/lib/perl5 \
-MDevel::Cover=+ignore,thirdparty ./t/znapzendztatz.t ./bin/znapzend || test $? == 1
-MDevel::Cover=+ignore,thirdparty ./t/znapzendztatz.t
perl -I./thirdparty/lib/perl5 \
-MDevel::Cover=+ignore,thirdparty ./t/autoscrub.t ./bin/znapzend || test $? == 1
-MDevel::Cover=+ignore,thirdparty ./t/autoscrub.t

Loading

1 comment on commit 78d95e2

@github-actions
Copy link

@github-actions github-actions bot commented on 78d95e2 Dec 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

Unrecognized words, please review:

  • a'u
  • Aqs
  • atime
  • bashrc
  • canmount
  • chroot
  • cmds
  • coprs
  • crlf
  • dedup
  • dirs
  • DTDs
  • ecdsa
  • eol
  • failsafes
  • flaged
  • HAARG
  • homedir
  • howtogeek
  • I'u
  • ico
  • incrementals
  • jenkins
  • keygen
  • logbias
  • Makefiles
  • png
  • primarycache
  • Proxmox
  • rbash
  • READNE
  • refquota
  • refreservation
  • remotehost
  • repoen
  • rsa
  • rsync
  • secondarycache
  • snaptime
  • stringify
  • useradd
  • usermod
  • Zends
  • znapdest
Previously acknowledged words that are now absent aix CBuilder Cwd cygwin ev Fcntl fh forkcall gh gz Ip JB JBERGER LEONT Mkbootstrap nf nh oi Pipely qq qw RCAPUTO rr rw SZ ve VOS wu wx xargs xf yy ZL
Some files were were automatically ignored

These sample patterns would exclude them:

^AUTHORS$

You should consider adding them to:

.github/workflows//spelling/excludes.txt

File matching is via Perl regular expressions.

To check these files, more of their words need to be in the dictionary than not. You can use patterns.txt to exclude portions, add items to the dictionary (e.g. by adding them to allow.txt), or fix typos.

To accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the [email protected]:oetiker/znapzend.git repository
on the master branch:

update_files() {
perl -e '
my @expect_files=qw('".github/workflows//spelling/whitelist.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/workflows//spelling/whitelist.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
(cat '.github/workflows//spelling/excludes.txt' - <<EOF
$should_exclude_patterns
EOF
) |grep .|
sort -f |
uniq > '.github/workflows//spelling/excludes.txt.temp' &&
mv '.github/workflows//spelling/excludes.txt.temp' '.github/workflows//spelling/excludes.txt'
}

comment_json=$(mktemp)
curl -L -s -S \
  --header "Content-Type: application/json" \
  "https://api.github.com/repos/oetiker/znapzend/comments/93652714" > "$comment_json"
comment_body=$(mktemp)
jq -r .body < "$comment_json" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")
  

patch_add=$(perl -e '$/=undef;
$_=<>;
s{<details>.*}{}s;
s{^#.*}{};
s{\n##.*}{};
s{(?:^|\n)\s*\*}{}g;
s{\s+}{ }g;
print' < "$comment_body")
  

should_exclude_patterns=$(perl -e '$/=undef;
$_=<>;
exit unless s{(?:You should consider excluding directory paths|You should consider adding them to).*}{}s;
s{.*These sample patterns would exclude them:}{}s;
s{.*\`\`\`([^`]*)\`\`\`.*}{$1}m;
print' < "$comment_body" | grep . || true)

update_files
rm $comment_body
git add -u

Please sign in to comment.