From b6376ed2e8e03cee483454dda74a6ef8fdd6924a Mon Sep 17 00:00:00 2001 From: whyour Date: Thu, 12 Oct 2023 00:45:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=20task=5Fafter=20=E5=91=BD=E4=BB=A4=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=81=9C=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/config/util.ts | 6 +++--- shell/otask.sh | 6 ++++-- shell/share.sh | 12 +++++++----- shell/task.sh | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/back/config/util.ts b/back/config/util.ts index 5c586983..aabd0975 100644 --- a/back/config/util.ts +++ b/back/config/util.ts @@ -423,11 +423,11 @@ export function psTree(pid: number): Promise { export async function killTask(pid: number) { const pids = await psTree(pid); - // SIGINT 2 程序终止(interrupt)信号,不会打印额外信息 + if (pids.length) { try { - [pid, ...pids].forEach((x) => { - process.kill(x, 2); + [pid, ...pids].reverse().forEach((x) => { + process.kill(x, 15); }); } catch (error) { } } else { diff --git a/shell/otask.sh b/shell/otask.sh index e573c504..5391428b 100755 --- a/shell/otask.sh +++ b/shell/otask.sh @@ -241,6 +241,8 @@ main() { fi } -handle_task_before "$@" +handle_task_start "$@" +run_task_before "$@" main "$@" -handle_task_after "$@" +run_task_after "$@" +handle_task_end "$@" diff --git a/shell/share.sh b/shell/share.sh index 96c4cafd..17a3f4ab 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -416,7 +416,7 @@ init_nginx() { location_url="^~${ql_base_url%*/}" aliasStr="alias ${dir_static}/dist;" if ! grep -q "" "${dir_static}/dist/index.html"; then - awk -v text="" '/ temp.html + awk -v text="" '/temp.html mv temp.html "${dir_static}/dist/index.html" fi else @@ -438,11 +438,12 @@ init_nginx() { sed -i "s,IPV4_CONFIG,${ipv4Str},g" /etc/nginx/conf.d/front.conf } -handle_task_before() { +handle_task_start() { [[ $ID ]] && update_cron "\"$ID\"" "0" "$$" "$log_path" "$begin_timestamp" - echo -e "## 开始执行... $begin_time\n" +} +run_task_before() { [[ $is_macos -eq 0 ]] && check_server . $file_task_before "$@" @@ -454,7 +455,7 @@ handle_task_before() { fi } -handle_task_after() { +run_task_after() { . $file_task_after "$@" if [[ $task_after ]]; then @@ -462,7 +463,9 @@ handle_task_after() { eval "$task_after" echo -e "\n执行后置命令结束" fi +} +handle_task_end() { local etime=$(date "+$time_format") local end_time=$(format_time "$time_format" "$etime") local end_timestamp=$(format_timestamp "$time_format" "$etime") @@ -471,7 +474,6 @@ handle_task_after() { [[ "$diff_time" == 0 ]] && diff_time=1 echo -e "\n## 执行结束... $end_time 耗时 $diff_time 秒     " - [[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time" } diff --git a/shell/task.sh b/shell/task.sh index 570a5332..5fb61b7c 100755 --- a/shell/task.sh +++ b/shell/task.sh @@ -7,7 +7,7 @@ dir_shell=$QL_DIR/shell trap "single_hanle" 2 3 20 15 14 19 1 single_hanle() { - eval handle_task_after "$@" "$cmd" + eval handle_task_end "$@" "$cmd" exit 1 }