Use flock to make sure only one gluster command run at a time

tags/zabbix-agent-addons-0.2.20-1 0.2.8_el5
Daniel Berteaud 9 years ago
parent 4b73b1f8df
commit c43bdff1a9
  1. 6
      zabbix_scripts/check_gluster_sudo
  2. 6
      zabbix_scripts/disco_gluster_sudo

@ -10,12 +10,16 @@ my $peer = undef;
my $bricks = undef;
my $gluster = which('gluster');
my $lock = '/var/lock/gluster-zabbix.lock';
unless($gluster){
# Gluster is not installed, exit with an error
die "gluster command not found";
}
# Get an exclusive lock
open(LOCK, ">$lock") || die "Can't open $lock";
flock(LOCK, 2);
GetOptions(
"what=s" => \$what,
@ -150,3 +154,5 @@ elsif ($what eq 'peer'){
print $status;
}
close(LOCK);
exit(0);

@ -9,6 +9,7 @@ my $json;
@{$json->{data}} = ();
my $gluster = which('gluster');
my $lock = '/var/lock/gluster-zabbix.lock';
unless($gluster){
# Gluster is not installed, just return an empty JSON object
@ -16,6 +17,10 @@ unless($gluster){
exit(0);
}
# Get an exclusive lock
open(LOCK, ">$lock") || die "Can't open $lock";
flock(LOCK, 2);
my $what = 'volumes';
GetOptions(
"what=s" => \$what,
@ -110,6 +115,7 @@ else{
exit(1);
}
close(LOCK);
print to_json($json);
exit(0);

Loading…
Cancel
Save