Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/dev/smc/conf/cloud.sagemath.com/push_conf.py
Views: 687
#!/usr/bin/env python212import os3os.chdir(os.path.split(os.path.realpath(__file__))[0])4import gen_conf56public_hosts = ["web%s" % n for n in range(3)]78hacfg = "haproxy.cfg"910os.system("mkdir -p bkb")111213def create(host = ''):14bkbfn = "bkb/haproxy-%s.cfg" % host15# generate the configuration file16gen_conf.gen_haproxy(host)17if os.path.exists(bkbfn):18if open(hacfg).read() == open(bkbfn).read():19# identical files, no need to update to targets20return False21# since it changed, make backup for the next time22os.system("cp -a haproxy.cfg %s" % bkbfn)23return True242526def push_conf(mode):27assert mode in ['public', 'private']2829if mode == "public":30# These are the web servers that are visible externally -- they also run haproxy31# and load balance between all web servers.32TARGETS = public_hosts3334elif mode == "private":35TARGETS = [x for x in gen_conf.web_hosts() if x not in public_hosts]3637# Now push out the haproxy script to the externally visible web servers38for host in TARGETS:39if (mode == "public" and create()) or (mode == "private" and create(host)):40os.system("scp %s %s:/tmp/" % (hacfg, host))41os.system("ssh %s 'sudo mv /tmp/%s /etc/haproxy/'" % (hacfg, host))42os.system("ssh %s 'sudo service haproxy reload'" % host)4344if __name__ == "__main__":45push_conf('public')46push_conf('private')474849