Skip to content

Commit

Permalink
make script timeout configureable
Browse files Browse the repository at this point in the history
  • Loading branch information
phreaker0 committed Oct 16, 2018
1 parent a7b7fe8 commit a8d5c56
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
16 changes: 9 additions & 7 deletions sanoid
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,10 @@ sub prune_snapshots {
my $dataset = (split '@', $snap)[0];
my $snapname = (split '@', $snap)[1];
if ($config{$dataset}{'pruning_script'}) {
my $timeout = 5;
$ENV{'SANOID_TARGET'} = $dataset;
$ENV{'SANOID_SNAPNAME'} = $snapname;
if ($args{'verbose'}) { print "executing pruning_script '".$config{$dataset}{'pruning_script'}."' on dataset '$dataset'\n"; }
my $ret = runscript('pruning_script',$dataset,$timeout);
my $ret = runscript('pruning_script',$dataset);

delete $ENV{'SANOID_TARGET'};
delete $ENV{'SANOID_SNAPNAME'};
Expand Down Expand Up @@ -475,7 +474,7 @@ sub take_snapshots {
$ENV{'SANOID_TARGET'} = $dataset;
$ENV{'SANOID_SNAPNAME'} = $snapname;
if ($args{'verbose'}) { print "executing pre_snapshot_script '".$config{$dataset}{'pre_snapshot_script'}."' on dataset '$dataset'\n"; }
my $ret = runscript('pre_snapshot_script',$dataset,$timeout);
my $ret = runscript('pre_snapshot_script',$dataset);

delete $ENV{'SANOID_TARGET'};
delete $ENV{'SANOID_SNAPNAME'};
Expand All @@ -498,7 +497,7 @@ sub take_snapshots {
$ENV{'SANOID_TARGET'} = $dataset;
$ENV{'SANOID_SNAPNAME'} = $snapname;
if ($args{'verbose'}) { print "executing post_snapshot_script '".$config{$dataset}{'post_snapshot_script'}."' on dataset '$dataset'\n"; }
runscript('post_snapshot_script',$dataset,$timeout);
runscript('post_snapshot_script',$dataset);

delete $ENV{'SANOID_TARGET'};
delete $ENV{'SANOID_SNAPNAME'};
Expand Down Expand Up @@ -1358,12 +1357,15 @@ sub removecachedsnapshots {
sub runscript {
my $key=shift;
my $dataset=shift;
my $timeout=shift;
my $timeout=$config{$dataset}{'script_timeout'};
my $ret;
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm $timeout;
if ($timeout gt 0) {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm $timeout;
}
$ret = system($config{$dataset}{$key});
alarm 0;
};
Expand Down
6 changes: 4 additions & 2 deletions sanoid.conf
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@
### run script after snapshot
### dataset name will be supplied as an environment variable $SANOID_TARGET
post_snapshot_script = /path/to/script.sh
### dataset name will be supplied as an environment variable $SANOID_TARGET
pruning_script = /path/to/script.sh
### don't take an inconsistent snapshot
#no_inconsistent_snapshot = yes
### run post_snapshot_script when pre_snapshot_script is failing
#force_post_snapshot_script = yes
### dataset name will be supplied as an environment variable $SANOID_TARGET
pruning_script = /path/to/script.sh
### limit allowed execution time of scripts before continuing (<= 0 -> infinite)
script_timeout = 5

[template_ignore]
autoprune = no
Expand Down
3 changes: 2 additions & 1 deletion sanoid.defaults.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ use_template =
process_children_only =
pre_snapshot_script =
post_snapshot_script =
pruning_script =
script_timeout = 5
no_inconsistent_snapshot =
force_post_snapshot_script =
pruning_script =

# If any snapshot type is set to 0, we will not take snapshots for it - and will immediately
# prune any of those type snapshots already present.
Expand Down

0 comments on commit a8d5c56

Please sign in to comment.