def install_haproxy(serv, **kwargs): import sql script = "install_haproxy.sh" hap_sock_p = sql.get_setting('haproxy_sock_port') stats_port = sql.get_setting('stats_port') server_state_file = sql.get_setting('server_state_file') stats_user = sql.get_setting('stats_user') stats_password = sql.get_setting('stats_password') proxy = sql.get_setting('proxy') hapver = kwargs.get('hapver') ssh_port = 22 ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = return_ssh_keys_path(serv) if ssh_enable == 0: ssh_key_name = '' servers = sql.select_servers(server=serv) for server in servers: ssh_port = str(server[10]) os.system("cp scripts/%s ." % script) if hapver is None: hapver = '2.0.7-1' if proxy is not None and proxy != '' and proxy != 'None': proxy_serv = proxy else: proxy_serv = '' syn_flood_protect = '1' if kwargs.get('syn_flood') == "1" else '' commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " SOCK_PORT=" + hap_sock_p + " STAT_PORT=" + stats_port + " STAT_FILE="+server_state_file + " SSH_PORT=" + ssh_port + " STATS_USER="******" STATS_PASS="******" HAPVER=" + hapver + " SYN_FLOOD=" + syn_flood_protect + " HOST=" + serv + " USER="******" PASS="******" KEY=" + ssh_key_name] output, error = subprocess_execute(commands[0]) if error: logging('localhost', error, haproxywi=1) print('error: '+error) else: for l in output: if "msg" in l or "FAILED" in l: try: l = l.split(':')[1] l = l.split('"')[1] print(l+"<br>") break except Exception: print(output) break else: print('success: HAProxy was installed<br>') os.system("rm -f %s" % script) sql.update_haproxy(serv)
def install_haproxy(serv, **kwargs): import sql script = "install_haproxy.sh" hap_sock_p = sql.get_setting('haproxy_sock_port') stats_port = sql.get_setting('stats_port') server_state_file = sql.get_setting('server_state_file') stats_user = sql.get_setting('stats_user') stats_password = sql.get_setting('stats_password') proxy = sql.get_setting('proxy') hapver = kwargs.get('hapver') server_for_installing = kwargs.get('server') ssh_port = 22 ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = return_ssh_keys_path( serv) if ssh_enable == 0: ssh_key_name = '' servers = sql.select_servers(server=serv) for server in servers: ssh_port = str(server[10]) os.system("cp scripts/%s ." % script) if hapver is None: hapver = '2.3.0-1' if proxy is not None and proxy != '' and proxy != 'None': proxy_serv = proxy else: proxy_serv = '' syn_flood_protect = '1' if kwargs.get('syn_flood') == "1" else '' commands = [ "chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " SOCK_PORT=" + hap_sock_p + " STAT_PORT=" + stats_port + " STAT_FILE=" + server_state_file + " SSH_PORT=" + ssh_port + " STATS_USER="******" STATS_PASS="******" HAPVER=" + hapver + " SYN_FLOOD=" + syn_flood_protect + " HOST=" + serv + " USER="******" PASS="******" KEY=" + ssh_key_name ] output, error = subprocess_execute(commands[0]) if server_for_installing: service = server_for_installing + ' HAProxy' else: service = ' HAProxy' show_installation_output(error, output, service) os.system("rm -f %s" % script) sql.update_haproxy(serv)