From c43bdff1a916b090505ac400240ed0cc485884d2 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Mon, 21 Mar 2016 10:16:28 +0100 Subject: [PATCH] Use flock to make sure only one gluster command run at a time --- zabbix_scripts/check_gluster_sudo | 6 ++++++ zabbix_scripts/disco_gluster_sudo | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/zabbix_scripts/check_gluster_sudo b/zabbix_scripts/check_gluster_sudo index dd006f5..c123121 100644 --- a/zabbix_scripts/check_gluster_sudo +++ b/zabbix_scripts/check_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); diff --git a/zabbix_scripts/disco_gluster_sudo b/zabbix_scripts/disco_gluster_sudo index 73c3ee0..b07d91e 100644 --- a/zabbix_scripts/disco_gluster_sudo +++ b/zabbix_scripts/disco_gluster_sudo @@ -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);