UI - basic services list

This commit is contained in:
bunkerity 2020-12-21 15:32:15 +01:00
parent c5f283b00e
commit 59b2fed416
No known key found for this signature in database
GPG Key ID: 654FFF51CEF7CC47
5 changed files with 58 additions and 28 deletions

View File

@ -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

View File

@ -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)

View File

@ -2,9 +2,9 @@
{% block content %}
<div class="text-center">
<!--<div class="text-center">
<button class="btn btn-success btn-lg mb-5"><i class="fas fa-plus"></i> new</button>
</div>
</div>-->
<div class="row justify-content-center">
@ -38,10 +38,12 @@
<div class="card-body text-dark">
<h5 class="card-title">Status : {{ instance["status"] }}</h5>
<span class="card-text">
Web services : <span class="badge bg-primary">X</span><br />
Environment variables :<br />
{% set envfilter = ["PATH", "NGINX_VERSION", "NJS_VERSION", "PKG_RELEASE"] %}
{% for env in instance.attrs["Config"]["Env"] %}
{{ env }}<br />
{% if not env.startswith("PATH=") and not env.startswith("NGINX_VERSION=") and not env.startswith("NJS_VERSION=") and not env.startswith("PKG_RELEASE=") %}
{{ env }}<br />
{% endif %}
{% endfor %}
</span>
</div>

View File

@ -2,41 +2,37 @@
{% block content %}
<div class="row justify-content-center">
{% 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 %}
<div class="col col-6">
<div class="card border-{{ color }} mb-3" style="max-width: 80rem;">
<div class="card-header border-{{ color }} bg-{{ color }}">
{{ service["name"] }}
<div class="btn-group mx-2 float-end" role="group">
<div class="card border-primary mb-3" style="max-width: 80rem;">
<div class="card-header border-primary bg-primary">
{{ service["SERVER_NAME"] }}
<!--<div class="btn-group mx-2 float-end" role="group">
<button id="btnGroupDrop1" class="btn btn-sm dropdown-toggle btn-light" data-bs-toggle="dropdown" aria-expanded="false">
<i class="fas fa-cogs"> manage container</i>
</button>
<ul class="dropdown-menu" aria-labelledby="btnGroupDrop1">
<li><a class="dropdown-item" href="service/start/{{ service["id"] }}">Start</a></li>
<li><a class="dropdown-item" href="service/stop/{{ service["id"] }}">Stop</a></li>
<li><a class="dropdown-item" href="service/restart/{{ service["id"] }}">Restart</a></li>
<li><a class="dropdown-item" href="#">Start</a></li>
<li><a class="dropdown-item" href="#">Stop</a></li>
<li><a class="dropdown-item" href="#">Restart</a></li>
<li><a class="dropdown-item" href="#">Remove</a></li>
</ul>
</div>
<button class="btn btn-sm mx-2 float-end btn-light"><i class="fas fa-redo-alt"></i> reload nginx</button>-->
</div>
<div class="card-body text-dark">
<h5 class="card-title">Status : {{ service["status"] }}</h5>
<h5 class="card-title">Server name : {{ service["SERVER_NAME"] }}</h5>
<span class="card-text">
Web services : <span class="badge bg-primary">X</span><br />
Environment variables :<br />
{% for env in service.attrs["Config"]["Env"] %}
{{ env }}<br />
{% 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 }}<br />
{% endif %}
{% endfor %}
</span>
</div>

View File

@ -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