重构删除日志命令

This commit is contained in:
whyour 2021-04-30 22:09:54 +08:00
parent bf7324fa9c
commit 54020ca0dd
6 changed files with 20 additions and 67 deletions

View File

@ -30,12 +30,6 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
&& git clone -b ${QL_BRANCH} ${QL_URL} ${QL_DIR} \ && git clone -b ${QL_BRANCH} ${QL_URL} ${QL_DIR} \
&& cd ${QL_DIR} \ && cd ${QL_DIR} \
&& cp -f .env.example .env \ && cp -f .env.example .env \
&& ln -sf ${QL_DIR}/shell/task.sh /usr/local/bin/task \
&& ln -sf ${QL_DIR}/shell/update.sh /usr/local/bin/update \
&& ln -sf ${QL_DIR}/shell/rmlog.sh /usr/local/bin/rmlog \
&& ln -sf ${QL_DIR}/shell/notify.sh /usr/local/bin/notify \
&& ln -sf ${QL_DIR}/shell/rebuild.sh /usr/local/bin/rebuild \
&& ln -sf ${QL_DIR}/docker/docker-entrypoint.sh /usr/local/bin/entrypoint \
&& chmod 777 ${QL_DIR}/shell/*.sh \ && chmod 777 ${QL_DIR}/shell/*.sh \
&& chmod 777 ${QL_DIR}/docker/*.sh \ && chmod 777 ${QL_DIR}/docker/*.sh \
&& npm install -g pm2 \ && npm install -g pm2 \

View File

@ -1,11 +1,16 @@
#!/bin/bash #!/bin/bash
set -e set -e
echo -e "======================1. 更新源代码========================\n" echo -e "======================1. 初始化命令========================\n"
update ql . ${QL_DIR}/shell/share.sh
link_shell
echo echo
echo -e "======================2. 检测配置文件========================\n" echo -e "======================2. 更新源代码========================\n"
ql update
echo
echo -e "======================3. 检测配置文件========================\n"
[ ! -d ${QL_DIR}/config ] && mkdir -p ${QL_DIR}/config [ ! -d ${QL_DIR}/config ] && mkdir -p ${QL_DIR}/config
[ ! -d ${QL_DIR}/log ] && mkdir -p ${QL_DIR}/log [ ! -d ${QL_DIR}/log ] && mkdir -p ${QL_DIR}/log
[ ! -d ${QL_DIR}/db ] && mkdir -p ${QL_DIR}/db [ ! -d ${QL_DIR}/db ] && mkdir -p ${QL_DIR}/db
@ -37,11 +42,11 @@ fi
cp -fv ${QL_DIR}/docker/front.conf /etc/nginx/conf.d/front.conf cp -fv ${QL_DIR}/docker/front.conf /etc/nginx/conf.d/front.conf
echo -e "======================3. 启动nginx========================\n" echo -e "======================4. 启动nginx========================\n"
nginx -c /etc/nginx/nginx.conf nginx -c /etc/nginx/nginx.conf
echo echo
echo -e "======================4. 启动控制面板========================\n" echo -e "======================5. 启动控制面板========================\n"
pm2 start ${QL_DIR}/build/app.js -n panel pm2 start ${QL_DIR}/build/app.js -n panel
echo -e "控制面板启动成功...\n" echo -e "控制面板启动成功...\n"

View File

@ -32,11 +32,6 @@ AutoDelCron="true"
## 在运行 update 命令时,是否自动增加新的本地定时任务 ## 在运行 update 命令时,是否自动增加新的本地定时任务
AutoAddCron="true" AutoAddCron="true"
## 运行 rmlog 命令时删除多久以前的日志,仅能输入正整数
RmLogDaysAgo="7"
## 在运行 task 命令时,随机延迟启动任务的最大延迟时间 ## 在运行 task 命令时,随机延迟启动任务的最大延迟时间
## 如果任务不是必须准点运行的任务,那么给它增加一个随机延迟,由你定义最大延迟时间,单位为秒,如 RandomDelay="300" ,表示任务将在 1-300 秒内随机延迟一个秒数,然后再运行 ## 如果任务不是必须准点运行的任务,那么给它增加一个随机延迟,由你定义最大延迟时间,单位为秒,如 RandomDelay="300" ,表示任务将在 1-300 秒内随机延迟一个秒数,然后再运行
## 在crontab.list中在每小时第0-2分、第30-31分、第59分这几个时间内启动的任务均算作必须准点运行的任务在启动这些任务时即使你定义了RandomDelay也将准点运行不启用随机延迟 ## 在crontab.list中在每小时第0-2分、第30-31分、第59分这几个时间内启动的任务均算作必须准点运行的任务在启动这些任务时即使你定义了RandomDelay也将准点运行不启用随机延迟
@ -47,42 +42,3 @@ RandomDelay="300"
## 如果你自己会写shell脚本并且希望在每次运行 update 命令时,额外运行你的 shell 脚本,请赋值为 "true" ## 如果你自己会写shell脚本并且希望在每次运行 update 命令时,额外运行你的 shell 脚本,请赋值为 "true"
## 同时,请务必将你的脚本命名为 extra.sh (只能叫这个文件名),放在 config 目录下 ## 同时,请务必将你的脚本命名为 extra.sh (只能叫这个文件名),放在 config 目录下
EnableExtraShell="" EnableExtraShell=""
## 启用其他开发者的仓库方式一(选填):完整更新整个仓库,针对同一个仓库,方式一和方式二只能选择一种
## RepoUrl仓库地址清单必须从1开始依次编号
## RepoBranch你想使用的分支清单不指定分支即使用默认分支时可以用一对不包含内容的空引号"",编号必须和 OwnRepoUrl 对应。
## RepoPath要使用的脚本在仓库哪个路径下请输入仓库下的相对路径默认空值""代表仓库根目录,编号必须和 OwnRepoUrl 对应同一个仓库下不同文件夹之间使用空格分开。如果既包括根目录又包括子目录填写请见示例中OwnRepoPath3。
## 所有脚本存放在 own 目录下,三个清单必须一一对应,示例如下:
## RepoUrl1="https://gitee.com/abc/jdtsa.git"
## RepoUrl2="https://github.com/nedcd/jxddfsa.git"
## RepoUrl3="git@github.com:eject/poex.git"
##
## RepoBranch1="" # 代表第1个仓库 https://gitee.com/abc/jdtsa.git 使用 "默认" 分支
## RepoBranch2="main" # 代表第2个仓库 https://github.com/nedcd/jxddfsa.git 使用 "main" 分支
## RepoBranch3="master" # 代表第3个仓库 git@github.com:eject/poex.git 使用 "master" 分支
##
## RepoPath1="" # 代表第1个仓库https://gitee.com/abc/jdtsa.git你想使用的脚本就在仓库根目录下。
## RepoPath2="scripts/jd normal" # 代表第2个仓库https://github.com/nedcd/jxddfsa.git你想使用的脚本在仓库的 scripts/jd 和 normal文件夹下必须输入相对路径
## RepoPath3="'' cron" # 代表第3个仓库git@github.com:eject/poex.git你想使用的脚本在仓库的 根目录 和 cron 文件夹下,必须输入相对路径
RepoUrl1=""
RepoUrl2=""
RepoBranch1=""
RepoBranch2=""
RepoPath1=""
RepoPath2=""
## 启用其他开发者的仓库方式二(选填):只下载想要的文件,针对同一个脚本,方式一和方式二建议只选择一种。
## 请先确认你能正常下载该raw文件才列在下方无论是github还是gitee请只填入 raw 文件链接。
## 一行一个文件下载链接,首尾一对半角括号,示例:
## RawUrl=(
## https://gitee.com/wabdwdd/scipts/raw/master/jd_abc.js
## https://github.com/lonfeg/loon/raw/main/jd_dudi.js
## https://github.com/sunsem/qx/raw/main/z_dida.js
## )
RawUrl=(
)

View File

@ -12,6 +12,8 @@ import_config_no_check rmlog
detect_termux detect_termux
detect_macos detect_macos
days=$1
## 删除运行js脚本的旧日志 ## 删除运行js脚本的旧日志
remove_js_log () { remove_js_log () {
local log_full_path_list=$(ls -l $dir_log/*/*.log | awk '{print $9}') local log_full_path_list=$(ls -l $dir_log/*/*.log | awk '{print $9}')
@ -23,7 +25,7 @@ remove_js_log () {
else else
diff_time=$(($(date +%s) - $(date +%s -d "$log_date"))) diff_time=$(($(date +%s) - $(date +%s -d "$log_date")))
fi fi
[[ $diff_time -gt $((${RmLogDaysAgo} * 86400)) ]] && rm -vf $log [[ $diff_time -gt $((${days} * 86400)) ]] && rm -vf $log
done done
} }
@ -38,7 +40,7 @@ remove_empty_dir () {
} }
## 运行 ## 运行
if [[ ${RmLogDaysAgo} ]]; then if [[ ${days} ]]; then
echo -e "查找旧日志文件中...\n" echo -e "查找旧日志文件中...\n"
remove_js_log remove_js_log
remove_empty_dir remove_empty_dir

View File

@ -35,15 +35,11 @@ var_name=(
## 软连接及其原始文件对应关系 ## 软连接及其原始文件对应关系
link_name=( link_name=(
task task
rmlog ql
update
rebuild
) )
original_name=( original_name=(
task.sh task.sh
rmlog.sh
update.sh update.sh
rebuild.sh
) )
## 导入配置文件不校验 ## 导入配置文件不校验

View File

@ -10,15 +10,12 @@ dir_root=$(
send_mark=$dir_shell/send_mark send_mark=$dir_shell/send_mark
# 导入通用变量与函数 # 导入通用变量与函数
# . $dir_shell/share.sh . $dir_shell/share.sh
# . $dir_shell/api.sh . $dir_shell/api.sh
. ./shell/share.sh
. ./shell/api.sh
## 导入配置文件,检测平台,创建软连接,识别命令,修复配置文件 ## 导入配置文件,检测平台,创建软连接,识别命令,修复配置文件
detect_termux detect_termux
detect_macos detect_macos
link_shell
define_cmd define_cmd
fix_config fix_config
import_config_no_check "update" import_config_no_check "update"
@ -409,6 +406,9 @@ main() {
raw) raw)
update_raw | tee $log_path update_raw | tee $log_path
;; ;;
rmlog)
source $dir_shell/rmlog.sh "$p2" | tee $log_path
;;
*) *)
echo -e "命令输入错误...\n" echo -e "命令输入错误...\n"
usage usage