diff --git a/entrypoint/site-config.sh b/entrypoint/site-config.sh index 89fb108..ec70b52 100644 --- a/entrypoint/site-config.sh +++ b/entrypoint/site-config.sh @@ -1,7 +1,9 @@ #!/bin/bash # load default values +set -a . /opt/entrypoint/defaults.sh +set +a # load some functions . /opt/entrypoint/utils.sh @@ -10,6 +12,20 @@ NGINX_PREFIX="/etc/nginx/" if [ "$MULTISITE" = "yes" ] ; then NGINX_PREFIX="${NGINX_PREFIX}${1}/" + if [ ! -d "$NGINX_PREFIX" ] ; then + mkdir "$NGINX_PREFIX" + fi + ROOT_FOLDER="${ROOT_FOLDER}/$1" +fi +env | grep -E -v "^(HOSTNAME|PWD|PKG_RELEASE|NJS_VERSION|SHLVL|PATH|_|NGINX_VERSION)=" > "${NGINX_PREFIX}nginx.env" + +if [ "$MULTISITE" = "yes" ] ; then + sed -i "s~^SERVER_NAME=.*~SERVER_NAME=$1~" "${NGINX_PREFIX}nginx.env" + for server in $SERVER_NAME ; do + if [ "$server" != "$1" ] ; then + sed -i "/^${server}_.*=.*/d" "${NGINX_PREFIX}nginx.env" + fi + done for var in $(env) ; do name=$(echo "$var" | cut -d '=' -f 1) check=$(echo "$name" | grep "^$1_") @@ -17,15 +33,14 @@ if [ "$MULTISITE" = "yes" ] ; then repl_name=$(echo "$name" | sed "s~${1}_~~") repl_value=$(echo "$var" | sed "s~${name}=~~") read -r "$repl_name" <<< $repl_value + sed -i "/^${repl_name}=.*/d" "${NGINX_PREFIX}nginx.env" + sed -i "/^${name}=.*/d" "${NGINX_PREFIX}nginx.env" + echo "${repl_name}=${repl_value}" >> "${NGINX_PREFIX}nginx.env" fi done - ROOT_FOLDER="${ROOT_FOLDER}/$1" fi # copy stub confs -if [ "$MULTISITE" = "yes" ] ; then - mkdir "$NGINX_PREFIX" -fi cp /opt/confs/site/* "$NGINX_PREFIX" # replace paths diff --git a/ui/entrypoint.py b/ui/entrypoint.py index b964eca..4fa6d04 100644 --- a/ui/entrypoint.py +++ b/ui/entrypoint.py @@ -33,6 +33,7 @@ def instances(): @app.route('/services') def services(): check, services = wrappers.get_services() + print(services, flush=True) if not check : return render_template("error.html", title="Error", error=services) return render_template("services.html", title="Services", services=services) diff --git a/ui/templates/instances.html b/ui/templates/instances.html index 2d2fccc..87893ae 100644 --- a/ui/templates/instances.html +++ b/ui/templates/instances.html @@ -2,9 +2,9 @@ {% block content %} -
+
@@ -38,10 +38,12 @@
Status : {{ instance["status"] }}
- Web services : X
Environment variables :
+ {% set envfilter = ["PATH", "NGINX_VERSION", "NJS_VERSION", "PKG_RELEASE"] %} {% for env in instance.attrs["Config"]["Env"] %} - {{ env }}
+ {% if not env.startswith("PATH=") and not env.startswith("NGINX_VERSION=") and not env.startswith("NJS_VERSION=") and not env.startswith("PKG_RELEASE=") %} + {{ env }}
+ {% endif %} {% endfor %}
diff --git a/ui/templates/services.html b/ui/templates/services.html index ecbf87b..de36b53 100644 --- a/ui/templates/services.html +++ b/ui/templates/services.html @@ -2,41 +2,37 @@ {% block content %} +
{% for service in services %} - {% set color = "dark" %} - {% if service["status"] == "running" %} - {% set color = "success" %} - {% elif service["status"] == "created" or service["status"] == "restarting" or service["status"] == "paused" %} - {% set color = "warning" %} - {% elif service["status"] == "exited" or service["status"] == "dead" %} - {% set color = "danger" %} - {% endif %}
-
-
- {{ service["name"] }} -
+
+
+ {{ service["SERVER_NAME"] }} +
-
Status : {{ service["status"] }}
+
Server name : {{ service["SERVER_NAME"] }}
- Web services : X
Environment variables :
- {% for env in service.attrs["Config"]["Env"] %} - {{ env }}
+ {% set envfilter = ["PATH", "NGINX_VERSION", "NJS_VERSION", "PKG_RELEASE"] %} + {% for k, v in service.items() %} + {% if not k.startswith("PATH=") and not k.startswith("NGINX_VERSION=") and not k.startswith("NJS_VERSION=") and not k.startswith("PKG_RELEASE=") %} + {{ k + "=" + v }}
+ {% endif %} {% endfor %}
diff --git a/ui/wrappers.py b/ui/wrappers.py index 1e40507..c234af7 100644 --- a/ui/wrappers.py +++ b/ui/wrappers.py @@ -27,4 +27,20 @@ def get_instances() : return get_containers("UI") def get_services() : - return get_containers("SERVER_NAME") + services = [] + try : + for root, dirs, files in os.walk("/etc/nginx") : + for file in files : + filepath = os.path.join(root, file) + print(filepath, flush=True) + if filepath.endswith("/nginx.env") : + with open(filepath, "r") as f : + service = {} + for line in f.readlines() : + name = line.split("=")[0] + value = line.replace(name + "=", "", 1).strip() + service[name] = value + services.append(service) + except Exception as e : + return False, str(e) + return True, services