diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-10-09 11:15:13 -0700 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-10-09 11:15:13 -0700 |
commit | 1d3e6b3ea190d14b68b2f9792784037d4f12928b (patch) | |
tree | bc70da3d169c8d5fc46f90d6f2811060cfe36234 /scripts/snmp | |
parent | aa7eb86891fc84bebcd6fb3aaec2918f11b8ea82 (diff) | |
download | vyatta-cfg-quagga-1d3e6b3ea190d14b68b2f9792784037d4f12928b.tar.gz vyatta-cfg-quagga-1d3e6b3ea190d14b68b2f9792784037d4f12928b.zip |
Check if SNMP is running before starting
The SNMPD restart has 2 or 3 seconds of sleep that
is unnecessary if SNMPD isn't running.
Diffstat (limited to 'scripts/snmp')
-rw-r--r-- | scripts/snmp/vyatta-snmp.pl | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/scripts/snmp/vyatta-snmp.pl b/scripts/snmp/vyatta-snmp.pl index e077482c..e977d619 100644 --- a/scripts/snmp/vyatta-snmp.pl +++ b/scripts/snmp/vyatta-snmp.pl @@ -45,8 +45,16 @@ my $local_agent = 'unix:/var/run/snmpd.socket'; my $snmp_level = 'service snmp'; -sub snmp_restart { - system("$snmp_init restart > /dev/null 2>&1 &"); +sub snmp_running { + open (my $pidf, '<', "/var/run/snmpd.pid") + or return; + my $pid = <$pidf>; + close $pidf; + + chomp $pid; + my $exe = readlink "/proc/$pid/exe"; + + return (defined($exe) && $exe eq "/usr/sbin/snmpd"); } sub snmp_stop { @@ -69,7 +77,11 @@ sub snmp_start { move($snmp_tmp, $snmp_conf) or die "Couldn't move $snmp_tmp to $snmp_conf - $!"; - snmp_restart(); + if (snmp_running()) { + system("$snmp_init restart > /dev/null 2>&1 &"); + } else { + system("$snmp_init start > /dev/null 2>&1 &"); + } } sub get_version { |