Use flock to make sure only one gluster command run at a time
This commit is contained in:
parent
4b73b1f8df
commit
c43bdff1a9
|
@ -10,12 +10,16 @@ my $peer = undef;
|
||||||
my $bricks = undef;
|
my $bricks = undef;
|
||||||
|
|
||||||
my $gluster = which('gluster');
|
my $gluster = which('gluster');
|
||||||
|
my $lock = '/var/lock/gluster-zabbix.lock';
|
||||||
|
|
||||||
unless($gluster){
|
unless($gluster){
|
||||||
# Gluster is not installed, exit with an error
|
# Gluster is not installed, exit with an error
|
||||||
die "gluster command not found";
|
die "gluster command not found";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Get an exclusive lock
|
||||||
|
open(LOCK, ">$lock") || die "Can't open $lock";
|
||||||
|
flock(LOCK, 2);
|
||||||
|
|
||||||
GetOptions(
|
GetOptions(
|
||||||
"what=s" => \$what,
|
"what=s" => \$what,
|
||||||
|
@ -150,3 +154,5 @@ elsif ($what eq 'peer'){
|
||||||
print $status;
|
print $status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(LOCK);
|
||||||
|
exit(0);
|
||||||
|
|
|
@ -9,6 +9,7 @@ my $json;
|
||||||
@{$json->{data}} = ();
|
@{$json->{data}} = ();
|
||||||
|
|
||||||
my $gluster = which('gluster');
|
my $gluster = which('gluster');
|
||||||
|
my $lock = '/var/lock/gluster-zabbix.lock';
|
||||||
|
|
||||||
unless($gluster){
|
unless($gluster){
|
||||||
# Gluster is not installed, just return an empty JSON object
|
# Gluster is not installed, just return an empty JSON object
|
||||||
|
@ -16,6 +17,10 @@ unless($gluster){
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Get an exclusive lock
|
||||||
|
open(LOCK, ">$lock") || die "Can't open $lock";
|
||||||
|
flock(LOCK, 2);
|
||||||
|
|
||||||
my $what = 'volumes';
|
my $what = 'volumes';
|
||||||
GetOptions(
|
GetOptions(
|
||||||
"what=s" => \$what,
|
"what=s" => \$what,
|
||||||
|
@ -110,6 +115,7 @@ else{
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(LOCK);
|
||||||
print to_json($json);
|
print to_json($json);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue