-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathlocal_entrypoint.sh
More file actions
executable file
·171 lines (150 loc) · 4.47 KB
/
Copy pathlocal_entrypoint.sh
File metadata and controls
executable file
·171 lines (150 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env bash
set -e
# Default settings
ENABLE_WEBSERVER=1
ENABLE_TASKEXECUTOR=1
CONSUMER_NO_BEG=0
CONSUMER_NO_END=0
WORKERS=1
HOST_ID=$(hostname)
# PID storage
PIDS=()
# Cleanup function
cleanup() {
echo "Stopping all services..."
# Kill all background processes started by this script
for pid in "${PIDS[@]}"; do
if kill -0 "$pid" 2>/dev/null; then
echo "Killing process $pid"
kill "$pid" 2>/dev/null || true
fi
done
# Kill any remaining ragflow_server processes
pkill -f "ragflow_server.py" 2>/dev/null || true
# Kill any remaining task_executor processes
pkill -f "task_executor.py" 2>/dev/null || true
echo "All services stopped."
exit 0
}
# Function to kill existing services
kill_existing_services() {
echo "Cleaning up existing services..."
# Kill existing ragflow_server processes
if pgrep -f "ragflow_server.py" > /dev/null; then
echo "Stopping existing ragflow_server processes..."
pkill -f "ragflow_server.py" || true
sleep 2
fi
# Kill existing task_executor processes
if pgrep -f "task_executor.py" > /dev/null; then
echo "Stopping existing task_executor processes..."
pkill -f "task_executor.py" || true
sleep 2
fi
echo "Cleanup completed."
}
# Set up signal handlers
trap cleanup SIGINT SIGTERM EXIT
# Parse arguments
for arg in "$@"; do
case $arg in
--disable-webserver)
ENABLE_WEBSERVER=0
shift
;;
--disable-taskexecutor)
ENABLE_TASKEXECUTOR=0
shift
;;
--consumer-no-beg=*)
CONSUMER_NO_BEG="${arg#*=}"
shift
;;
--consumer-no-end=*)
CONSUMER_NO_END="${arg#*=}"
shift
;;
--workers=*)
WORKERS="${arg#*=}"
shift
;;
--host-id=*)
HOST_ID="${arg#*=}"
shift
;;
--stop)
echo "Stopping all KnowFlow services..."
pkill -f "ragflow_server.py" 2>/dev/null || true
pkill -f "task_executor.py" 2>/dev/null || true
echo "All services stopped."
exit 0
;;
--help|-h)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --disable-webserver Disable ragflow webserver"
echo " --disable-taskexecutor Disable task executor"
echo " --consumer-no-beg=N Consumer ID begin (default: 0)"
echo " --consumer-no-end=N Consumer ID end (default: 0)"
echo " --workers=N Number of worker processes (default: 1)"
echo " --host-id=ID Host identifier (default: hostname)"
echo " --stop Stop all running services"
echo " --help, -h Show this help message"
echo ""
echo "To stop services: Ctrl+C or run: $0 --stop"
exit 0
;;
*)
echo "Unknown argument: $arg"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Function to run task executor
function task_exe() {
local consumer_id="$1"
local host_id="$2"
if command -v pkg-config &> /dev/null && pkg-config --exists jemalloc; then
JEMALLOC_PATH="$(pkg-config --variable=libdir jemalloc)/libjemalloc.so"
echo "Starting task executor ${host_id}_${consumer_id} with jemalloc..."
while true; do
LD_PRELOAD="$JEMALLOC_PATH" python rag/svr/task_executor.py "${consumer_id}"
done
else
echo "Starting task executor ${consumer_id} without jemalloc..."
while true; do
python rag/svr/task_executor.py "${consumer_id}"
done
fi
}
# Clean up existing services before starting
kill_existing_services
# Start components
if [[ "${ENABLE_WEBSERVER}" -eq 1 ]]; then
echo "Starting ragflow_server..."
python api/ragflow_server.py &
PIDS+=($!)
fi
if [[ "${ENABLE_TASKEXECUTOR}" -eq 1 ]]; then
if [[ "${CONSUMER_NO_END}" -gt "${CONSUMER_NO_BEG}" ]]; then
echo "Starting task executors on host '${HOST_ID}' for IDs in [${CONSUMER_NO_BEG}, ${CONSUMER_NO_END})..."
for (( i=CONSUMER_NO_BEG; i<CONSUMER_NO_END; i++ ))
do
task_exe "${i}" "${HOST_ID}" &
PIDS+=($!)
done
else
echo "Starting ${WORKERS} task executor(s) on host '${HOST_ID}'..."
for (( i=0; i<WORKERS; i++ ))
do
task_exe "${i}" "${HOST_ID}" &
PIDS+=($!)
done
fi
fi
# Show running services
echo "Services started with PIDs: ${PIDS[*]}"
echo "To stop all services: Ctrl+C or run: $0 --stop"
wait