#!/bin/bash set -eo pipefail # 导入环境变量 # source /home/pn/.env # 错误处理函数 handle_error() { echo "错误发生在第 $1 行" exit 1 } trap 'handle_error $LINENO' ERR # 超时处理函数 timeout_handler() { echo "操作超时" exit 1 } # 等待服务就绪的通用函数 wait_for_service() { local service=$1 local host=$2 local port=$3 local timeout=${4:-$WAIT_TIMEOUT} echo "等待 $service 就绪..." local end=$((SECONDS + timeout)) while [ $SECONDS -lt $end ]; do if nc -z "$host" "$port" >/dev/null 2>&1; then echo "$service 已就绪" return 0 fi echo "尝试连接 $service at $host:$port..." sleep 1 done echo "$service 启动超时" exit 1 } # 主流程 main() { current_time=$(date +"%Y-%m-%d %H:%M:%S") echo "Starting services at $current_time" echo "Starting deepseek-free-api... " exec node /home/pn/deepseek-free-api/dist/index.js } # 执行主流程 main "$@"