fix: run.sh get pid bug

This commit is contained in:
zhayujie
2026-03-20 17:51:04 +08:00
parent 7d0e1568ac
commit 9febb071c6

11
run.sh
View File

@@ -590,14 +590,14 @@ show_usage() {
# Ensure PYTHON_CMD is set # Ensure PYTHON_CMD is set
ensure_python_cmd() { ensure_python_cmd() {
if [ -z "$PYTHON_CMD" ]; then if [ -z "$PYTHON_CMD" ]; then
detect_python_command 2>/dev/null || PYTHON_CMD="python3" detect_python_command > /dev/null 2>&1 || PYTHON_CMD="python3"
fi fi
} }
# Get service PID (empty string if not running) # Get service PID (empty string if not running)
get_pid() { get_pid() {
ensure_python_cmd ensure_python_cmd > /dev/null 2>&1
ps ax | grep -i app.py | grep "${BASE_DIR}" | grep "$PYTHON_CMD" | grep -v grep | awk '{print $1}' ps ax | grep -i app.py | grep "${BASE_DIR}" | grep "$PYTHON_CMD" | grep -v grep | awk '{print $1}' | grep -E '^[0-9]+$'
} }
# Check if service is running # Check if service is running
@@ -634,6 +634,11 @@ cmd_stop() {
fi fi
pid=$(get_pid) pid=$(get_pid)
if [ -z "$pid" ] || ! echo "$pid" | grep -qE '^[0-9]+$'; then
echo -e "${RED}❌ Failed to get valid PID (got: ${pid})${NC}"
return 1
fi
echo -e "${GREEN}Found running process (PID: ${pid})${NC}" echo -e "${GREEN}Found running process (PID: ${pid})${NC}"
kill ${pid} kill ${pid}