第一次提交
This commit is contained in:
67
app-instance/entrypoint.sh
Executable file
67
app-instance/entrypoint.sh
Executable file
@ -0,0 +1,67 @@
|
||||
#!/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}"
|
||||
|
||||
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"
|
||||
|
||||
require_file "$NANOBOT_HOME/config.json" "Missing nanobot config"
|
||||
require_file "$NANOBOT_AUTH_FILE" "Missing web auth users file"
|
||||
|
||||
export NANOBOT_AUTH_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"
|
||||
|
||||
Reference in New Issue
Block a user