From 9146c87cad4de1bd0a61b8c59f6376ecf5ff1733 Mon Sep 17 00:00:00 2001 From: loveuer Date: Mon, 12 May 2025 15:53:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=200.1.3=20=20=201.=20=E5=AE=8C=E5=96=84?= =?UTF-8?q?=20dockerfile=20=E5=92=8C=20entrypoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 5 +++-- Dockerfile | 5 ++++- deployment/entrypoint.sh | 35 +++++++++++++++++++++++++++++++++++ internal/controller/meta.go | 4 ++++ 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 deployment/entrypoint.sh diff --git a/.dockerignore b/.dockerignore index 76add87..397656d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ -node_modules -dist \ No newline at end of file +frontend/node_modules +dist +frontend/dist \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f347b52..8cf213c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,9 +27,12 @@ COPY --from=backend-builder /app/ushare /usr/local/bin/ushare # 配置 Nginx RUN rm /etc/nginx/conf.d/default.conf COPY deployment/nginx.conf /etc/nginx/conf.d +COPY deployment/entrypoint.sh /usr/local/bin/entrypoint.sh + +RUN chmod +x /usr/local/bin/entrypoint.sh # 开放端口 EXPOSE 80 # 启动服务 -CMD ["sh", "-c", "nginx -g 'daemon off;' & exec ushare"] \ No newline at end of file +ENTRYPOINT ["entrypoint.sh"] \ No newline at end of file diff --git a/deployment/entrypoint.sh b/deployment/entrypoint.sh new file mode 100644 index 0000000..3ea7c75 --- /dev/null +++ b/deployment/entrypoint.sh @@ -0,0 +1,35 @@ +#!/bin/sh +set -e + +# 启动后端服务(带参数后台运行) +echo "启动后端服务,参数: $@" +ushare "$@" & +BACKEND_PID=$! + +# 定义优雅关闭函数 +graceful_shutdown() { + echo "接收到终止信号,开始优雅关闭..." + + # 先关闭 Nginx + echo "关闭 Nginx..." + nginx -s quit 2>/dev/null || kill -TERM $NGINX_PID 2>/dev/null + + # 关闭后端服务 + echo "关闭后端服务 PID $BACKEND_PID..." + kill -TERM $BACKEND_PID 2>/dev/null + + # 等待进程终止 + wait $BACKEND_PID $NGINX_PID 2>/dev/null + exit 0 +} + +# 捕获系统信号 +trap 'graceful_shutdown' SIGTERM SIGINT + +# 启动 Nginx(前台运行) +echo "启动 Nginx..." +nginx -g "daemon off;" & +NGINX_PID=$! + +# 等待所有后台进程 +wait $BACKEND_PID $NGINX_PID \ No newline at end of file diff --git a/internal/controller/meta.go b/internal/controller/meta.go index 818061f..a19e6f6 100644 --- a/internal/controller/meta.go +++ b/internal/controller/meta.go @@ -104,6 +104,10 @@ func (m *meta) Start(ctx context.Context) { ticker := time.NewTicker(time.Minute) m.ctx = ctx + if err := os.MkdirAll(opt.Cfg.DataPath, 0644); err != nil { + log.Fatal("controller.MetaManager.Start: mkdir datapath failed, path = %s, err = %s", opt.Cfg.DataPath, err.Error()) + } + // 清理 2 分钟内没有继续上传的 part go func() { for {