MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / start_service

Function start_service

tests/ce/deploy/deploy.py:233–304  ·  view source on GitHub ↗

启动大模型推理服务

()

Source from the content-addressed store, hash-verified

231
232@app.route("/start", methods=["POST"])
233def start_service():
234 """启动大模型推理服务"""
235 # 检查服务是否已在运行
236 if is_server_running()[0]:
237 return Response(
238 json.dumps({"status": "error", "message": "服务已启动,无需start"}, ensure_ascii=False),
239 status=400,
240 content_type="application/json",
241 )
242
243 try:
244 base_config = DEFAULT_PARAMS
245
246 override_config = request.get_json() or {}
247 print("override_config", override_config)
248
249 final_config = merge_configs(base_config, override_config)
250
251 global FD_API_PORT
252 global FD_ENGINE_QUEUE_PORT
253 global FD_METRICS_PORT
254 FD_API_PORT = final_config["--port"]
255 FD_ENGINE_QUEUE_PORT = final_config["--engine-worker-queue-port"]
256 FD_METRICS_PORT = final_config["--metrics-port"]
257
258 # 构建命令
259 cmd = build_command(final_config)
260 except Exception as e:
261 error_msg = f"Failed to start service: {e}, {str(traceback.format_exc())}"
262 print(error_msg)
263 return Response(
264 json.dumps({"status": "error", "message": error_msg}, ensure_ascii=False),
265 status=500,
266 content_type="application/json",
267 )
268
269 print("cmd", cmd)
270
271 try:
272 # 设置环境变量并启动进程
273 env = os.environ.copy()
274
275 with open(LOG_FILE, "w") as log:
276 process = subprocess.Popen(cmd, stdout=log, stderr=log, env=env, start_new_session=True)
277
278 # 保存进程ID,port到yaml文件
279 with open(PID_FILE, "w") as f:
280 yaml.dump({"PID": process.pid, "PORT": final_config["--port"]}, f)
281
282 json_data = {
283 "status": "success",
284 "message": "服务启动命令已执行",
285 "pid": process.pid,
286 "config": final_config,
287 "log_file": LOG_FILE,
288 "cmd": cmd,
289 "port_info": {
290 "api_port": FD_API_PORT,

Callers

nothing calls this directly

Calls 6

is_server_runningFunction · 0.85
printFunction · 0.85
merge_configsFunction · 0.85
build_commandFunction · 0.85
dumpMethod · 0.80
copyMethod · 0.45

Tested by

no test coverage detected