fix: Update pm2-manager with updated ecosystem

Now prefers Ctrl-managed configs when no explicit ecosystem file is passed.
Still supports explicit repo-local or absolute config paths.
This commit is contained in:
2026-06-22 17:01:29 +00:00
parent ce97bfa3ea
commit 0239f49aaa
2 changed files with 115 additions and 12 deletions
+51 -9
View File
@@ -2,10 +2,13 @@
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
CTRL_DATA_DIR="${CTRL_DATA_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/ctrl}"
CTRL_ECOSYSTEM_DIR="${CTRL_ECOSYSTEM_DIR:-$CTRL_DATA_DIR/ecosystems}"
declare -a APP_NAMES=()
declare -a APP_DIRS=()
declare -a APP_ECOSYSTEMS=()
declare -a APP_SOURCES=()
trim() {
local s="$1"
@@ -25,18 +28,49 @@ extract_app_name() {
printf "%s" "$name"
}
extract_app_cwd() {
local ecosystem_file="$1"
local cwd
cwd="$(grep -E 'cwd:[[:space:]]*"[^"]+"' "$ecosystem_file" | head -n1 | sed -E 's/.*cwd:[[:space:]]*"([^"]+)".*/\1/' || true)"
cwd="$(trim "$cwd")"
if [ -z "$cwd" ]; then
cwd="$(dirname "$ecosystem_file")"
fi
printf "%s" "$cwd"
}
add_ecosystem() {
local file="$1"
local source="$2"
local app_name project_dir
app_name="$(extract_app_name "$file")"
project_dir="$(extract_app_cwd "$file")"
APP_NAMES+=("$app_name")
APP_DIRS+=("$project_dir")
APP_ECOSYSTEMS+=("$file")
APP_SOURCES+=("$source")
}
discover_ecosystems() {
local file app_name project_dir
local file
if [ -d "$CTRL_ECOSYSTEM_DIR" ]; then
while IFS= read -r file; do
add_ecosystem "$file" "ctrl"
done < <(
find "$CTRL_ECOSYSTEM_DIR" -maxdepth 1 -type f -name "*.config.cjs" | sort
)
fi
while IFS= read -r file; do
project_dir="$(dirname "$file")"
app_name="$(extract_app_name "$file")"
APP_NAMES+=("$app_name")
APP_DIRS+=("$project_dir")
APP_ECOSYSTEMS+=("$file")
add_ecosystem "$file" "repo"
done < <(
find "$ROOT_DIR" -mindepth 2 -maxdepth 2 -type f \
find "$ROOT_DIR" -maxdepth 4 \
\( -path "$ROOT_DIR/gitea" -o -path "*/node_modules" -o -path "*/.next" -o -path "*/.git" \) -prune -o \
-type f \
\( -name "ecosystem.config.cjs" -o -name "ecosystem.cron.config.js" \) \
-print \
| sort
)
}
@@ -50,8 +84,13 @@ print_services() {
echo "Discovered services:"
for i in "${!APP_NAMES[@]}"; do
rel="${APP_ECOSYSTEMS[$i]#"$ROOT_DIR/"}"
printf " %2d) %-18s %s\n" "$((i + 1))" "${APP_NAMES[$i]}" "$rel"
if [[ "${APP_ECOSYSTEMS[$i]}" == "$ROOT_DIR/"* ]]; then
rel="${APP_ECOSYSTEMS[$i]#"$ROOT_DIR/"}"
else
rel="${APP_ECOSYSTEMS[$i]}"
fi
printf " %2d) %-18s %-4s %s\n" "$((i + 1))" "${APP_NAMES[$i]}" "${APP_SOURCES[$i]}" "$rel"
printf " cwd: %s\n" "${APP_DIRS[$i]}"
done
}
@@ -144,6 +183,9 @@ Actions:
Service can be:
- numeric index from "list"
- app name (e.g. zap, zap-cleanup, caddy-manager, api)
Ctrl-managed configs are discovered from:
${CTRL_ECOSYSTEM_DIR}
EOF
}