@coze-arch/cli 0.0.1-alpha.c49cb2 → 0.0.1-alpha.d5effa
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.
|
@@ -4,44 +4,25 @@ set -Eeuo pipefail
|
|
|
4
4
|
PORT=<%= port %>
|
|
5
5
|
COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
|
|
6
6
|
NODE_ENV=development
|
|
7
|
+
DEPLOY_RUN_PORT=<%= port %>
|
|
7
8
|
|
|
8
9
|
cd "${COZE_WORKSPACE_PATH}"
|
|
9
10
|
|
|
10
11
|
kill_port_if_listening() {
|
|
11
12
|
local pids
|
|
12
|
-
|
|
13
|
-
# Check if lsof is available (macOS/BSD) or ss (Linux)
|
|
14
|
-
if command -v lsof >/dev/null 2>&1; then
|
|
15
|
-
# macOS/BSD using lsof
|
|
16
|
-
pids=$(lsof -ti:${PORT} 2>/dev/null || true)
|
|
17
|
-
elif command -v ss >/dev/null 2>&1; then
|
|
18
|
-
# Linux using ss
|
|
19
|
-
pids=$(ss -H -lntp 2>/dev/null | awk -v port="${PORT}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | paste -sd' ' - || true)
|
|
20
|
-
else
|
|
21
|
-
echo "Warning: neither lsof nor ss found, cannot check port ${PORT}"
|
|
22
|
-
return
|
|
23
|
-
fi
|
|
24
|
-
|
|
13
|
+
pids=$(ss -H -lntp 2>/dev/null | awk -v port="${DEPLOY_RUN_PORT}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | paste -sd' ' - || true)
|
|
25
14
|
if [[ -z "${pids}" ]]; then
|
|
26
|
-
echo "Port ${
|
|
15
|
+
echo "Port ${DEPLOY_RUN_PORT} is free."
|
|
27
16
|
return
|
|
28
17
|
fi
|
|
29
|
-
|
|
30
|
-
echo "Port ${PORT} in use by PIDs: ${pids} (SIGKILL)"
|
|
18
|
+
echo "Port ${DEPLOY_RUN_PORT} in use by PIDs: ${pids} (SIGKILL)"
|
|
31
19
|
echo "${pids}" | xargs -I {} kill -9 {}
|
|
32
20
|
sleep 1
|
|
33
|
-
|
|
34
|
-
# Verify port is cleared
|
|
35
|
-
if command -v lsof >/dev/null 2>&1; then
|
|
36
|
-
pids=$(lsof -ti:${PORT} 2>/dev/null || true)
|
|
37
|
-
elif command -v ss >/dev/null 2>&1; then
|
|
38
|
-
pids=$(ss -H -lntp 2>/dev/null | awk -v port="${PORT}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | paste -sd' ' - || true)
|
|
39
|
-
fi
|
|
40
|
-
|
|
21
|
+
pids=$(ss -H -lntp 2>/dev/null | awk -v port="${DEPLOY_RUN_PORT}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | paste -sd' ' - || true)
|
|
41
22
|
if [[ -n "${pids}" ]]; then
|
|
42
|
-
echo "Warning: port ${
|
|
23
|
+
echo "Warning: port ${DEPLOY_RUN_PORT} still busy after SIGKILL, PIDs: ${pids}"
|
|
43
24
|
else
|
|
44
|
-
echo "Port ${
|
|
25
|
+
echo "Port ${DEPLOY_RUN_PORT} cleared."
|
|
45
26
|
fi
|
|
46
27
|
}
|
|
47
28
|
|
|
@@ -3,44 +3,25 @@ set -Eeuo pipefail
|
|
|
3
3
|
|
|
4
4
|
PORT=<%= port %>
|
|
5
5
|
COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
|
|
6
|
+
DEPLOY_RUN_PORT=<%= port %>
|
|
6
7
|
|
|
7
8
|
cd "${COZE_WORKSPACE_PATH}"
|
|
8
9
|
|
|
9
10
|
kill_port_if_listening() {
|
|
10
11
|
local pids
|
|
11
|
-
|
|
12
|
-
# Check if lsof is available (macOS/BSD) or ss (Linux)
|
|
13
|
-
if command -v lsof >/dev/null 2>&1; then
|
|
14
|
-
# macOS/BSD using lsof
|
|
15
|
-
pids=$(lsof -ti:${PORT} 2>/dev/null || true)
|
|
16
|
-
elif command -v ss >/dev/null 2>&1; then
|
|
17
|
-
# Linux using ss
|
|
18
|
-
pids=$(ss -H -lntp 2>/dev/null | awk -v port="${PORT}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | paste -sd' ' - || true)
|
|
19
|
-
else
|
|
20
|
-
echo "Warning: neither lsof nor ss found, cannot check port ${PORT}"
|
|
21
|
-
return
|
|
22
|
-
fi
|
|
23
|
-
|
|
12
|
+
pids=$(ss -H -lntp 2>/dev/null | awk -v port="${DEPLOY_RUN_PORT}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | paste -sd' ' - || true)
|
|
24
13
|
if [[ -z "${pids}" ]]; then
|
|
25
|
-
echo "Port ${
|
|
14
|
+
echo "Port ${DEPLOY_RUN_PORT} is free."
|
|
26
15
|
return
|
|
27
16
|
fi
|
|
28
|
-
|
|
29
|
-
echo "Port ${PORT} in use by PIDs: ${pids} (SIGKILL)"
|
|
17
|
+
echo "Port ${DEPLOY_RUN_PORT} in use by PIDs: ${pids} (SIGKILL)"
|
|
30
18
|
echo "${pids}" | xargs -I {} kill -9 {}
|
|
31
19
|
sleep 1
|
|
32
|
-
|
|
33
|
-
# Verify port is cleared
|
|
34
|
-
if command -v lsof >/dev/null 2>&1; then
|
|
35
|
-
pids=$(lsof -ti:${PORT} 2>/dev/null || true)
|
|
36
|
-
elif command -v ss >/dev/null 2>&1; then
|
|
37
|
-
pids=$(ss -H -lntp 2>/dev/null | awk -v port="${PORT}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | paste -sd' ' - || true)
|
|
38
|
-
fi
|
|
39
|
-
|
|
20
|
+
pids=$(ss -H -lntp 2>/dev/null | awk -v port="${DEPLOY_RUN_PORT}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | paste -sd' ' - || true)
|
|
40
21
|
if [[ -n "${pids}" ]]; then
|
|
41
|
-
echo "Warning: port ${
|
|
22
|
+
echo "Warning: port ${DEPLOY_RUN_PORT} still busy after SIGKILL, PIDs: ${pids}"
|
|
42
23
|
else
|
|
43
|
-
echo "Port ${
|
|
24
|
+
echo "Port ${DEPLOY_RUN_PORT} cleared."
|
|
44
25
|
fi
|
|
45
26
|
}
|
|
46
27
|
|
package/lib/cli.js
CHANGED