diff --git a/docker/sync/Dockerfile b/docker/sync/Dockerfile index 2bcfaa4..1725ba5 100644 --- a/docker/sync/Dockerfile +++ b/docker/sync/Dockerfile @@ -45,6 +45,7 @@ COPY ./out/binary_files/sync_drive /home/app/config/sync_drive HEALTHCHECK --start-period=5s --interval=10s --timeout=5s --retries=3 CMD /bin/sh /home/app/health_check.sh # 环境变量 +ENV ALIYUNPAN_DOCKER=1 ENV ALIYUNPAN_CONFIG_DIR=/home/app/config ENV ALIYUNPAN_REFRESH_TOKEN="" diff --git a/docker/webdav/Dockerfile b/docker/webdav/Dockerfile index 77c8e98..1b81ec9 100644 --- a/docker/webdav/Dockerfile +++ b/docker/webdav/Dockerfile @@ -44,6 +44,7 @@ HEALTHCHECK --start-period=5s --interval=10s --timeout=5s --retries=3 CMD /bin/s EXPOSE 23077 # 环境变量 +ENV ALIYUNPAN_DOCKER=1 ENV ALIYUNPAN_CONFIG_DIR=/home/app/config ENV ALIYUNPAN_AUTH_USER=admin ENV ALIYUNPAN_AUTH_PASSWORD=admin diff --git a/internal/command/sync.go b/internal/command/sync.go index a919eda..c7bf72b 100644 --- a/internal/command/sync.go +++ b/internal/command/sync.go @@ -260,11 +260,23 @@ func RunSync(defaultTask *syncdrive.SyncTask, fileDownloadParallel, fileUploadPa fmt.Println("启动任务失败:", e) return } - c := "" - fmt.Print("本命令不会退出,如需要结束同步备份进程请输入y,然后按Enter键进行停止:") - for strings.ToLower(c) != "y" { - fmt.Scan(&c) + + _, ok := os.LookupEnv("ALIYUNPAN_DOCKER") + if ok { + // in docker container + // 使用休眠以节省CPU资源 + for { + time.Sleep(60 * time.Second) + } + } else { + // in cmd mode + c := "" + fmt.Print("本命令不会退出,如需要结束同步备份进程请输入y,然后按Enter键进行停止:") + for strings.ToLower(c) != "y" { + fmt.Scan(&c) + } } + fmt.Println("正在停止同步备份任务,请稍等...") syncMgr.Stop() }