Skip to content

Commit

Permalink
First release
Browse files Browse the repository at this point in the history
  • Loading branch information
kladkogex committed Jun 7, 2021
1 parent 4c520e6 commit 0d5d5fd
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions periodic_config_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
from os import path
from shutil import copyfile

CONFIG_FILE = "/etc/nginx/sites-available/default"
TMP_CONFIG_FILE = "/tmp/tmp.config"
CERT_FILE = "/data/server.crt"
KEY_FILE = "/data/server.key"


class ChainInfo:
def __init__(self, _network: str, _chain_name: str, _list_of_domain_endpoints: list):
Expand All @@ -20,9 +25,15 @@ def run(_command):
subprocess.check_call(_command, shell=True)


def print_global_server_config(_f):
def print_global_server_config(_f, _use_ssl: bool):
_f.write("server {\n")
_f.write(" listen 80;\n")
if _use_ssl:
_f.write(" listen 443 ssl;\n")
_f.write(" ssl_certificate " + CERT_FILE + "\n")
_f.write(" ssl_certificate_key " + KEY_FILE + "\n")
_f.write(" ssl_verify_client off;\n")
else:
_f.write(" listen 80;\n")
_f.write(" root /usr/share/nginx/www;\n")
_f.write(" index index.php index.html index.htm;\n")
_f.write(" server_name localhost;\n")
Expand All @@ -49,7 +60,10 @@ def print_config_file(_chain_infos: list):
with open(TMP_CONFIG_FILE, 'w') as f:
for chain_info in _chain_infos:
print_group_definition(chain_info, f)
print_global_server_config(f)
print_global_server_config(f, False)
for chain_info in _chain_infos:
print_loadbalacing_config_for_chain(chain_info, f)
print_global_server_config(f, True)
for chain_info in _chain_infos:
print_loadbalacing_config_for_chain(chain_info, f)
f.write("}\n")
Expand All @@ -65,9 +79,6 @@ def copy_config_file_if_modified():
run("/usr/sbin/nginx -s reload")


CONFIG_FILE = "/etc/nginx/sites-available/default"
TMP_CONFIG_FILE = "/tmp/tmp.config"

endpoints = list()
endpoints.append("testnet-16.skalenodes.com:10131")
endpoints.append("testnet-15.skalenodes.com:10195")
Expand All @@ -80,8 +91,18 @@ def copy_config_file_if_modified():
chain_infos.append(chain_info)

# let nginx start)


time.sleep(30)

if not path.exists(CERT_FILE):
print("Fatal error: could not find:" + CERT_FILE + " Exiting.")
exit(-1)

if not path.exists(KEY_FILE):
print("Fatal error: could not find:" + KEY_FILE + " Exiting.")
exit(-2)

while True:
print("Checking Config file ")
print_config_file(chain_infos)
Expand Down

0 comments on commit 0d5d5fd

Please sign in to comment.