#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck disable=SC1091 source "$SCRIPT_DIR/common.sh" load_config ensure_command node ensure_command npm ensure_command python3 ensure_command setsid ensure_runtime_dir ensure_service_source "网易云音乐 API" "$NETEASE_DIR" ensure_service_source "QQ 音乐 API" "$QQ_DIR" ensure_qq_port_env_support ensure_qq_search_compat_route start_service() { local service_name="$1" local service_key="$2" local service_dir="$3" local host="$4" local port="$5" local pid_file local log_file pid_file="$(pid_file_for "$service_key")" log_file="$(log_file_for "$service_key")" if pid="$(active_pid_from_file "$pid_file" 2>/dev/null)"; then log "$service_name 已在运行 (PID $pid)" return 0 fi : > "$log_file" ( cd "$service_dir" exec setsid env HOST="$host" PORT="$port" npm run start ) >>"$log_file" 2>&1 & echo "$!" > "$pid_file" wait_for_url "$service_name" "$pid_file" "http://$host:$port" log "$service_name 已启动: http://$host:$port" } start_service "网易云音乐 API" "netease" "$NETEASE_DIR" "$NETEASE_HOST" "$NETEASE_PORT" start_service "QQ 音乐 API" "qq" "$QQ_DIR" "$QQ_HOST" "$QQ_PORT"