1
0
Fork 0

More adjustmemts

This commit is contained in:
Joao M 2022-08-24 02:33:21 +00:00
parent 7d959f892a
commit 877a4b3383
7 changed files with 69 additions and 36 deletions

View file

@ -3,6 +3,7 @@ from processor import ProcessorInterface
import os
import time
from threading import Thread
from deepdiff import DeepDiff
easyhaproxy_config = "/etc/haproxy/easyconfig.yml"
haproxy_config = "/etc/haproxy/haproxy.cfg"
@ -17,9 +18,9 @@ def start():
os.makedirs(certs_letsencrypt, exist_ok=True)
os.makedirs(certs_haproxy, exist_ok=True)
Functions.save(haproxy_config, processor_obj.get_haproxy_conf())
for cert in processor_obj.get_certs():
Functions.save(certs_haproxy, processor_obj.get_certs(cert))
processor_obj.save_config(haproxy_config)
processor_obj.save_certs(certs_haproxy)
Functions.log('EASYHAPROXY', 'info', 'Found hosts: %s' % ", ".join(processor_obj.get_hosts())) # Needs to after save_config
#configs = Functions.run_bash('HAPROXY', 'ls /etc/haproxy/conf.d/*.cfg', log_output=False)
x = Thread(target=Functions.run_bash, args=("HAPROXY", "/usr/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -S /var/run/haproxy.sock", True, False))
@ -27,6 +28,22 @@ def start():
while True:
time.sleep(10)
try:
old_parsed = processor_obj.get_parsed_object()
processor_obj.refresh()
if DeepDiff(old_parsed, processor_obj.get_parsed_object()) != {} or not x.is_alive():
Functions.log('EASYHAPROXY', 'info', 'New configuration found. Reloading...')
processor_obj.save_config(haproxy_config)
processor_obj.save_certs(certs_haproxy)
Functions.log('EASYHAPROXY', 'info', 'Found hosts: %s' % ", ".join(processor_obj.get_hosts())) # Needs to after save_config
pid = "".join(Functions().run_bash("HAPROXY", "cat /run/haproxy.pid", log_output=False))
x = Thread(target=Functions.run_bash, args=("HAPROXY", "/usr/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -x /var/run/haproxy.sock -sf %s" % (pid), True, False))
x.start()
except Exception as e:
Functions.log('EASYHAPROXY', 'error', "Err: %s" % (e))
Functions.log('EASYHAPROXY', 'info', 'Heartbeat')
def main():
@ -38,12 +55,13 @@ def main():
Functions.log('INIT', 'info', "\___\__,_/__/\_, | |_||_\__,_| .__/_| \___/_\_\\_, |")
Functions.log('INIT', 'info', " |__/ |_| |__/ ")
Functions.log('INIT', 'INFO', os.getenv("RELEASE_VERSION"))
Functions.log('INIT', 'INFO', "")
Functions.log('INIT', 'INFO', 'Environment:')
Functions.log('INIT', 'info', "Release: %s" % (os.getenv("RELEASE_VERSION")))
Functions.log('INIT', 'info', 'Environment:')
for name, value in os.environ.items():
if "HAPROXY" in name:
print("- {0}: {1}".format(name, value))
Functions.log('INIT', 'info', "- {0}: {1}".format(name, value))
start()
if __name__ == '__main__':
main()