Deep-sea commited on
Commit
ca40643
·
verified ·
1 Parent(s): 4cabd10

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +57 -16
Dockerfile CHANGED
@@ -109,7 +109,7 @@ if __name__ == "__main__":
109
  exit(1)
110
  EOF
111
 
112
- # 复制上传脚本,修改为使用北京时间并在 Gitea 达到重试上限时抛出错误
113
  COPY --chown=git:git <<'EOF' /uploadhf.py
114
  import os
115
  import time
@@ -223,46 +223,87 @@ def start_directory_monitoring(data_directory="/data", repo_id=None, hf_token=No
223
  return observer
224
 
225
  def start_gitea_server(port=7860):
226
- """启动 Gitea 服务器,包含自动重逻辑,达到重试上限时抛出错误"""
227
  def run_gitea():
228
  max_restart_attempts = 5
229
  restart_delay = 10 # 每次重启前的等待时间(秒)
 
230
  attempt = 0
231
 
 
 
 
 
 
 
 
 
 
232
  while attempt < max_restart_attempts:
233
  try:
 
234
  gitea_process = subprocess.Popen(
235
  ['gitea', 'web', '--port', str(port)],
236
  stdout=subprocess.PIPE,
237
  stderr=subprocess.PIPE,
238
  universal_newlines=True
239
  )
240
- logger.info(f"🚀 Gitea 服务器启动,端口: {port}")
241
  logger.info(f"📊 访问地址: http://localhost:{port}")
242
-
243
- while True:
244
- output = gitea_process.stdout.readline()
245
- if output == '' and gitea_process.poll() is not None:
 
246
  break
247
- if output:
248
- logger.info(f"Gitea: {output.strip()}")
249
-
 
 
 
250
  return_code = gitea_process.poll()
251
- if return_code != 0:
 
252
  error_output = gitea_process.stderr.read()
253
  logger.error(f"❌ Gitea 服务器异常退出,返回码: {return_code}")
254
- logger.error(f"错误信息: {error_output}")
 
255
  attempt += 1
256
  if attempt < max_restart_attempts:
257
  logger.info(f"将在 {restart_delay} 秒后尝试重启 Gitea (尝试 {attempt + 1}/{max_restart_attempts})")
258
  time.sleep(restart_delay)
259
  else:
260
- error_msg = f"❌ 达到最大重次数 ({max_restart_attempts}),Gitea 启动失败"
261
  logger.error(error_msg)
262
  raise RuntimeError(error_msg)
263
  else:
264
- logger.info("✅ Gitea 服务器正常退")
265
- break
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
 
267
  except FileNotFoundError:
268
  error_msg = "❌ 未找到 gitea 命令,请确保 Gitea 已正确安装"
@@ -317,7 +358,7 @@ async def main():
317
 
318
  logger.info("✅ 所有服务已启动完成!")
319
  logger.info("📁 目录监控: /data → Hugging Face Hub")
320
- logger.info("🌐 Gitea 服务: http://localhost:7860")
321
  logger.info("🛑 按 Ctrl+C 停止所有服务")
322
 
323
  try:
 
109
  exit(1)
110
  EOF
111
 
112
+ # 复制上传脚本,增强 Gitea 错误日志并在重试上限时抛出错误
113
  COPY --chown=git:git <<'EOF' /uploadhf.py
114
  import os
115
  import time
 
223
  return observer
224
 
225
  def start_gitea_server(port=7860):
226
+ """启动 Gitea 服务器,包含自动重逻辑和超时机制,达到重试上限时抛出错误"""
227
  def run_gitea():
228
  max_restart_attempts = 5
229
  restart_delay = 10 # 每次重启前的等待时间(秒)
230
+ startup_timeout = 30 # 启动超时时间(秒)
231
  attempt = 0
232
 
233
+ # 检查 /data 目录权限和数据库状态
234
+ logger.info("检查 /data 目录权限和 Gitea 数据库状态")
235
+ os.system("ls -la /data 2>/dev/null")
236
+ os.system("ls -la /data/gitea 2>/dev/null || echo '/data/gitea 不存在'")
237
+ if os.path.exists("/data/gitea/gitea.db"):
238
+ logger.info("Gitea 数据库文件存在: /data/gitea/gitea.db")
239
+ else:
240
+ logger.warning("Gitea 数据库文件不存在: /data/gitea/gitea.db")
241
+
242
  while attempt < max_restart_attempts:
243
  try:
244
+ # 启动 Gitea 进程
245
  gitea_process = subprocess.Popen(
246
  ['gitea', 'web', '--port', str(port)],
247
  stdout=subprocess.PIPE,
248
  stderr=subprocess.PIPE,
249
  universal_newlines=True
250
  )
251
+ logger.info(f"🚀 Gitea 服务器启动尝试 {attempt + 1}/{max_restart_attempts},端口: {port}")
252
  logger.info(f"📊 访问地址: http://localhost:{port}")
253
+
254
+ # 等待 Gitea 启动(超时机制)
255
+ start_time = time.time()
256
+ while time.time() - start_time < startup_timeout:
257
+ if gitea_process.poll() is not None:
258
  break
259
+ line = gitea_process.stderr.readline()
260
+ if line:
261
+ logger.info(f"Gitea stderr: {line.strip()}")
262
+ time.sleep(0.1)
263
+
264
+ # 检查进程状态
265
  return_code = gitea_process.poll()
266
+ if return_code is not None:
267
+ # 进程已退出
268
  error_output = gitea_process.stderr.read()
269
  logger.error(f"❌ Gitea 服务器异常退出,返回码: {return_code}")
270
+ if error_output:
271
+ logger.error(f"错误信息: {error_output.strip()}")
272
  attempt += 1
273
  if attempt < max_restart_attempts:
274
  logger.info(f"将在 {restart_delay} 秒后尝试重启 Gitea (尝试 {attempt + 1}/{max_restart_attempts})")
275
  time.sleep(restart_delay)
276
  else:
277
+ error_msg = f"❌ 达到最大重次数 ({max_restart_attempts}),Gitea 启动失败"
278
  logger.error(error_msg)
279
  raise RuntimeError(error_msg)
280
  else:
281
+ # 进程仍在运行,开始读取输
282
+ logger.info("✅ Gitea 服务器启动成功,开始监控输出")
283
+ while True:
284
+ output = gitea_process.stdout.readline()
285
+ if output == '' and gitea_process.poll() is not None:
286
+ break
287
+ if output:
288
+ logger.info(f"Gitea: {output.strip()}")
289
+
290
+ return_code = gitea_process.poll()
291
+ if return_code != 0:
292
+ error_output = gitea_process.stderr.read()
293
+ logger.error(f"❌ Gitea 服务器后期异常退出,返回码: {return_code}")
294
+ if error_output:
295
+ logger.error(f"错误信息: {error_output.strip()}")
296
+ attempt += 1
297
+ if attempt < max_restart_attempts:
298
+ logger.info(f"将在 {restart_delay} 秒后尝试重启 Gitea (尝试 {attempt + 1}/{max_restart_attempts})")
299
+ time.sleep(restart_delay)
300
+ else:
301
+ error_msg = f"❌ 达到最大重试次数 ({max_restart_attempts}),Gitea 启动失败"
302
+ logger.error(error_msg)
303
+ raise RuntimeError(error_msg)
304
+ else:
305
+ logger.info("✅ Gitea 服务器正常退出")
306
+ break
307
 
308
  except FileNotFoundError:
309
  error_msg = "❌ 未找到 gitea 命令,请确保 Gitea 已正确安装"
 
358
 
359
  logger.info("✅ 所有服务已启动完成!")
360
  logger.info("📁 目录监控: /data → Hugging Face Hub")
361
+ logger.info(f"🌐 Gitea 服务: http://localhost:{CONFIG['gitea_port']}")
362
  logger.info("🛑 按 Ctrl+C 停止所有服务")
363
 
364
  try: