diff --git a/back/services/cron.ts b/back/services/cron.ts index fc41d3f0..6dba7d0d 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -246,7 +246,7 @@ export default class CronService { cmdStr = `${cmdStr} now`; } - const cp = spawn(cmdStr, { shell: '/bin/bash' }); + const cp = spawn(cmdStr, { shell: '/bin/bash', detached: true }); this.cronDb.update( { _id }, { $set: { status: CrontabStatus.running, pid: cp.pid } }, diff --git a/shell/share.sh b/shell/share.sh index 9c6596d8..9b52b4dd 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -31,6 +31,7 @@ file_notify_js_sample=$dir_sample/notify.js file_notify_py_sample=$dir_sample/notify.py file_notify_py=$dir_scripts/notify.py file_notify_js=$dir_scripts/sendNotify.js +task_error_log_path=$dir_log/task_error.log ## 清单文件 list_crontab_user=$dir_config/crontab.list @@ -305,4 +306,6 @@ init_env detect_termux detect_macos define_cmd -import_config $1 + +rm $task_error_log_path +import_config $1 >> $task_error_log_path 2>&1 diff --git a/shell/task.sh b/shell/task.sh index b2a8861a..03d214b9 100755 --- a/shell/task.sh +++ b/shell/task.sh @@ -92,6 +92,8 @@ run_normal() { local id=$(cat $list_crontab_user | grep -E "$cmd_task $p1" | perl -pe "s|.*ID=(.*) $cmd_task $p1\.*|\1|" | head -1 | awk -F " " '{print $1}') local begin_time=$(date '+%Y-%m-%d %H:%M:%S') echo -e "## 开始执行... $begin_time\n" >> $log_path + cat $task_error_log_path >> $log_path + [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" . $file_task_before >> $log_path 2>&1 @@ -124,9 +126,9 @@ run_concurrent() { local id=$(cat $list_crontab_user | grep -E "$cmd_task $p1" | perl -pe "s|.*ID=(.*) $cmd_task $p1\.*|\1|" | head -1 | awk -F " " '{print $1}') local begin_time=$(date '+%Y-%m-%d %H:%M:%S') echo -e "## 开始执行... $begin_time\n" >> $log_path + cat $task_error_log_path >> $log_path [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" . $file_task_before >> $log_path 2>&1 - echo -e "\n各账号间已经在后台开始并发执行,前台不输入日志,日志直接写入文件中。\n" >> $log_path local envs=$(eval echo "\$${p3}") local array=($(echo $envs | sed 's/&/ /g')) @@ -137,6 +139,13 @@ run_concurrent() { timeout -k 10s $command_timeout_time $which_program $p1 &>$single_log_path 2>&1 & done + wait + for i in "${!array[@]}"; do + single_log_path="$log_dir/${single_log_time}_$((i + 1)).log" + cat $single_log_path >> $log_path + [ -f $single_log_path ] && rm -f $single_log_path + done + . $file_task_after >> $log_path 2>&1 [[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path" local end_time=$(date '+%Y-%m-%d %H:%M:%S') @@ -155,6 +164,8 @@ run_else() { local id=$(cat $list_crontab_user | grep -E "$cmd_task $p1" | perl -pe "s|.*ID=(.*) $cmd_task $p1\.*|\1|" | head -1 | awk -F " " '{print $1}') local begin_time=$(date '+%Y-%m-%d %H:%M:%S') echo -e "## 开始执行... $begin_time\n" >> $log_path + cat $task_error_log_path >> $log_path + [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" . $file_task_before >> $log_path 2>&1 diff --git a/shell/update.sh b/shell/update.sh index f01ee66c..dd78859c 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -285,10 +285,10 @@ update_qinglong() { rm -rf $dir_root/build && rm -rf $dir_root/dist cp -rf $ql_static_repo/* $dir_root if [[ $no_restart != "no-restart" ]]; then - echo -e "重启面板中..." - nginx -s reload 2>/dev/null || nginx -c /etc/nginx/nginx.conf - sleep 1 reload_pm2 + nginx -s reload 2>/dev/null || nginx -c /etc/nginx/nginx.conf + sleep 3 + echo -e "重启面板中..." fi else echo -e "\n更新$dir_root失败,请检查原因...\n" @@ -436,19 +436,22 @@ main() { case $p1 in update) echo -e "## 开始执行... $begin_time\n" >> $log_path - update_qinglong "$2" | tee -p -a $log_path + cat $task_error_log_path >> $log_path + update_qinglong "$2" >> $log_path ;; extra) echo -e "## 开始执行... $begin_time\n" >> $log_path - run_extra_shell | tee -p -a $log_path + cat $task_error_log_path >> $log_path + run_extra_shell >> $log_path ;; repo) get_user_info get_uniq_path "$p2" "$p6" log_path="$dir_log/update/${log_time}_${uniq_path}.log" echo -e "## 开始执行... $begin_time\n" >> $log_path + cat $task_error_log_path >> $log_path if [[ -n $p2 ]]; then - update_repo "$p2" "$p3" "$p4" "$p5" "$p6" | tee -p -a $log_path + update_repo "$p2" "$p3" "$p4" "$p5" "$p6" >> $log_path else echo -e "命令输入错误...\n" usage @@ -459,8 +462,9 @@ main() { get_uniq_path "$p2" log_path="$dir_log/update/${log_time}_${uniq_path}.log" echo -e "## 开始执行... $begin_time\n" >> $log_path + cat $task_error_log_path >> $log_path if [[ -n $p2 ]]; then - update_raw "$p2" | tee -p -a $log_path + update_raw "$p2" >> $log_path else echo -e "命令输入错误...\n" usage @@ -468,15 +472,18 @@ main() { ;; rmlog) echo -e "## 开始执行... $begin_time\n" >> $log_path - . $dir_shell/rmlog.sh "$p2" | tee -p -a $log_path + cat $task_error_log_path >> $log_path + . $dir_shell/rmlog.sh "$p2" >> $log_path ;; bot) echo -e "## 开始执行... $begin_time\n" >> $log_path - . $dir_shell/bot.sh | tee -p -a $log_path + cat $task_error_log_path >> $log_path + . $dir_shell/bot.sh >> $log_path ;; check) echo -e "## 开始执行... $begin_time\n" >> $log_path - . $dir_shell/check.sh | tee -p -a $log_path + cat $task_error_log_path >> $log_path + . $dir_shell/check.sh >> $log_path ;; *) echo -e "命令输入错误...\n"