summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2018-09-01 21:18:32 +0200
committerChristian Poessinger <christian@poessinger.com>2018-09-01 21:18:34 +0200
commit6b7c267de3272bff74fa1321f81559d24a85f13f (patch)
tree51bea9a72764a5072f7db4b2b0a5deee54316809 /src
parentd48e5d8d196365862feae6943e97cbc803469cbb (diff)
downloadvyos-1x-6b7c267de3272bff74fa1321f81559d24a85f13f.tar.gz
vyos-1x-6b7c267de3272bff74fa1321f81559d24a85f13f.zip
snmp.py: improve daemon startup
The previous implementation used a hardcoded 2 seconds sleep until the daemon configuration was rendered by snmpd (user/password stuff). Waiting 2 seconds is error prone and was replaced by reading the configuration file until it shows a marker indicating that the file was properly processed by snmpd.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/snmp.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/conf_mode/snmp.py b/src/conf_mode/snmp.py
index a4e776d49..3eb2935be 100755
--- a/src/conf_mode/snmp.py
+++ b/src/conf_mode/snmp.py
@@ -21,7 +21,6 @@ import os
import shutil
import stat
import pwd
-import time
import jinja2
import random
@@ -771,9 +770,17 @@ def apply(snmp):
# start SNMP daemon
os.system("sudo systemctl restart snmpd.service")
- # the passwords are not available immediately so this is a workaround
- # and should be changed to polling
- time.sleep(2)
+ # Passwords are not available immediately in the configuration file,
+ # after daemon startup - we wait until they have been processed by
+ # snmpd, which we see when a magic line appears in this file.
+ snmpReady = False
+ while not snmpReady:
+ with open(config_file_user, 'r') as f:
+ for line in f:
+ # Search for our magic string inside the file
+ if '**** DO NOT EDIT THIS FILE ****' in line:
+ snmpReady = True
+ break
# Back in the Perl days the configuration was re-read and any
# plaintext password inside the configuration was replaced by