devzone 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.devcontainer/agent-errors.sh +6 -6
- package/.devcontainer/agent-pod-manifest.sh +4 -4
- package/.devcontainer/agent-session.sh +2 -2
- package/.devcontainer/agent-state-json.sh +2 -2
- package/.devcontainer/agent-workspace.sh +1 -1
- package/.devcontainer/agent.sh +7 -7
- package/.devcontainer/ai/host-models.sh +2 -2
- package/.devcontainer/ai/plugins/devzone-guard-v2.js +3 -3
- package/.devcontainer/ai/plugins/devzone-guard.js +3 -3
- package/.devcontainer/argocd/argocd.sh +90 -89
- package/.devcontainer/argocd/catalog-argocd.sh +2 -2
- package/.devcontainer/argocd/services-hook.sh +3 -3
- package/.devcontainer/argocd/services.sh +1 -1
- package/.devcontainer/catalog/app.sh +114 -116
- package/.devcontainer/catalog/catalog-watcher.sh +62 -62
- package/.devcontainer/catalog/mysql/app.conf +1 -1
- package/.devcontainer/catalog/mysql/install.sh +40 -40
- package/.devcontainer/catalog/mysql/mysql.sh +141 -141
- package/.devcontainer/catalog/mysql/volume.sh +39 -39
- package/.devcontainer/catalog.sh +112 -112
- package/.devcontainer/chart-direct.sh +1 -1
- package/.devcontainer/cluster.sh +216 -218
- package/.devcontainer/clusters.sh +41 -41
- package/.devcontainer/devzone +92 -1495
- package/.devcontainer/devzone-ai-guard.sh +76 -0
- package/.devcontainer/devzone-ai.sh +201 -0
- package/.devcontainer/devzone-cluster.sh +210 -0
- package/.devcontainer/devzone-modules.sh +126 -0
- package/.devcontainer/devzone-platform.sh +189 -0
- package/.devcontainer/devzone-repair.sh +94 -0
- package/.devcontainer/devzone-services.sh +241 -0
- package/.devcontainer/devzone-skill.sh +97 -0
- package/.devcontainer/devzone-status.sh +140 -0
- package/.devcontainer/devzone-version.sh +78 -0
- package/.devcontainer/git-identity.sh +28 -0
- package/.devcontainer/gitlab/chart.sh +2 -2
- package/.devcontainer/gitlab/gitlab.sh +81 -82
- package/.devcontainer/gitlab/installation.sh +109 -109
- package/.devcontainer/gitlab/secrets.sh +47 -47
- package/.devcontainer/gitlab/seed.sh +77 -77
- package/.devcontainer/gitlab/test-gitlab.sh +242 -243
- package/.devcontainer/help.sh +1 -1
- package/.devcontainer/isolation.sh +30 -30
- package/.devcontainer/kind-wrapper.sh +17 -17
- package/.devcontainer/kube-account.sh +112 -113
- package/.devcontainer/kube-config.sh +45 -46
- package/.devcontainer/{invite-kube.sh → kube-prompt.sh} +6 -6
- package/.devcontainer/kube-reachable.sh +40 -40
- package/.devcontainer/memory.sh +1 -1
- package/.devcontainer/metrics-server.sh +2 -2
- package/.devcontainer/opencode.jsonc +2 -2
- package/.devcontainer/packages.sh +136 -135
- package/.devcontainer/password.sh +1 -1
- package/.devcontainer/ports-auto.sh +152 -153
- package/.devcontainer/ports-json.sh +16 -15
- package/.devcontainer/ports.sh +126 -122
- package/.devcontainer/post-create.sh +52 -52
- package/.devcontainer/postgres/postgres.sh +174 -174
- package/.devcontainer/rename-legacy-files.sh +103 -0
- package/.devcontainer/services-admin.sh +3 -3
- package/.devcontainer/skills/devzone/SKILL.md +40 -41
- package/.devcontainer/startup.sh +48 -49
- package/.devcontainer/state-gitops.sh +1 -1
- package/.devcontainer/state-json.sh +36 -62
- package/.devcontainer/state.sh +2 -2
- package/.devcontainer/workspace-init.sh +16 -2
- package/Makefile +1 -1
- package/README.md +195 -194
- package/charts/devzone-workspace/templates/statefulset.yaml +1 -1
- package/manage/devzone +5 -7
- package/manage/scripts/argocd-workspace.sh +1 -1
- package/manage/scripts/check-names.sh +6 -5
- package/manage/scripts/create-cluster.sh +1 -1
- package/manage/scripts/create-mode.sh +2 -2
- package/manage/scripts/devzone-create.sh +3 -3
- package/manage/scripts/devzone-manifest.sh +1 -1
- package/manage/scripts/devzone-update.sh +12 -8
- package/manage/scripts/launch.sh +7 -48
- package/manage/scripts/migrate-revert.sh +3 -3
- package/manage/scripts/migrate.sh +7 -13
- package/manage/scripts/ports-apps.sh +1 -1
- package/manage/scripts/ports-workspace.sh +7 -7
- package/manage/scripts/uninstall.sh +8 -8
- package/manage/scripts/workspace-egress.sh +2 -2
- package/manage/scripts/workspace-update.sh +5 -2
- package/manage/scripts/workspace-wait.sh +2 -2
- package/package.json +1 -1
- package/.devcontainer/docker-relay.sh +0 -149
- package/.devcontainer/docker-without-host.sh +0 -12
- package/.devcontainer/git-identite.sh +0 -28
|
@@ -1,151 +1,150 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
|
|
2
|
+
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
3
3
|
# shellcheck source=ports.sh
|
|
4
4
|
# shellcheck disable=SC1091
|
|
5
|
-
. "$
|
|
5
|
+
. "$HERE/ports.sh"
|
|
6
6
|
PORTS_AUTO_DIR="${DEVZONE_PORTS_AUTO_DIR:-/tmp/devzone-ports-auto}"
|
|
7
7
|
BASE="$PORTS_AUTO_DIR/${INSTANCE:-devzone}"
|
|
8
8
|
BRIDGES="$BASE/bridges"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
COURANT="$BASE/courant"
|
|
9
|
+
# State file names on disk (verrou, occupes, actifs, courant) are kept: tests and the watcher use them
|
|
10
|
+
LOCK="$BASE/verrou"; BUSY="$BASE/occupes"; ACTIVE="$BASE/actifs"
|
|
11
|
+
PENDING="$BASE/pending"; CURRENT="$BASE/courant"
|
|
12
|
+
JSON_APP_BUSY=$'occup\303\251 sur le poste' # JSON value, contract (see ports.sh)
|
|
14
13
|
mkdir -p "$BASE" "$BRIDGES"
|
|
15
14
|
|
|
16
|
-
#
|
|
17
|
-
|
|
18
|
-
#
|
|
19
|
-
|
|
20
|
-
#
|
|
21
|
-
|
|
22
|
-
#
|
|
23
|
-
|
|
24
|
-
#
|
|
25
|
-
|
|
26
|
-
#
|
|
27
|
-
|
|
28
|
-
#
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
|
|
15
|
+
# Automatic watcher state: off as soon as ports_auto= is off (« non » kept as a stored value)
|
|
16
|
+
auto_enabled() { local v; v="$(grep -E '^ports_auto=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true)"; case "$v" in off|false|0|non|no) echo off ;; *) echo on ;; esac; }
|
|
17
|
+
# List of the ports excluded by the user (ports_exclus=, comma-separated)
|
|
18
|
+
excluded_read() { grep -E '^ports_exclus=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true; }
|
|
19
|
+
# Writes a key=value line in the state, like write_ports does for ports=
|
|
20
|
+
write_key() { state_write "$1" "${2:-}" || { echo "devzone : port : state not saved : $ETAT" >&2; return 1; }; }
|
|
21
|
+
# A port is excluded when it is listed in ports_exclus=.
|
|
22
|
+
port_excluded() { case ",$(excluded_read)," in *",$1,"*) return 0 ;; esac; return 1; }
|
|
23
|
+
# Name of the automatic relay of a port: devzone-<instance>-auto-<port>.
|
|
24
|
+
auto_relay_name() { echo "devzone-$INSTANCE-auto-$1"; }
|
|
25
|
+
# Is the automatic relay of <port> already alive on the host's Docker?
|
|
26
|
+
auto_relay_active() { local name; name="$(auto_relay_name "$1")"; command -v docker >/dev/null 2>&1 || return 1; [ -n "$(docker ps --filter "name=^$name$" --format '{{.Names}}' 2>/dev/null | grep -Fx "$name" || true)" ]; }
|
|
27
|
+
# Delay after a port disappears before removing its bridge and relay.
|
|
28
|
+
disappearance_delay() { local v; for v in DEVZONE_PORTS_AUTO_DISAPPEARANCE_DELAY DEVZONE_PORTS_AUTO_DELAY DEVZONE_PORTS_AUTO_LATE PORTS_AUTO_DELAI PORTS_AUTO_RETARD; do [ -n "${!v:-}" ] && { echo "${!v}"; return 0; }; done; echo 10; }
|
|
29
|
+
|
|
30
|
+
# Guard: the loop and demarrer never run under bats,
|
|
31
|
+
# and outside the container only if the real context is set.
|
|
32
|
+
guard_watcher() {
|
|
34
33
|
if [ -n "${BATS_TEST_TMPDIR:-}" ]; then
|
|
35
|
-
echo "devzone : port :
|
|
34
|
+
echo "devzone : port : automatic watcher refused under bats (tests)" >&2
|
|
36
35
|
return 2
|
|
37
36
|
fi
|
|
38
|
-
[ "${
|
|
39
|
-
echo "devzone : port :
|
|
37
|
+
[ "${DEVZONE_PORTS_AUTO_REAL:-}" = yes ] && return 0
|
|
38
|
+
echo "devzone : port : automatic watcher refused here: run devzone repair instead" >&2
|
|
40
39
|
return 2
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
#
|
|
44
|
-
|
|
45
|
-
local port="$1"
|
|
46
|
-
|
|
47
|
-
if
|
|
48
|
-
case "$
|
|
42
|
+
# Launches the automatic relay; on failure, a message and code 1 (busy port marked).
|
|
43
|
+
launch_auto() {
|
|
44
|
+
local port="$1" network="$2" ip="$3" name output
|
|
45
|
+
name="$(auto_relay_name "$port")"
|
|
46
|
+
if output="$(docker run -d --restart unless-stopped --name "$name" --label "devzone.instance=$INSTANCE" --label "devzone.port=$port" --label "devzone.auto=true" --network "$network" -p "127.0.0.1:$port:$port" "$SOCAT_IMAGE" "tcp-listen:$port,fork,reuseaddr" "tcp-connect:$ip:$port" 2>&1)"; then return 0; fi
|
|
47
|
+
case "$output" in *"port is already allocated"*|*"address already in use"*) echo "devzone : port : port already in use on the workstation : $port" >&2 ;; *) echo "devzone : port : relay on port $port failed : $output" >&2 ;; esac
|
|
49
48
|
return 1
|
|
50
49
|
}
|
|
51
|
-
#
|
|
52
|
-
|
|
53
|
-
#
|
|
54
|
-
|
|
55
|
-
#
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
#
|
|
59
|
-
|
|
60
|
-
local port; [ -f "$
|
|
61
|
-
[ -f "$
|
|
62
|
-
: >"$
|
|
50
|
+
# Starts the internal bridge: socat on the container IP, toward the 127.0.0.1 of the port.
|
|
51
|
+
start_bridge() { local port="$1" ip="$2"; local pidfile="$BRIDGES/$port.pid"; if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile" 2>/dev/null)" 2>/dev/null; then return 0; fi; socat "TCP-LISTEN:$port,bind=$ip,fork,reuseaddr" "TCP:127.0.0.1:$port" >/dev/null 2>&1 & echo "$!" >"$pidfile"; }
|
|
52
|
+
# Stops the internal bridge (pid in $BRIDGES).
|
|
53
|
+
stop_bridge() { local port="$1"; local pidfile="$BRIDGES/$port.pid"; local pid; if [ -f "$pidfile" ]; then pid="$(cat "$pidfile" 2>/dev/null || true)"; if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; fi; wait "$pid" 2>/dev/null || true; rm -f "$pidfile"; fi; }
|
|
54
|
+
# Removes the automatic relay and its bridge.
|
|
55
|
+
close_auto() { local port="$1"; docker rm -f "$(auto_relay_name "$port")" >/dev/null 2>&1 || true; stop_bridge "$port"; }
|
|
56
|
+
|
|
57
|
+
# Removes all the automatic relays and their bridges, then empties the states.
|
|
58
|
+
clean_auto_all() {
|
|
59
|
+
local port; [ -f "$ACTIVE" ] && while IFS= read -r port; do [ -n "$port" ] && close_auto "$port"; done <"$ACTIVE"
|
|
60
|
+
[ -f "$BUSY" ] && while IFS= read -r port; do [ -n "$port" ] && stop_bridge "$port"; done <"$BUSY"
|
|
61
|
+
: >"$ACTIVE" 2>/dev/null || true; : >"$BUSY" 2>/dev/null || true; : >"$PENDING" 2>/dev/null || true; rm -f "$BRIDGES"/*.pid 2>/dev/null || true
|
|
63
62
|
}
|
|
64
|
-
#
|
|
65
|
-
|
|
63
|
+
# Removes the automatic relays of a previous session.
|
|
64
|
+
clean_previous() { docker ps -a --filter "name=devzone-$INSTANCE-auto-" --format '{{.Names}}' 2>/dev/null | while IFS= read -r name; do case "$name" in devzone-"$INSTANCE"-auto-*) docker rm -f "$name" >/dev/null 2>&1 || true ;; esac; done; rm -f "$BRIDGES"/*.pid 2>/dev/null || true; }
|
|
66
65
|
|
|
67
|
-
#
|
|
68
|
-
|
|
69
|
-
local
|
|
70
|
-
|
|
66
|
+
# Exclusive lock (mkdir) with a pid: a single watcher instance.
|
|
67
|
+
lock_take() {
|
|
68
|
+
local start now age pid
|
|
69
|
+
start="$(date +%s)"
|
|
71
70
|
while true; do
|
|
72
|
-
if mkdir "$
|
|
73
|
-
now="$(date +%s)"; age=""; [ -d "$
|
|
74
|
-
pid="$(cat "$
|
|
75
|
-
if [ -n "$age" ] && [ "$(( now - age ))" -gt 30 ]; then rm -rf "$
|
|
76
|
-
if [ -n "$pid" ] && ! kill -0 "$pid" 2>/dev/null; then rm -rf "$
|
|
77
|
-
[ "$(( now -
|
|
71
|
+
if mkdir "$LOCK" 2>/dev/null; then echo "$$" >"$LOCK/pid"; return 0; fi
|
|
72
|
+
now="$(date +%s)"; age=""; [ -d "$LOCK" ] && age="$(stat -c %Y "$LOCK" 2>/dev/null || stat -f %m "$LOCK" 2>/dev/null || true)"
|
|
73
|
+
pid="$(cat "$LOCK/pid" 2>/dev/null || true)"
|
|
74
|
+
if [ -n "$age" ] && [ "$(( now - age ))" -gt 30 ]; then rm -rf "$LOCK"; continue; fi
|
|
75
|
+
if [ -n "$pid" ] && ! kill -0 "$pid" 2>/dev/null; then rm -rf "$LOCK"; continue; fi
|
|
76
|
+
[ "$(( now - start ))" -ge 5 ] && return 1
|
|
78
77
|
sleep 1
|
|
79
78
|
done
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
#
|
|
83
|
-
#
|
|
84
|
-
|
|
81
|
+
# Marks the lock as alive: recent date and pid of the holder up to date,
|
|
82
|
+
# otherwise another instance takes the lock as stale.
|
|
83
|
+
lock_refresh() { touch "$LOCK" 2>/dev/null || true; echo "$$" >"$LOCK/pid" 2>/dev/null || true; }
|
|
85
84
|
|
|
86
|
-
#
|
|
87
|
-
|
|
88
|
-
local port now delay
|
|
89
|
-
#
|
|
85
|
+
# One watcher pass: relays the listening ports, removes the vanished ones.
|
|
86
|
+
auto_pass() {
|
|
87
|
+
local port now delay output
|
|
88
|
+
# State restored or rebuilt: nothing for 60 s (#417, step 4)
|
|
90
89
|
state_recovery_wait && return 0
|
|
91
|
-
if [ "$(
|
|
92
|
-
#
|
|
93
|
-
state_recovery_pending ||
|
|
90
|
+
if [ "$(auto_enabled)" = off ]; then
|
|
91
|
+
# Never uninstall on an unconfirmed state (#417, step 4)
|
|
92
|
+
state_recovery_pending || clean_auto_all
|
|
94
93
|
return 0
|
|
95
94
|
fi
|
|
96
|
-
if !
|
|
97
|
-
: >"$
|
|
98
|
-
ss -ltnH 2>/dev/null | awk '{ if (NF >= 4) print $4; else if (NF >= 1) print $1 }' | while IFS= read -r
|
|
99
|
-
[ -n "$
|
|
100
|
-
p="${
|
|
95
|
+
if ! network_ip; then echo "devzone : ports-auto : devzone container not found" >&2; return 1; fi
|
|
96
|
+
: >"$CURRENT"
|
|
97
|
+
ss -ltnH 2>/dev/null | awk '{ if (NF >= 4) print $4; else if (NF >= 1) print $1 }' | while IFS= read -r listen; do
|
|
98
|
+
[ -n "$listen" ] || continue
|
|
99
|
+
p="${listen##*:}"; a="${listen%:*}"; a="${a#[}"; a="${a%]}"
|
|
101
100
|
case "$p" in ''|*[!0-9]*) continue ;; esac
|
|
102
101
|
[ "$a" = "127.0.0.11" ] && continue
|
|
103
102
|
[ "$p" -lt 1024 ] 2>/dev/null && continue
|
|
104
103
|
case "$p" in 5432|8929|2224) continue ;; esac
|
|
105
|
-
case ",$(
|
|
106
|
-
|
|
104
|
+
case ",$(read_ports)," in *",$p,"*) continue ;; esac
|
|
105
|
+
port_excluded "$p" && continue
|
|
107
106
|
[ "$a" = "$IP" ] && continue
|
|
108
|
-
printf '%s %s\n' "$a" "$p" >>"$
|
|
107
|
+
printf '%s %s\n' "$a" "$p" >>"$CURRENT"
|
|
109
108
|
done
|
|
110
|
-
awk '{print $2}' "$
|
|
111
|
-
awk '$1=="0.0.0.0" || $1=="::" || $1=="*" || $1==":::" {print $2}' "$
|
|
109
|
+
awk '{print $2}' "$CURRENT" 2>/dev/null | sort -n -u >"$BASE/actuels"
|
|
110
|
+
awk '$1=="0.0.0.0" || $1=="::" || $1=="*" || $1==":::" {print $2}' "$CURRENT" 2>/dev/null | sort -n -u >"$BASE/allif"
|
|
112
111
|
: >"$BASE/managed"
|
|
113
|
-
[ -f "$
|
|
112
|
+
[ -f "$ACTIVE" ] && cat "$ACTIVE" >>"$BASE/managed"
|
|
114
113
|
for f in "$BRIDGES"/*.pid; do [ -e "$f" ] || continue; basename "${f%.pid}" >>"$BASE/managed"; done
|
|
115
|
-
[ -f "$
|
|
114
|
+
[ -f "$BUSY" ] && cat "$BUSY" >>"$BASE/managed"
|
|
116
115
|
sort -n -u "$BASE/managed" -o "$BASE/managed" 2>/dev/null || true
|
|
117
116
|
|
|
118
|
-
now="$(date +%s)"; delay="$(
|
|
117
|
+
now="$(date +%s)"; delay="$(disappearance_delay)"
|
|
119
118
|
while IFS= read -r port; do
|
|
120
119
|
[ -n "$port" ] || continue
|
|
121
|
-
grep -qxF "$port" "$
|
|
122
|
-
grep -qxF "$port" "$
|
|
123
|
-
grep -qxF "$port" "$BASE/allif" ||
|
|
120
|
+
grep -qxF "$port" "$BUSY" 2>/dev/null && continue
|
|
121
|
+
grep -qxF "$port" "$ACTIVE" 2>/dev/null && continue
|
|
122
|
+
grep -qxF "$port" "$BASE/allif" || start_bridge "$port" "$IP"
|
|
124
123
|
# shellcheck disable=SC2153
|
|
125
|
-
if
|
|
126
|
-
grep -qxF "$port" "$
|
|
124
|
+
if output="$(launch_auto "$port" "$NETWORK" "$IP" 2>&1)"; then
|
|
125
|
+
grep -qxF "$port" "$ACTIVE" 2>/dev/null || echo "$port" >>"$ACTIVE"
|
|
127
126
|
else
|
|
128
|
-
printf '%s\n' "$
|
|
129
|
-
grep -qxF "$port" "$BASE/allif" ||
|
|
130
|
-
case "$
|
|
127
|
+
printf '%s\n' "$output" >&2
|
|
128
|
+
grep -qxF "$port" "$BASE/allif" || stop_bridge "$port"
|
|
129
|
+
case "$output" in *"already in use"*|*"already allocated"*) echo "$port" >>"$BUSY" ;; esac
|
|
131
130
|
fi
|
|
132
131
|
done <"$BASE/actuels"
|
|
133
132
|
|
|
134
133
|
while IFS= read -r port; do
|
|
135
134
|
[ -n "$port" ] || continue
|
|
136
135
|
grep -qxF "$port" "$BASE/actuels" 2>/dev/null && continue
|
|
137
|
-
if grep -qxF "$port" "$
|
|
138
|
-
grep -vxF "$port" "$
|
|
139
|
-
|
|
136
|
+
if grep -qxF "$port" "$BUSY" 2>/dev/null; then
|
|
137
|
+
grep -vxF "$port" "$BUSY" >"$BUSY.tmp" 2>/dev/null || true; mv "$BUSY.tmp" "$BUSY" 2>/dev/null || true
|
|
138
|
+
stop_bridge "$port"; continue
|
|
140
139
|
fi
|
|
141
140
|
if grep -q "^$port " "$PENDING" 2>/dev/null; then
|
|
142
|
-
|
|
143
|
-
#
|
|
141
|
+
old="$(grep "^$port " "$PENDING" | head -1 | cut -d' ' -f2)"
|
|
142
|
+
# Nothing is removed on an unconfirmed restored state (#417)
|
|
144
143
|
if state_recovery_pending; then continue; fi
|
|
145
|
-
if [ -n "$
|
|
146
|
-
|
|
144
|
+
if [ -n "$old" ] && [ "$(( now - old ))" -ge "$delay" ]; then
|
|
145
|
+
close_auto "$port"
|
|
147
146
|
grep -v "^$port " "$PENDING" >"$PENDING.tmp" 2>/dev/null || true; mv "$PENDING.tmp" "$PENDING" 2>/dev/null || true
|
|
148
|
-
grep -vxF "$port" "$
|
|
147
|
+
grep -vxF "$port" "$ACTIVE" >"$ACTIVE.tmp" 2>/dev/null || true; mv "$ACTIVE.tmp" "$ACTIVE" 2>/dev/null || true
|
|
149
148
|
fi
|
|
150
149
|
else
|
|
151
150
|
echo "$port $now" >>"$PENDING"
|
|
@@ -158,91 +157,91 @@ ports_auto_tour() {
|
|
|
158
157
|
done <"$BASE/actuels"
|
|
159
158
|
}
|
|
160
159
|
|
|
161
|
-
#
|
|
162
|
-
|
|
160
|
+
# Stops the watcher and cleans its relays.
|
|
161
|
+
stop_watcher() { local pid; pid="$(cat "$LOCK/pid" 2>/dev/null || true)"; if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; wait "$pid" 2>/dev/null || true; fi; clean_auto_all; rm -rf "$LOCK"; }
|
|
163
162
|
|
|
164
|
-
#
|
|
165
|
-
|
|
166
|
-
if !
|
|
167
|
-
|
|
168
|
-
trap '
|
|
163
|
+
# Loop: one pass every DEVZONE_PORTS_AUTO_STEP seconds.
|
|
164
|
+
auto_loop() {
|
|
165
|
+
if ! lock_take; then return 0; fi
|
|
166
|
+
clean_previous
|
|
167
|
+
trap 'clean_auto_all; rm -rf "$LOCK"' EXIT INT TERM
|
|
169
168
|
while true; do
|
|
170
|
-
#
|
|
169
|
+
# State restored or rebuilt: nothing for 60 s (#417, step 4)
|
|
171
170
|
if state_recovery_wait; then
|
|
172
|
-
|
|
173
|
-
sleep "${
|
|
171
|
+
lock_refresh
|
|
172
|
+
sleep "${DEVZONE_PORTS_AUTO_STEP:-2}"
|
|
174
173
|
continue
|
|
175
174
|
fi
|
|
176
|
-
#
|
|
177
|
-
if [ ! -f "$ETAT" ]; then
|
|
178
|
-
|
|
179
|
-
if [ "$(
|
|
180
|
-
#
|
|
181
|
-
state_recovery_pending ||
|
|
175
|
+
# State folder gone: the container has left, the watcher stops.
|
|
176
|
+
if [ ! -f "$ETAT" ]; then clean_auto_all; break; fi
|
|
177
|
+
lock_refresh
|
|
178
|
+
if [ "$(auto_enabled)" = off ]; then
|
|
179
|
+
# Never uninstall on an unconfirmed state (#417)
|
|
180
|
+
state_recovery_pending || clean_auto_all
|
|
182
181
|
break
|
|
183
182
|
fi
|
|
184
|
-
|
|
185
|
-
sleep "${
|
|
183
|
+
auto_pass || true
|
|
184
|
+
sleep "${DEVZONE_PORTS_AUTO_STEP:-2}"
|
|
186
185
|
done
|
|
187
186
|
}
|
|
188
187
|
|
|
189
|
-
#
|
|
190
|
-
|
|
191
|
-
#
|
|
192
|
-
|
|
188
|
+
# Excludes a port from the automatic list (writes ports_exclus=).
|
|
189
|
+
auto_exclude() { validate_port "${1:-}"; local current; current="$(excluded_read)"; case ",$current," in *",$1,"*) echo "port $1 already excluded"; return 0 ;; esac; write_key ports_exclus "$(sort_ports "$current,$1")"; echo "✔ port $1 excluded"; }
|
|
190
|
+
# Puts a port back in the automatic list (removes it from ports_exclus=).
|
|
191
|
+
auto_include() { validate_port "${1:-}"; local current rest p; current="$(excluded_read)"; rest=""; for p in $(printf '%s' "$current" | tr ',' ' '); do [ "$p" = "$1" ] || rest="$rest${rest:+,}$p"; done; write_key ports_exclus "$(sort_ports "$rest")"; echo "✔ port $1 included"; }
|
|
193
192
|
|
|
194
|
-
#
|
|
195
|
-
|
|
196
|
-
local port
|
|
197
|
-
if [ -f "$
|
|
193
|
+
# Lists the automatic relays alive (or busy on the workstation).
|
|
194
|
+
auto_list() {
|
|
195
|
+
local port mark app
|
|
196
|
+
if [ -f "$ACTIVE" ]; then
|
|
198
197
|
while IFS= read -r port; do
|
|
199
198
|
[ -n "$port" ] || continue
|
|
200
|
-
if grep -qxF "$port" "$
|
|
201
|
-
if
|
|
202
|
-
if
|
|
203
|
-
printf ' %-5s %s auto %s\n' "$port" "$
|
|
204
|
-
done <"$
|
|
199
|
+
if grep -qxF "$port" "$BUSY" 2>/dev/null; then printf ' %-5s %s auto\n' "$port" "busy on the workstation"; continue; fi
|
|
200
|
+
if auto_relay_active "$port"; then mark="● active"; else mark="○ stopped"; fi
|
|
201
|
+
if app_responds "$port"; then app="$APP_RESPONDS"; else app="$APP_NONE"; fi
|
|
202
|
+
printf ' %-5s %s auto %s\n' "$port" "$mark" "$app"
|
|
203
|
+
done <"$ACTIVE"
|
|
205
204
|
fi
|
|
206
|
-
if [ -f "$
|
|
205
|
+
if [ -f "$BUSY" ]; then
|
|
207
206
|
while IFS= read -r port; do
|
|
208
207
|
[ -n "$port" ] || continue
|
|
209
|
-
grep -qxF "$port" "$
|
|
210
|
-
printf ' %-5s %s auto\n' "$port" "
|
|
211
|
-
done <"$
|
|
208
|
+
grep -qxF "$port" "$ACTIVE" 2>/dev/null && continue
|
|
209
|
+
printf ' %-5s %s auto\n' "$port" "busy on the workstation"
|
|
210
|
+
done <"$BUSY"
|
|
212
211
|
fi
|
|
213
212
|
}
|
|
214
213
|
|
|
215
|
-
#
|
|
216
|
-
|
|
217
|
-
local port
|
|
218
|
-
[ -f "$
|
|
219
|
-
[ -f "$
|
|
214
|
+
# Machine output (jq) of the automatic relays.
|
|
215
|
+
auto_list_json() {
|
|
216
|
+
local port active app json='[]' ports=""
|
|
217
|
+
[ -f "$ACTIVE" ] && ports="$(cat "$ACTIVE")"
|
|
218
|
+
[ -f "$BUSY" ] && ports="$ports"$'\n'"$(cat "$BUSY")"
|
|
220
219
|
ports="$(printf '%s\n' "$ports" | awk 'NF' | sort -n -u)"
|
|
221
220
|
while IFS= read -r port; do
|
|
222
221
|
[ -n "$port" ] || continue
|
|
223
|
-
if grep -qxF "$port" "$
|
|
224
|
-
json="$(jq -c --argjson port "$port" '. + [{port:$port,
|
|
222
|
+
if grep -qxF "$port" "$BUSY" 2>/dev/null; then
|
|
223
|
+
json="$(jq -c --argjson port "$port" --arg busy "$JSON_APP_BUSY" '. + [{port:$port,active:false,application:$busy,auto:true}]' <<<"$json")"; continue
|
|
225
224
|
fi
|
|
226
|
-
if
|
|
227
|
-
if
|
|
228
|
-
json="$(jq -c --argjson port "$port" --argjson
|
|
225
|
+
if auto_relay_active "$port"; then active=true; else active=false; fi
|
|
226
|
+
if app_responds "$port"; then app="$JSON_APP_RESPONDS"; else app="$JSON_APP_NONE"; fi
|
|
227
|
+
json="$(jq -c --argjson port "$port" --argjson active "$active" --arg app "$app" '. + [{port:$port,active:$active,application:$app,auto:true}]' <<<"$json")"
|
|
229
228
|
done <<<"$ports"
|
|
230
229
|
printf '%s\n' "$json"
|
|
231
230
|
}
|
|
232
231
|
|
|
233
232
|
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
|
|
234
233
|
case "${1:-}" in
|
|
235
|
-
''|boucle|loop) if !
|
|
236
|
-
tour|one|un-tour)
|
|
237
|
-
demarrer|start|lancer) if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then echo "ports: Kubernetes workspace, ports go through devzone workspace ports"; exit 0; fi; if !
|
|
238
|
-
arreter|stop)
|
|
239
|
-
nettoyer|clean)
|
|
240
|
-
auto) case "${2:-}" in on)
|
|
241
|
-
exclude|exclure)
|
|
242
|
-
include|inclure)
|
|
243
|
-
|
|
244
|
-
|
|
234
|
+
''|boucle|loop) if ! guard_watcher; then exit 2; fi; auto_loop ;;
|
|
235
|
+
tour|one|un-tour) auto_pass ;;
|
|
236
|
+
demarrer|start|lancer) if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then echo "ports: Kubernetes workspace, ports go through devzone workspace ports"; exit 0; fi; if ! guard_watcher; then exit 2; fi; if kill -0 "$(cat "$LOCK/pid" 2>/dev/null)" 2>/dev/null; then echo "already running"; else DEVZONE_PORTS_AUTO_REAL=yes bash "$0" boucle >/dev/null 2>&1 & echo "started"; fi ;;
|
|
237
|
+
arreter|stop) stop_watcher; echo "stopped" ;;
|
|
238
|
+
nettoyer|clean) clean_auto_all ;;
|
|
239
|
+
auto) case "${2:-}" in on) write_key ports_auto on; echo "✔ automatic ports enabled" ;; off) write_key ports_auto off; stop_watcher; echo "✔ automatic ports disabled" ;; *) echo "devzone : port : auto on|off" >&2; exit 2 ;; esac ;;
|
|
240
|
+
exclude|exclure) auto_exclude "${2:-}" ;;
|
|
241
|
+
include|inclure) auto_include "${2:-}" ;;
|
|
242
|
+
list_auto) auto_list ;;
|
|
243
|
+
list_json_auto) auto_list_json ;;
|
|
245
244
|
-h|--help|aide) sed -n '2,8p' "$0" | sed 's/^# \{0,1\}//' ;;
|
|
246
|
-
*) echo "devzone : ports-auto :
|
|
245
|
+
*) echo "devzone : ports-auto : unknown command : ${1:-}" >&2; exit 2 ;;
|
|
247
246
|
esac
|
|
248
247
|
fi
|
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# JSON output of the port relays (#557)
|
|
3
|
-
# [{port,
|
|
2
|
+
# JSON output of the port relays (#557): the array
|
|
3
|
+
# [{port,active,application,auto}] read by the tools (devzone status --json).
|
|
4
|
+
# The keys and the application values are a contract.
|
|
4
5
|
# Sourced by ports.sh, which holds the functions used here.
|
|
5
6
|
|
|
6
|
-
# JSON list of the relays of the state
|
|
7
|
-
|
|
8
|
-
local ports port
|
|
9
|
-
ports="$(
|
|
7
|
+
# JSON list of the relays of the state: jq only
|
|
8
|
+
list_json() {
|
|
9
|
+
local ports port active app json='[]'
|
|
10
|
+
ports="$(sort_ports "$(read_ports)")"
|
|
10
11
|
if [ -z "$ports" ]; then
|
|
11
12
|
printf '[]\n'
|
|
12
13
|
return 0
|
|
13
14
|
fi
|
|
14
15
|
# shellcheck disable=SC2046 # list of ports separated by commas
|
|
15
16
|
for port in $(printf '%s' "$ports" | tr ',' ' '); do
|
|
16
|
-
if
|
|
17
|
-
|
|
17
|
+
if relay_active "$port"; then
|
|
18
|
+
active=true
|
|
18
19
|
else
|
|
19
|
-
|
|
20
|
+
active=false
|
|
20
21
|
fi
|
|
21
|
-
if
|
|
22
|
-
app="$
|
|
22
|
+
if app_responds "$port"; then
|
|
23
|
+
app="$JSON_APP_RESPONDS"
|
|
23
24
|
else
|
|
24
|
-
app="$
|
|
25
|
+
app="$JSON_APP_NONE"
|
|
25
26
|
fi
|
|
26
|
-
json="$(jq -c --argjson port "$port" --argjson
|
|
27
|
-
'. + [{port:$port,
|
|
27
|
+
json="$(jq -c --argjson port "$port" --argjson active "$active" --arg app "$app" \
|
|
28
|
+
'. + [{port:$port,active:$active,application:$app,auto:false}]' <<<"$json")"
|
|
28
29
|
done
|
|
29
|
-
auto_json="$(bash "$
|
|
30
|
+
auto_json="$(bash "$HERE/ports-auto.sh" list_json_auto 2>/dev/null || echo '[]')"
|
|
30
31
|
if [ -n "$auto_json" ] && [ "$auto_json" != "[]" ]; then
|
|
31
32
|
json="$(jq -s 'add' <<<"$json"$'\n'"$auto_json")"
|
|
32
33
|
fi
|