From 922cad03ea48fcf99bc7204c7955e1ecd60a4ad6 Mon Sep 17 00:00:00 2001 From: dahai80 <121743945@qq.com> Date: Fri, 7 Aug 2026 11:41:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(start.sh):=20=E5=90=8E=E5=8F=B0=20detac?= =?UTF-8?q?h=20=E5=90=AF=E5=8A=A8=EF=BC=8C=E9=81=BF=E5=85=8D=E8=A2=AB=20St?= =?UTF-8?q?udio=2030s=20=E8=B6=85=E6=97=B6=E8=BF=9E=E5=B8=A6=E7=BB=88?= =?UTF-8?q?=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit start.sh 原用 exec 前台启动 fusion-code,进程不退出。 Fusion-Studio UpstreamServiceManager.runStartSh 对 start.sh start 设 30s 超时强制 terminate,前台 exec 不返回 → 30s 后连同刚启动的服务一起被杀, Code 模块显示 Offline。 改为参考 fusion-projects/start.sh:nohup 后台 + PID 文件 + start|stop|status|restart 子命令。start 立即返回,服务 detach 存活;stop 按 PID 文件优雅停 + 强杀兜底。 Closes #54 Co-Authored-By: Claude Fable 5 --- start.sh | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 84 insertions(+), 9 deletions(-) diff --git a/start.sh b/start.sh index ec63e9f..f4aa21b 100755 --- a/start.sh +++ b/start.sh @@ -1,18 +1,93 @@ -#!/bin/bash +#!/usr/bin/env bash # start.sh — Fusion-Code API 服务启动脚本 # 供 Fusion-Studio UpstreamServiceManager 调用 -set -e +# 支持 start|stop|status 子命令;start 后台 detach,避免被 Studio 30s 超时连带终止 +set -euo pipefail -DIR="$(cd "$(dirname "$0")" && pwd)" +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$DIR" PORT="${FUSION_CODE_PORT:-11441}" AUTH="${FUSION_API_KEY:-}" +PID_FILE="$DIR/.fusion-code.pid" +LOG_DIR="$DIR/logs" +STDOUT_LOG="$LOG_DIR/stdout.log" +STDERR_LOG="$LOG_DIR/stderr.log" -if [ ! -f ./fusion-code ]; then - echo "[start.sh] Building fusion-code..." - bun run build -fi +mkdir -p "$LOG_DIR" -echo "[start.sh] Starting Fusion-Code API on port ${PORT}" -exec ./fusion-code --serve --port="${PORT}" --auth="${AUTH}" +is_running() { + [ -f "$PID_FILE" ] || return 1 + local pid + pid="$(cat "$PID_FILE" 2>/dev/null || true)" + [ -n "$pid" ] || return 1 + kill -0 "$pid" 2>/dev/null +} + +ensure_binary() { + if [ ! -f ./fusion-code ]; then + echo "[start.sh] Building fusion-code..." + bun run build + fi +} + +do_start() { + if is_running; then + echo "[start.sh] fusion-code already running (pid $(cat "$PID_FILE"))" + return 0 + fi + ensure_binary + echo "[start.sh] Starting Fusion-Code API on port ${PORT}" + nohup ./fusion-code --serve --port="${PORT}" --auth="${AUTH}" \ + >> "$STDOUT_LOG" 2>> "$STDERR_LOG" & + local pid=$! + echo "$pid" > "$PID_FILE" + sleep 1 + if is_running; then + echo "[start.sh] fusion-code started (pid $pid, port $PORT)" + else + echo "[start.sh] fusion-code failed to start, see $STDERR_LOG" >&2 + rm -f "$PID_FILE" + return 1 + fi +} + +do_stop() { + if ! is_running; then + echo "[start.sh] fusion-code not running" + rm -f "$PID_FILE" + return 0 + fi + local pid + pid="$(cat "$PID_FILE")" + echo "[start.sh] stopping fusion-code (pid $pid)" + kill "$pid" 2>/dev/null || true + for _ in 1 2 3 4 5; do + kill -0 "$pid" 2>/dev/null || break + sleep 1 + done + if kill -0 "$pid" 2>/dev/null; then + echo "[start.sh] force kill (pid $pid)" + kill -9 "$pid" 2>/dev/null || true + fi + rm -f "$PID_FILE" + echo "[start.sh] fusion-code stopped" +} + +do_status() { + if is_running; then + echo "running (pid $(cat "$PID_FILE"), port $PORT)" + return 0 + fi + echo "stopped" + return 1 +} + +ACTION="${1:-start}" +case "$ACTION" in + start) do_start ;; + stop) do_stop ;; + status) do_status ;; + restart) do_stop || true; do_start ;; + *) echo "usage: $0 {start|stop|status|restart}" >&2; exit 1 ;; +esac From 818b91fbbeb1e6f798fd60e61fdf96ff09d5b187 Mon Sep 17 00:00:00 2001 From: dahai80 <121743945@qq.com> Date: Fri, 7 Aug 2026 17:24:33 +0800 Subject: [PATCH 2/2] chore: gitignore start.sh runtime artifacts (.fusion-code.pid, logs/) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #55 的 start.sh 后台 detach 会生成 .fusion-code.pid 与 logs/ 目录, 未加入 .gitignore 会污染工作树 (当前 .fusion-code.pid 已出现在 untracked)。 补齐忽略规则。 Co-Authored-By: Claude --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index cadc19d..7f95bbc 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,10 @@ dist/ /cli-dev openclaw/ +# start.sh runtime artifacts (pid file + logs dir) +.fusion-code.pid +/logs/ + # Bun build artifacts .*.bun-build