- 将项目品牌从nanobot重命名为Boardware Genius,更新所有相关文档、注释和日志输出 - 在web服务器中添加运行时环境变量同步功能,支持授权和后端身份配置 - 更新create-instance脚本以生成运行时环境文件 - 添加实例后端绑定功能到部署控制服务 - 修改入口脚本以加载运行时环境变量 - 更新前端和认证门户的相关描述文本
75 lines
1.8 KiB
Bash
Executable File
75 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
APP_PUBLIC_PORT="${APP_PUBLIC_PORT:-8080}"
|
|
APP_FRONTEND_PORT="${APP_FRONTEND_PORT:-3000}"
|
|
APP_BACKEND_PORT="${APP_BACKEND_PORT:-18080}"
|
|
NANOBOT_HOME="${NANOBOT_HOME:-/root/.nanobot}"
|
|
NANOBOT_AUTH_FILE="${NANOBOT_AUTH_FILE:-$NANOBOT_HOME/web_auth_users.json}"
|
|
NANOBOT_RUNTIME_ENV_FILE="${NANOBOT_RUNTIME_ENV_FILE:-$NANOBOT_HOME/runtime.env}"
|
|
|
|
log() {
|
|
printf '[app-instance] %s\n' "$*"
|
|
}
|
|
|
|
require_file() {
|
|
local path="$1"
|
|
local message="$2"
|
|
if [[ ! -f "$path" ]]; then
|
|
printf '[app-instance] %s: %s\n' "$message" "$path" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
cleanup() {
|
|
local status=$?
|
|
|
|
if [[ -n "${NGINX_PID:-}" ]]; then
|
|
kill "${NGINX_PID}" 2>/dev/null || true
|
|
fi
|
|
if [[ -n "${FRONTEND_PID:-}" ]]; then
|
|
kill "${FRONTEND_PID}" 2>/dev/null || true
|
|
fi
|
|
if [[ -n "${BACKEND_PID:-}" ]]; then
|
|
kill "${BACKEND_PID}" 2>/dev/null || true
|
|
fi
|
|
|
|
wait 2>/dev/null || true
|
|
exit "$status"
|
|
}
|
|
|
|
trap cleanup EXIT INT TERM
|
|
|
|
mkdir -p "$NANOBOT_HOME" "$NANOBOT_HOME/workspace"
|
|
|
|
if [[ -f "$NANOBOT_RUNTIME_ENV_FILE" ]]; then
|
|
set -a
|
|
. "$NANOBOT_RUNTIME_ENV_FILE"
|
|
set +a
|
|
fi
|
|
|
|
require_file "$NANOBOT_HOME/config.json" "Missing Boardware Genius config"
|
|
require_file "$NANOBOT_AUTH_FILE" "Missing web auth users file"
|
|
|
|
export NANOBOT_AUTH_FILE
|
|
export NANOBOT_RUNTIME_ENV_FILE
|
|
export PORT="$APP_FRONTEND_PORT"
|
|
export HOSTNAME="127.0.0.1"
|
|
|
|
log "starting backend on 127.0.0.1:${APP_BACKEND_PORT}"
|
|
nanobot web --host 127.0.0.1 --port "$APP_BACKEND_PORT" &
|
|
BACKEND_PID=$!
|
|
|
|
log "starting frontend on 127.0.0.1:${APP_FRONTEND_PORT}"
|
|
(
|
|
cd /opt/app/frontend
|
|
node server.js
|
|
) &
|
|
FRONTEND_PID=$!
|
|
|
|
log "starting nginx on 0.0.0.0:${APP_PUBLIC_PORT}"
|
|
nginx -c /opt/app/nginx.conf -g 'daemon off;' &
|
|
NGINX_PID=$!
|
|
|
|
wait -n "$BACKEND_PID" "$FRONTEND_PID" "$NGINX_PID"
|