diff --git a/back/config/index.ts b/back/config/index.ts index 437b9856..1c426811 100644 --- a/back/config/index.ts +++ b/back/config/index.ts @@ -19,7 +19,12 @@ const lastVersionFile = `https://qn.whyour.cn/version.yaml`; const rootPath = process.env.QL_DIR as string; const envFound = dotenv.config({ path: path.join(rootPath, '.env') }); -const dataPath = path.join(rootPath, 'data/'); +let dataPath = path.join(rootPath, 'data/'); + +if (process.env.QL_DATA_DIR) { + dataPath = process.env.QL_DATA_DIR.replace(/\/$/g, ''); +} + const shellPath = path.join(rootPath, 'shell/'); const tmpPath = path.join(rootPath, '.tmp/'); const samplePath = path.join(rootPath, 'sample/'); diff --git a/back/loaders/initData.ts b/back/loaders/initData.ts index 8ed5a52c..5d19b4e1 100644 --- a/back/loaders/initData.ts +++ b/back/loaders/initData.ts @@ -125,7 +125,7 @@ export default async () => { if (doc.command.includes(`${config.rootPath}/log/`)) { await CrontabModel.update( { - command: `${config.rootPath}/data/log/${doc.command.replace( + command: `${config.dataPath}/log/${doc.command.replace( `${config.rootPath}/log/`, '', )}`, @@ -136,7 +136,7 @@ export default async () => { if (doc.command.includes(`${config.rootPath}/config/`)) { await CrontabModel.update( { - command: `${config.rootPath}/data/config/${doc.command.replace( + command: `${config.dataPath}/config/${doc.command.replace( `${config.rootPath}/config/`, '', )}`, @@ -147,7 +147,7 @@ export default async () => { if (doc.command.includes(`${config.rootPath}/db/`)) { await CrontabModel.update( { - command: `${config.rootPath}/data/db/${doc.command.replace( + command: `${config.dataPath}/db/${doc.command.replace( `${config.rootPath}/db/`, '', )}`, diff --git a/back/loaders/initFile.ts b/back/loaders/initFile.ts index 861395c6..7b694e7a 100644 --- a/back/loaders/initFile.ts +++ b/back/loaders/initFile.ts @@ -5,7 +5,12 @@ import Logger from './logger'; import { fileExist } from '../config/util'; const rootPath = process.env.QL_DIR as string; -const dataPath = path.join(rootPath, 'data/'); +let dataPath = path.join(rootPath, 'data/'); + +if (process.env.QL_DATA_DIR) { + dataPath = process.env.QL_DATA_DIR.replace(/\/$/g, ''); +} + const configPath = path.join(dataPath, 'config/'); const scriptPath = path.join(dataPath, 'scripts/'); const logPath = path.join(dataPath, 'log/'); diff --git a/shell/share.sh b/shell/share.sh index f038ddd8..44af0f73 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -4,6 +4,11 @@ dir_root=$QL_DIR dir_tmp=$dir_root/.tmp dir_data=$dir_root/data + +if [[ $QL_DATA_DIR ]]; then + dir_data="${QL_DATA_DIR%/}" +fi + dir_shell=$dir_root/shell dir_sample=$dir_root/sample dir_static=$dir_root/static @@ -371,25 +376,25 @@ patch_version() { if [[ -d "$dir_root/db" ]]; then echo -e "检测到旧的db目录,拷贝到data目录...\n" - cp -rf $dir_root/config $dir_root/data + cp -rf $dir_root/config $dir_data echo fi if [[ -d "$dir_root/scripts" ]]; then echo -e "检测到旧的scripts目录,拷贝到data目录...\n" - cp -rf $dir_root/scripts $dir_root/data + cp -rf $dir_root/scripts $dir_data echo fi if [[ -d "$dir_root/log" ]]; then echo -e "检测到旧的log目录,拷贝到data目录...\n" - cp -rf $dir_root/log $dir_root/data + cp -rf $dir_root/log $dir_data echo fi if [[ -d "$dir_root/config" ]]; then echo -e "检测到旧的config目录,拷贝到data目录...\n" - cp -rf $dir_root/config $dir_root/data + cp -rf $dir_root/config $dir_data echo fi } diff --git a/shell/update.sh b/shell/update.sh index 12fe3c02..3ffd7152 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -242,8 +242,8 @@ reload_qinglong() { fi if [[ "$reload_target" == 'data' ]]; then - rm -rf ${dir_root}/data/* - mv -f ${dir_tmp}/data/* ${dir_root}/data/ + rm -rf ${dir_data}/* + mv -f ${dir_tmp}/data/* ${dir_data}/ fi reload_pm2