orztv commited on
Commit ·
f4cb592
1
Parent(s): 09b474c
update
Browse files- services.json +2 -2
- start.sh +7 -2
services.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
| 12 |
},
|
| 13 |
{
|
| 14 |
"name": "node-service",
|
| 15 |
-
"command": "npx serve -
|
| 16 |
"port": 8001,
|
| 17 |
"path_prefix": "/node",
|
| 18 |
"health_check_path": "/",
|
|
@@ -23,7 +23,7 @@
|
|
| 23 |
},
|
| 24 |
{
|
| 25 |
"name": "n8n-service",
|
| 26 |
-
"command": "n8n start
|
| 27 |
"port": 5678,
|
| 28 |
"path_prefix": "/",
|
| 29 |
"health_check_path": "/healthz",
|
|
|
|
| 12 |
},
|
| 13 |
{
|
| 14 |
"name": "node-service",
|
| 15 |
+
"command": "npx serve -l $PORT",
|
| 16 |
"port": 8001,
|
| 17 |
"path_prefix": "/node",
|
| 18 |
"health_check_path": "/",
|
|
|
|
| 23 |
},
|
| 24 |
{
|
| 25 |
"name": "n8n-service",
|
| 26 |
+
"command": "n8n start",
|
| 27 |
"port": 5678,
|
| 28 |
"path_prefix": "/",
|
| 29 |
"health_check_path": "/healthz",
|
start.sh
CHANGED
|
@@ -35,7 +35,11 @@ echo "$services" | while read -r service; do
|
|
| 35 |
log "ERROR: Directory $working_dir does not exist"
|
| 36 |
exit 1
|
| 37 |
fi
|
| 38 |
-
(cd $working_dir &&
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
done
|
| 40 |
|
| 41 |
# 等待服务启动
|
|
@@ -46,7 +50,7 @@ check_health() {
|
|
| 46 |
local port=$1
|
| 47 |
local service=$2
|
| 48 |
local health_check_path=$3
|
| 49 |
-
for i in {1..
|
| 50 |
if curl -s "http://localhost:$port$health_check_path" > /dev/null; then
|
| 51 |
log "$service is up"
|
| 52 |
return 0
|
|
@@ -65,6 +69,7 @@ echo "$services" | while read -r service; do
|
|
| 65 |
|
| 66 |
if ! check_health $port "$name" "$health_check_path"; then
|
| 67 |
log "ERROR: 健康检查失败,退出程序"
|
|
|
|
| 68 |
exit 1
|
| 69 |
fi
|
| 70 |
done
|
|
|
|
| 35 |
log "ERROR: Directory $working_dir does not exist"
|
| 36 |
exit 1
|
| 37 |
fi
|
| 38 |
+
(cd $working_dir && PORT=$port eval "$command") &
|
| 39 |
+
|
| 40 |
+
# 记录进程ID
|
| 41 |
+
pids+=($!)
|
| 42 |
+
log "$name started with PID ${pids[-1]}"
|
| 43 |
done
|
| 44 |
|
| 45 |
# 等待服务启动
|
|
|
|
| 50 |
local port=$1
|
| 51 |
local service=$2
|
| 52 |
local health_check_path=$3
|
| 53 |
+
for i in {1..30}; do
|
| 54 |
if curl -s "http://localhost:$port$health_check_path" > /dev/null; then
|
| 55 |
log "$service is up"
|
| 56 |
return 0
|
|
|
|
| 69 |
|
| 70 |
if ! check_health $port "$name" "$health_check_path"; then
|
| 71 |
log "ERROR: 健康检查失败,退出程序"
|
| 72 |
+
kill ${pids[@]} 2>/dev/null
|
| 73 |
exit 1
|
| 74 |
fi
|
| 75 |
done
|