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,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
# devzone-<app> (chart charts/devzone-<app>
|
|
5
|
-
#
|
|
2
|
+
# Install operations of the catalog (#414): sourced by catalog.sh.
|
|
3
|
+
# With the argocd module on, the installed application is an Argo CD Application
|
|
4
|
+
# devzone-<app> (chart charts/devzone-<app> of the devzone repository, #538) instead
|
|
5
|
+
# of the manifest of the direct helm path.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
WAIT_SECONDS="${DEVZONE_CATALOG_WAIT:-300}"
|
|
8
8
|
|
|
9
9
|
# shellcheck source=SCRIPTDIR/argocd/catalog-argocd.sh
|
|
10
10
|
# shellcheck disable=SC1091
|
|
@@ -13,119 +13,117 @@ ATTENTE="${DEVZONE_CATALOGUE_ATTENTE:-300}"
|
|
|
13
13
|
# shellcheck disable=SC1091
|
|
14
14
|
. "$ICI/chart-direct.sh"
|
|
15
15
|
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
local app="$1" ns="$2" argo="$3" fin=$((SECONDS + ATTENTE))
|
|
16
|
+
# Waits for the StatefulSet to be ready: a single rollout command on the manifest
|
|
17
|
+
# path, polled on the Argo CD path (the sync runs in the background)
|
|
18
|
+
app_wait() {
|
|
19
|
+
local app="$1" ns="$2" argo="$3" end=$((SECONDS + WAIT_SECONDS))
|
|
21
20
|
if [ "$argo" = 1 ]; then
|
|
22
|
-
while [ "$SECONDS" -lt "$
|
|
21
|
+
while [ "$SECONDS" -lt "$end" ]; do
|
|
23
22
|
kubectl --context devzone -n "$ns" rollout status "statefulset/$app" --timeout=10s >/dev/null 2>&1 && return 0
|
|
24
23
|
sleep 5
|
|
25
24
|
done
|
|
26
|
-
echo "devzone :
|
|
25
|
+
echo "devzone : catalog : $app not ready after ${WAIT_SECONDS}s" >&2
|
|
27
26
|
return 1
|
|
28
27
|
fi
|
|
29
28
|
if ! kubectl --context devzone -n "$ns" rollout status "statefulset/$app" \
|
|
30
|
-
--timeout="${
|
|
31
|
-
echo "devzone :
|
|
29
|
+
--timeout="${WAIT_SECONDS}s" >/dev/null; then
|
|
30
|
+
echo "devzone : catalog : $app not ready after ${WAIT_SECONDS}s" >&2
|
|
32
31
|
return 1
|
|
33
32
|
fi
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
#
|
|
37
|
-
# (workspace/.$app/admin-password, 600,
|
|
38
|
-
#
|
|
35
|
+
# Application secret: password generated once, local mirror
|
|
36
|
+
# (workspace/.$app/admin-password, 600, never shown). Re-run: a password already
|
|
37
|
+
# there (cluster secret or root.env) is kept, never regenerated.
|
|
39
38
|
app_secret() {
|
|
40
|
-
local app="$1" ns="$2"
|
|
41
|
-
|
|
42
|
-
mkdir -p "$(dirname "$
|
|
43
|
-
chmod 700 "$(dirname "$
|
|
39
|
+
local app="$1" ns="$2" password file
|
|
40
|
+
file="$RACINE/workspace/.$app/admin-password"
|
|
41
|
+
mkdir -p "$(dirname "$file")"
|
|
42
|
+
chmod 700 "$(dirname "$file")"
|
|
44
43
|
if kubectl --context devzone -n "$ns" get secret "$app-admin" >/dev/null 2>&1; then
|
|
45
|
-
|
|
44
|
+
password="$(kubectl --context devzone -n "$ns" get secret "$app-admin" \
|
|
46
45
|
-o jsonpath='{.data.password}' | tr -d '\n')"
|
|
47
|
-
(umask 077 && printf '%s' "$
|
|
46
|
+
(umask 077 && printf '%s' "$password" >"$file")
|
|
48
47
|
return 0
|
|
49
48
|
fi
|
|
50
|
-
|
|
51
|
-
if [ -z "$
|
|
52
|
-
if [ -z "$
|
|
53
|
-
(umask 077 && openssl rand -hex 24 | tr -d '\n' >"$
|
|
54
|
-
elif [ ! -s "$
|
|
55
|
-
(umask 077 && printf '%s' "$
|
|
49
|
+
password="$(sed -n 's/^\(MYSQL_\|\)PASSWORD=//p' "$RACINE/workspace/.$app/root.env" 2>/dev/null | tail -1 || true)"
|
|
50
|
+
if [ -z "$password" ] && [ -s "$file" ]; then password="$(cat "$file")"; fi
|
|
51
|
+
if [ -z "$password" ]; then
|
|
52
|
+
(umask 077 && openssl rand -hex 24 | tr -d '\n' >"$file")
|
|
53
|
+
elif [ ! -s "$file" ]; then
|
|
54
|
+
(umask 077 && printf '%s' "$password" >"$file")
|
|
56
55
|
fi
|
|
57
56
|
kubectl --context devzone -n "$ns" create secret generic "$app-admin" \
|
|
58
|
-
--from-file=password="$
|
|
57
|
+
--from-file=password="$file" >/dev/null
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
#
|
|
60
|
+
# Grouped view of the credentials: a failure never blocks the operation
|
|
62
61
|
regenerer_identifiants() {
|
|
63
62
|
password_regenerate ||
|
|
64
|
-
echo "devzone :
|
|
63
|
+
echo "devzone : catalog : grouped credentials not updated (devzone passwords)" >&2
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
#
|
|
68
|
-
#
|
|
69
|
-
# #538)
|
|
70
|
-
#
|
|
71
|
-
|
|
66
|
+
# Installs an application: devzone context set (#396), namespace created and
|
|
67
|
+
# isolated (#396), secret generated, then the Argo CD Application (argocd module
|
|
68
|
+
# on, #538) or the manifest, wait until ready, relay started to 127.0.0.1:<port>
|
|
69
|
+
# of the container; returns non-zero on failure
|
|
70
|
+
app_install() {
|
|
72
71
|
local app="$1" ns port image CTX extra="" argo=0
|
|
73
|
-
ns="$(
|
|
74
|
-
port="$(
|
|
75
|
-
image="$(
|
|
76
|
-
CTX="$(
|
|
77
|
-
[ -n "$CTX" ] || refuse "
|
|
78
|
-
if !
|
|
79
|
-
echo "devzone :
|
|
72
|
+
ns="$(app_namespace "$app")"
|
|
73
|
+
port="$(app_read "$app" port)"
|
|
74
|
+
image="$(app_read "$app" image)"
|
|
75
|
+
CTX="$(cluster_saved)"
|
|
76
|
+
[ -n "$CTX" ] || refuse "no cluster chosen: devzone enable $app"
|
|
77
|
+
if ! devzone_context_set "$CTX"; then
|
|
78
|
+
echo "devzone : catalog : cannot set the devzone context on $CTX" >&2
|
|
80
79
|
return 1
|
|
81
80
|
fi
|
|
82
|
-
echo "▶ Application $app
|
|
83
|
-
# Namespace
|
|
84
|
-
#
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
81
|
+
echo "▶ Application $app on cluster $CTX (namespace $ns)…"
|
|
82
|
+
# Namespace created and labelled by the administrator (#430), then the limited
|
|
83
|
+
# account allowed in the namespace
|
|
84
|
+
account_admin "$CTX" create namespace "$ns" --dry-run=client -o yaml |
|
|
85
|
+
account_admin "$CTX" apply -f - >/dev/null
|
|
86
|
+
account_admin "$CTX" label namespace "$ns" "$CLUSTER_LABEL" --overwrite >/dev/null
|
|
87
|
+
account_allow "$CTX" "$ns"
|
|
88
|
+
namespace_isolate "$ns" >/dev/null
|
|
90
89
|
app_secret "$app" "$ns"
|
|
91
90
|
local claim=donnees
|
|
92
91
|
if [ "$app" = mysql ]; then
|
|
93
92
|
# shellcheck source=SCRIPTDIR/mysql/volume.sh
|
|
94
93
|
# shellcheck disable=SC1091
|
|
95
|
-
. "$(
|
|
96
|
-
claim="$(
|
|
94
|
+
. "$(catalog_dir)/mysql/volume.sh"
|
|
95
|
+
claim="$(mysql_claim_choose "$ns")" || return 2
|
|
97
96
|
[ "$claim" = donnees ] || extra="claim=$claim"
|
|
98
97
|
fi
|
|
99
98
|
if catalogue_argocd_active "$app"; then
|
|
100
99
|
argo=1
|
|
101
|
-
echo "▶ Application $app
|
|
100
|
+
echo "▶ Application $app through Argo CD (chart charts/devzone-$app)…"
|
|
102
101
|
catalogue_argocd_apply "$app" "$ns" "$image" "$port" \
|
|
103
|
-
"$(
|
|
102
|
+
"$(app_read "$app" memoire)" "$(app_read "$app" taille)" "$extra" || return 1
|
|
104
103
|
else
|
|
105
|
-
#
|
|
104
|
+
# Direct helm: the chart charts/devzone-<app>, the one definition (#559)
|
|
106
105
|
chart_install "$app" "$ns" "image=$image" "port=$port" \
|
|
107
|
-
"memory=$(
|
|
106
|
+
"memory=$(app_read "$app" memoire)" "size=$(app_read "$app" taille)" "claim=$claim" || return 1
|
|
108
107
|
fi
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
echo "✔ $app
|
|
108
|
+
app_wait "$app" "$ns" "$argo" || return 1
|
|
109
|
+
relay_start "$app" "$CTX" "$ns" "svc/$app" "$port:$port"
|
|
110
|
+
echo "✔ $app ready: 127.0.0.1:$port in the container"
|
|
112
111
|
regenerer_identifiants
|
|
113
112
|
}
|
|
114
113
|
|
|
115
|
-
#
|
|
116
|
-
#
|
|
117
|
-
#
|
|
118
|
-
|
|
119
|
-
app_desinstaller() {
|
|
114
|
+
# Uninstalls an application: relay stopped, Argo CD Application removed (argocd
|
|
115
|
+
# module on, #538) or the manifest, failure marker forgotten. The volume (PVC) and
|
|
116
|
+
# the data stay (#441): deleting the data is confirmed apart (devzone mysql delete-data)
|
|
117
|
+
app_remove() {
|
|
120
118
|
local app="$1" ns claim pvc CTX
|
|
121
|
-
ns="$(
|
|
122
|
-
|
|
123
|
-
rm -f "$(
|
|
124
|
-
# RoleBinding
|
|
125
|
-
#
|
|
126
|
-
CTX="$(
|
|
119
|
+
ns="$(app_namespace "$app")"
|
|
120
|
+
relay_stop "$app"
|
|
121
|
+
rm -f "$(failure_file "$app")"
|
|
122
|
+
# RoleBinding removed by the administrator (#430): the namespace and the volume
|
|
123
|
+
# stay, the account authorization must not linger
|
|
124
|
+
CTX="$(cluster_saved)" || true
|
|
127
125
|
if [ -n "$CTX" ]; then
|
|
128
|
-
|
|
126
|
+
account_remove "$CTX" "$ns" >/dev/null 2>&1 || true
|
|
129
127
|
fi
|
|
130
128
|
claim="$(kubectl --context devzone -n "$ns" get statefulset "$app" \
|
|
131
129
|
-o jsonpath='{.spec.volumeClaimTemplates[0].metadata.name}' 2>/dev/null || true)"
|
|
@@ -133,79 +131,79 @@ app_desinstaller() {
|
|
|
133
131
|
catalogue_argocd_delete "$app" >/dev/null 2>&1 || true
|
|
134
132
|
kubectl --context devzone -n "$ns" delete "secret/$app-admin" >/dev/null 2>&1 || true
|
|
135
133
|
pvc="${claim:-donnees}-$app-0"
|
|
136
|
-
echo "✔ $app
|
|
134
|
+
echo "✔ $app removed: Application deleted; volume $pvc and databases kept: devzone $app volume"
|
|
137
135
|
regenerer_identifiants
|
|
138
136
|
return 0
|
|
139
137
|
fi
|
|
140
138
|
kubectl --context devzone -n "$ns" delete "statefulset/$app" "service/$app" \
|
|
141
139
|
"secret/$app-admin" >/dev/null 2>&1 || true
|
|
142
140
|
pvc="${claim:-donnees}-$app-0"
|
|
143
|
-
echo "✔ $app
|
|
141
|
+
echo "✔ $app removed from the cluster; volume $pvc and databases kept: devzone $app volume"
|
|
144
142
|
regenerer_identifiants
|
|
145
143
|
}
|
|
146
144
|
|
|
147
|
-
#
|
|
148
|
-
|
|
149
|
-
printf '%s\n' "$2" | tail -1 >"$(
|
|
145
|
+
# Failure marker of an attempt: last line of the message kept and shown
|
|
146
|
+
app_failure() {
|
|
147
|
+
printf '%s\n' "$2" | tail -1 >"$(failure_file "$1")"
|
|
150
148
|
printf '%s\n' "$2" >&2
|
|
151
149
|
}
|
|
152
150
|
|
|
153
|
-
#
|
|
154
|
-
# namespaces
|
|
155
|
-
|
|
156
|
-
local ctx ns
|
|
157
|
-
ctx="$(
|
|
151
|
+
# Warns about the mysql PVCs not mounted by the StatefulSet (#440). Reading the
|
|
152
|
+
# namespaces is reserved to the administrator (#430).
|
|
153
|
+
app_unused_mysql_volumes() {
|
|
154
|
+
local ctx ns mounted pvc list
|
|
155
|
+
ctx="$(cluster_saved)"
|
|
158
156
|
[ -n "$ctx" ] || return 0
|
|
159
|
-
ns="$(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
[ -n "$
|
|
163
|
-
|
|
157
|
+
ns="$(app_namespace mysql)"
|
|
158
|
+
account_admin "$ctx" get namespace "$ns" >/dev/null 2>&1 || return 0
|
|
159
|
+
mounted="$(kubectl --context devzone -n "$ns" get statefulset mysql -o jsonpath='{.spec.volumeClaimTemplates[0].metadata.name}' 2>/dev/null || true)"
|
|
160
|
+
[ -n "$mounted" ] || return 0
|
|
161
|
+
list="$(kubectl --context devzone -n "$ns" get pvc -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 2>/dev/null | grep -E '\-mysql-0$' || true)"
|
|
164
162
|
while IFS= read -r pvc; do
|
|
165
163
|
[ -n "$pvc" ] || continue
|
|
166
|
-
[ "$pvc" != "${
|
|
167
|
-
printf ' ⚠ volume %s
|
|
168
|
-
done <<<"$
|
|
164
|
+
[ "$pvc" != "${mounted}-mysql-0" ] || continue
|
|
165
|
+
printf ' ⚠ volume %s not used : devzone mysql volume\n' "$pvc"
|
|
166
|
+
done <<<"$list"
|
|
169
167
|
}
|
|
170
168
|
|
|
171
|
-
#
|
|
172
|
-
#
|
|
173
|
-
|
|
174
|
-
local app
|
|
169
|
+
# Closes the gap between wanted and actual: installs, removes, restarts the
|
|
170
|
+
# permanent relay; marks the first failure then moves on
|
|
171
|
+
catalog_apply() {
|
|
172
|
+
local app output code=0 port CTX ns
|
|
175
173
|
while IFS= read -r app; do
|
|
176
174
|
[ -n "$app" ] || continue
|
|
177
|
-
port="$(
|
|
178
|
-
if [ "$(
|
|
179
|
-
if !
|
|
180
|
-
code=1;
|
|
175
|
+
port="$(app_read "$app" port)"
|
|
176
|
+
if [ "$(wanted "$app")" != on ] && present "$app"; then
|
|
177
|
+
if ! output="$(app_remove "$app" 2>&1)"; then
|
|
178
|
+
code=1; app_failure "$app" "$output"
|
|
181
179
|
else
|
|
182
|
-
printf '%s\n' "$
|
|
180
|
+
printf '%s\n' "$output"
|
|
183
181
|
fi
|
|
184
|
-
elif [ "$(
|
|
185
|
-
if !
|
|
182
|
+
elif [ "$(wanted "$app")" = on ] && present "$app"; then
|
|
183
|
+
if ! app_ready "$app"; then
|
|
186
184
|
code=1
|
|
187
|
-
echo "devzone :
|
|
188
|
-
echo "
|
|
185
|
+
echo "devzone : catalog : $app installed but not ready: devzone apply" >&2
|
|
186
|
+
echo "not ready" >"$(failure_file "$app")"
|
|
189
187
|
else
|
|
190
|
-
rm -f "$(
|
|
188
|
+
rm -f "$(failure_file "$app")"
|
|
191
189
|
fi
|
|
192
|
-
#
|
|
193
|
-
CTX="$(
|
|
194
|
-
ns="$(
|
|
190
|
+
# Permanent relay: restarted if stopped
|
|
191
|
+
CTX="$(cluster_saved)" || true
|
|
192
|
+
ns="$(app_namespace "$app")"
|
|
195
193
|
if [ -n "$CTX" ]; then
|
|
196
|
-
if !
|
|
197
|
-
code=1;
|
|
194
|
+
if ! output="$(relay_start "$app" "$CTX" "$ns" "svc/$app" "$port:$port" 2>&1)"; then
|
|
195
|
+
code=1; app_failure "$app" "$output"
|
|
198
196
|
else
|
|
199
|
-
[ -n "$
|
|
197
|
+
[ -n "$output" ] && printf '%s\n' "$output"
|
|
200
198
|
fi
|
|
201
199
|
fi
|
|
202
|
-
elif [ "$(
|
|
203
|
-
if !
|
|
204
|
-
code=1;
|
|
200
|
+
elif [ "$(wanted "$app")" = on ]; then
|
|
201
|
+
if ! output="$(app_install "$app" 2>&1)"; then
|
|
202
|
+
code=1; app_failure "$app" "$output"
|
|
205
203
|
else
|
|
206
|
-
printf '%s\n' "$
|
|
204
|
+
printf '%s\n' "$output"
|
|
207
205
|
fi
|
|
208
206
|
fi
|
|
209
|
-
done <<<"$(
|
|
207
|
+
done <<<"$(catalog_apps)"
|
|
210
208
|
return "$code"
|
|
211
209
|
}
|
|
@@ -1,130 +1,130 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
#
|
|
2
|
+
# Catalog hot detection (#414): when .devzone.modules changes, catalog.sh apply
|
|
3
|
+
# runs. A single instance (lock, as #394).
|
|
4
4
|
# catalog-watcher.sh demarrer | arreter | tour
|
|
5
5
|
set -euo pipefail
|
|
6
6
|
|
|
7
7
|
ICI="$(cd "$(dirname "$0")" && pwd)"
|
|
8
|
-
RACINE="${
|
|
9
|
-
ETAT="${
|
|
8
|
+
RACINE="${DEVZONE_ROOT:-$(cd "$ICI/../.." && pwd)}"
|
|
9
|
+
ETAT="${DEVZONE_STATE:-$RACINE/.devzone.modules}"
|
|
10
10
|
# shellcheck source=SCRIPTDIR/state.sh
|
|
11
11
|
# shellcheck disable=SC1091
|
|
12
12
|
. "$(dirname "$ICI")/state.sh"
|
|
13
|
-
BASE="${
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
BASE="${DEVZONE_CATALOG_WATCHER_DIR:-$RACINE/.devzone.catalog-watcher}"
|
|
14
|
+
LOCK_DIR="$BASE/verrou"
|
|
15
|
+
LAST_FILE="$BASE/dernier"
|
|
16
16
|
|
|
17
|
-
refuse() { echo "devzone :
|
|
17
|
+
refuse() { echo "devzone : catalog-watcher : $*" >&2; exit 2; }
|
|
18
18
|
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
if [ "${
|
|
22
|
-
echo "devzone :
|
|
19
|
+
# Guard (#293): never under bats, only with DEVZONE_CATALOG_REAL=yes
|
|
20
|
+
guard_watcher() {
|
|
21
|
+
if [ "${DEVZONE_CATALOG_REAL:-}" != yes ]; then
|
|
22
|
+
echo "devzone : catalog-watcher : refused here (DEVZONE_CATALOG_REAL=yes)" >&2
|
|
23
23
|
return 2
|
|
24
24
|
fi
|
|
25
25
|
if [ -n "${BATS_TEST_TMPDIR:-}" ]; then
|
|
26
|
-
echo "devzone :
|
|
26
|
+
echo "devzone : catalog-watcher : refused under bats (tests)" >&2
|
|
27
27
|
return 2
|
|
28
28
|
fi
|
|
29
29
|
return 0
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
#
|
|
33
|
-
|
|
34
|
-
local
|
|
35
|
-
|
|
32
|
+
# Exclusive lock (mkdir) with the pid; a single watcher instance
|
|
33
|
+
lock_take() {
|
|
34
|
+
local start now age pid
|
|
35
|
+
start="$(date +%s)"
|
|
36
36
|
while true; do
|
|
37
|
-
if mkdir "$
|
|
37
|
+
if mkdir "$LOCK_DIR" 2>/dev/null; then echo "$$" >"$LOCK_DIR/pid"; return 0; fi
|
|
38
38
|
now="$(date +%s)"
|
|
39
|
-
age=""; [ -d "$
|
|
40
|
-
pid="$(cat "$
|
|
41
|
-
if [ -n "$age" ] && [ "$(( now - age ))" -gt 30 ]; then rm -rf "$
|
|
42
|
-
if [ -n "$pid" ] && ! kill -0 "$pid" 2>/dev/null; then rm -rf "$
|
|
43
|
-
[ "$(( now -
|
|
39
|
+
age=""; [ -d "$LOCK_DIR" ] && age="$(stat -c %Y "$LOCK_DIR" 2>/dev/null || stat -f %m "$LOCK_DIR" 2>/dev/null || true)"
|
|
40
|
+
pid="$(cat "$LOCK_DIR/pid" 2>/dev/null || true)"
|
|
41
|
+
if [ -n "$age" ] && [ "$(( now - age ))" -gt 30 ]; then rm -rf "$LOCK_DIR"; continue; fi
|
|
42
|
+
if [ -n "$pid" ] && ! kill -0 "$pid" 2>/dev/null; then rm -rf "$LOCK_DIR"; continue; fi
|
|
43
|
+
[ "$(( now - start ))" -ge 5 ] && return 1
|
|
44
44
|
sleep 1
|
|
45
45
|
done
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
#
|
|
49
|
-
|
|
48
|
+
# Marks the live lock (date and pid up to date)
|
|
49
|
+
lock_refresh() { touch "$LOCK_DIR" 2>/dev/null || true; echo "$$" >"$LOCK_DIR/pid" 2>/dev/null || true; }
|
|
50
50
|
|
|
51
|
-
#
|
|
52
|
-
|
|
53
|
-
local
|
|
51
|
+
# One tick: if .devzone.modules changed since the last tick, apply
|
|
52
|
+
tick() {
|
|
53
|
+
local now previous
|
|
54
54
|
[ -f "$ETAT" ] || return 0
|
|
55
|
-
#
|
|
56
|
-
#
|
|
55
|
+
# Restored or rebuilt state: the watcher does not follow a doubtful state,
|
|
56
|
+
# and never uninstalls until devzone apply has confirmed it
|
|
57
57
|
state_recovery_wait && return 0
|
|
58
58
|
state_recovery_pending && return 0
|
|
59
59
|
mkdir -p "$BASE"
|
|
60
|
-
|
|
61
|
-
[ -n "$
|
|
62
|
-
|
|
63
|
-
if [ "$
|
|
64
|
-
echo "$
|
|
65
|
-
echo "devzone :
|
|
60
|
+
now="$(stat -c %Y "$ETAT" 2>/dev/null || stat -f %m "$ETAT" 2>/dev/null || true)"
|
|
61
|
+
[ -n "$now" ] || return 0
|
|
62
|
+
previous="$(cat "$LAST_FILE" 2>/dev/null || true)"
|
|
63
|
+
if [ "$now" != "$previous" ]; then
|
|
64
|
+
echo "$now" >"$LAST_FILE"
|
|
65
|
+
echo "devzone : catalog-watcher : .devzone.modules changed, applying" >&2
|
|
66
66
|
bash "$ICI/../catalog.sh" apply
|
|
67
67
|
fi
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
#
|
|
71
|
-
|
|
70
|
+
# Loop: one tick every 5 s, lock refreshed on each tick
|
|
71
|
+
loop() {
|
|
72
72
|
mkdir -p "$BASE"
|
|
73
|
-
if !
|
|
74
|
-
trap 'rm -rf "$
|
|
73
|
+
if ! lock_take; then return 0; fi
|
|
74
|
+
trap 'rm -rf "$LOCK_DIR"' EXIT INT TERM
|
|
75
75
|
while true; do
|
|
76
|
-
[ -f "$ETAT" ] || { rm -rf "$
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
[ -f "$ETAT" ] || { rm -rf "$LOCK_DIR"; break; }
|
|
77
|
+
lock_refresh
|
|
78
|
+
tick || true
|
|
79
79
|
sleep 5
|
|
80
80
|
done
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
#
|
|
84
|
-
|
|
83
|
+
# Starts the detached loop (#435) and checks that its lock is alive
|
|
84
|
+
start_detached() {
|
|
85
85
|
local i pid stable=0 detache=()
|
|
86
86
|
mkdir -p "$BASE"
|
|
87
|
-
#
|
|
87
|
+
# Same detachment as relay_start: setsid when present, else nohup.
|
|
88
88
|
command -v setsid >/dev/null 2>&1 && detache=(setsid)
|
|
89
|
-
${detache[@]+"${detache[@]}"} nohup env
|
|
89
|
+
${detache[@]+"${detache[@]}"} nohup env DEVZONE_CATALOG_REAL=yes bash "$0" boucle >"$BASE/veilleur.log" 2>&1 &
|
|
90
90
|
i=0
|
|
91
91
|
while [ "$i" -lt 20 ]; do
|
|
92
|
-
pid="$(cat "$
|
|
92
|
+
pid="$(cat "$LOCK_DIR/pid" 2>/dev/null || true)"
|
|
93
93
|
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
|
|
94
94
|
stable=$((stable + 1))
|
|
95
|
-
[ "$stable" -ge 5 ] && { echo "
|
|
95
|
+
[ "$stable" -ge 5 ] && { echo "started"; return 0; }
|
|
96
96
|
else
|
|
97
97
|
stable=0
|
|
98
98
|
fi
|
|
99
99
|
sleep 0.1
|
|
100
100
|
i=$((i + 1))
|
|
101
101
|
done
|
|
102
|
-
echo "devzone :
|
|
102
|
+
echo "devzone : catalog-watcher : cannot start, see $BASE/veilleur.log" >&2
|
|
103
103
|
return 1
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
#
|
|
107
|
-
|
|
106
|
+
# Stops the watcher and removes the lock
|
|
107
|
+
stop_watcher() {
|
|
108
108
|
local pid
|
|
109
|
-
pid="$(cat "$
|
|
109
|
+
pid="$(cat "$LOCK_DIR/pid" 2>/dev/null || true)"
|
|
110
110
|
if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; fi
|
|
111
|
-
rm -rf "$
|
|
111
|
+
rm -rf "$LOCK_DIR"
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
case "${1:-}" in
|
|
115
|
-
boucle | loop) if !
|
|
115
|
+
boucle | loop) if ! guard_watcher; then exit 2; fi; loop ;;
|
|
116
116
|
demarrer | start | lancer)
|
|
117
|
-
if !
|
|
118
|
-
if [ -f "$
|
|
119
|
-
echo "
|
|
117
|
+
if ! guard_watcher; then exit 2; fi
|
|
118
|
+
if [ -f "$LOCK_DIR/pid" ] && kill -0 "$(cat "$LOCK_DIR/pid")" 2>/dev/null; then
|
|
119
|
+
echo "already running"
|
|
120
120
|
else
|
|
121
|
-
|
|
121
|
+
start_detached || exit 1
|
|
122
122
|
fi
|
|
123
123
|
;;
|
|
124
|
-
arreter | stop)
|
|
125
|
-
tour | un-tour)
|
|
124
|
+
arreter | stop) stop_watcher ; echo "stopped" ;;
|
|
125
|
+
tour | un-tour) tick ;;
|
|
126
126
|
*)
|
|
127
|
-
echo "devzone :
|
|
127
|
+
echo "devzone : catalog-watcher : demarrer | arreter | tour" >&2
|
|
128
128
|
exit 2
|
|
129
129
|
;;
|
|
130
130
|
esac
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Application MySQL du catalogue (#414) : MySQL local de test pour les projets
|
|
2
2
|
# du workspace, installé dans le cluster des services de devzone.
|
|
3
3
|
# Mémoire et taille du volume : 1 Gi et 5Gi par défaut, modifiables ici.
|
|
4
|
-
|
|
4
|
+
name=mysql
|
|
5
5
|
description=MySQL partagé, une base par projet
|
|
6
6
|
image=mysql:8.4
|
|
7
7
|
port=3306
|