def reload(): # reload applications applications = get_applications() for container in lxc.get_containers(): try: ipaddr = socket.gethostbyname(container) (proj, appl, id) = container.split('_') applications[proj + '_' + appl]['containers'].append({'id': container, 'ipaddr': ipaddr}) print ('added container ' + container + '('+ipaddr+') to ' + proj) except Exception as exc: print (exc) import jinja2 templateLoader = jinja2.FileSystemLoader( searchpath="/" ) templateEnv = jinja2.Environment( loader=templateLoader ) from jinja2 import Template template = templateEnv.get_template(os.path.join(datadir, 'haproxy/haproxy.cfg.jinja2')) with open("/etc/haproxy/haproxy.cfg", "wb") as fh: fh.write (template.render(applications=applications, config=config)) #print (template.render(applications=applications)) template = templateEnv.get_template(os.path.join(datadir, 'haproxy/haproxy.global.cfg.jinja2')) with open("/etc/haproxy/haproxy.global.cfg", "wb") as fh: fh.write (template.render(applications=applications, config=config)) import shlex, subprocess try: pid = int(open('/var/run/haproxy.pid', 'r').read()) os.kill(pid, 0) args = shlex.split('/bin/bash -c "haproxy -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -D -sf $(</var/run/haproxy.pid)"') except (IOError, OSError) as e: args = shlex.split('/bin/bash -c "haproxy -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -D"') finally: p = subprocess.Popen(args) try: pid = int(open('/var/run/haproxy.global.pid', 'r').read()) os.kill(pid, 0) args = shlex.split('/bin/bash -c "haproxy -f /etc/haproxy/haproxy.global.cfg -p /var/run/haproxy.global.pid -D -sf $(</var/run/haproxy.global.pid)"') except (IOError, OSError) as e: args = shlex.split('/bin/bash -c "haproxy -f /etc/haproxy/haproxy.global.cfg -p /var/run/haproxy.global.pid -D"') finally: p = subprocess.Popen(args)
def get_containers(self): return (lxc.get_containers())
def get_containers(self): return (lxc.get_containers())
def reload(): # reload applications applications = get_applications() for container in lxc.get_containers(): try: ipaddr = socket.gethostbyname(container) (proj, appl, id) = container.split('_') applications[proj + '_' + appl]['containers'].append({ 'id': container, 'ipaddr': ipaddr }) print('added container ' + container + '(' + ipaddr + ') to ' + proj) except Exception as exc: print(exc) import jinja2 templateLoader = jinja2.FileSystemLoader(searchpath="/") templateEnv = jinja2.Environment(loader=templateLoader) from jinja2 import Template template = templateEnv.get_template( os.path.join(datadir, 'haproxy/haproxy.cfg.jinja2')) with open("/etc/haproxy/haproxy.cfg", "wb") as fh: fh.write(template.render(applications=applications, config=config)) #print (template.render(applications=applications)) template = templateEnv.get_template( os.path.join(datadir, 'haproxy/haproxy.global.cfg.jinja2')) with open("/etc/haproxy/haproxy.global.cfg", "wb") as fh: fh.write(template.render(applications=applications, config=config)) import shlex, subprocess try: pid = int(open('/var/run/haproxy.pid', 'r').read()) os.kill(pid, 0) args = shlex.split( '/bin/bash -c "haproxy -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -D -sf $(</var/run/haproxy.pid)"' ) except (IOError, OSError) as e: args = shlex.split( '/bin/bash -c "haproxy -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -D"' ) finally: p = subprocess.Popen(args) try: pid = int(open('/var/run/haproxy.global.pid', 'r').read()) os.kill(pid, 0) args = shlex.split( '/bin/bash -c "haproxy -f /etc/haproxy/haproxy.global.cfg -p /var/run/haproxy.global.pid -D -sf $(</var/run/haproxy.global.pid)"' ) except (IOError, OSError) as e: args = shlex.split( '/bin/bash -c "haproxy -f /etc/haproxy/haproxy.global.cfg -p /var/run/haproxy.global.pid -D"' ) finally: p = subprocess.Popen(args)