From 9315157f2ff8104c9a800c5e874823685c533fb0 Mon Sep 17 00:00:00 2001 From: Joao Gilberto Magalhaes Date: Thu, 4 Oct 2018 21:46:23 -0500 Subject: [PATCH] Fix read config --- entrypoint.py | 8 +++++++- entrypoint.sh | 10 ++++++---- example.yml | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 example.yml diff --git a/entrypoint.py b/entrypoint.py index ce3a504..21a8298 100644 --- a/entrypoint.py +++ b/entrypoint.py @@ -1,4 +1,9 @@ import yaml +import sys + +if len(sys.argv) != 2: + print("You need to pass the easyconfig.cfg path") + exit(1) def defaults(custom): @@ -94,7 +99,8 @@ backend srv_{1}_{0} return result -parsed = yaml.load("/etc/easyconfig/easyconfig.cfg") +with open(sys.argv[1], 'r') as content_file: + parsed = yaml.load(content_file.read()) print(defaults(parsed["customerrors"] if "customerrors" in parsed else False)) if "stats" in parsed: diff --git a/entrypoint.sh b/entrypoint.sh index d5442db..9eb6d31 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -12,16 +12,18 @@ echo " __/ | __/ |" echo " |___/ |___/ " echo "" -if [ ! -f "/etc/easyconfig/easyconfig.cfg" ] +HAPROXY_CFG="/etc/haproxy/haproxy.cfg" +EASYCONFIG_CFG="/etc/easyconfig/easyconfig.cfg" + +if [ ! -f "$EASYCONFIG_CFG" ] then - echo "File '/etc/easyconfig/easyconfig.cfg' does not exist" + echo "File '$EASYCONFIG_CFG' does not exist" exit 1 fi -HAPROXY_CFG="/etc/haproxy/haproxy.cfg" -python3 /entrypoint.py > $HAPROXY_CFG +python3 /entrypoint.py "$EASYCONFIG_CFG" > $HAPROXY_CFG /sbin/syslogd -O /proc/1/fd/1 diff --git a/example.yml b/example.yml new file mode 100644 index 0000000..3371c9e --- /dev/null +++ b/example.yml @@ -0,0 +1,18 @@ +stats: + username: admin + password: senha + port: 1936 + +customerrors: true + +easymapping: + - port: 80 + hosts: + host1.com.br: container:5000 + host2.com.br: other:3000 + redirect: + www.host1.com.br: http://host1.com.br + + - port: 8080 + hosts: + host3.com.br: domain:8181 \ No newline at end of file