From fcccdcdbdf3b95c47c5caa4512e4484183646034 Mon Sep 17 00:00:00 2001 From: wandoubaba Date: Thu, 6 Jul 2023 10:25:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BAauto=5Finstall.sh=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E4=BB=A5=E4=BE=BF=E8=87=AA=E5=8A=A8=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=89=A7=E8=A1=8Cauto=5Fcleaner.sh=E7=9A=84=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 +++--------- auto_install.sh | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 auto_install.sh diff --git a/README.md b/README.md index a6c3b2d..a550a05 100644 --- a/README.md +++ b/README.md @@ -63,14 +63,8 @@ php start.php start -d ### 避免因自动打包进程意外终止而导致永远无法自动打包 +可以通过执行`auto_install.sh`脚本创建一个系统定时任务,用来定时清理由`auto_build.sh`脚本错误执行而产生的“僵尸锁”。 + ```sh -crontab -e +sh auto_install.sh ``` - -添加下面一行 - -```crontab -*/10 * * * * /path/to/auto_cleaner.sh /path/to/ >/dev/null 2>&1 -``` - -其中`/path/to/`要替换成实际路径。 diff --git a/auto_install.sh b/auto_install.sh new file mode 100644 index 0000000..87bde7d --- /dev/null +++ b/auto_install.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +lock_file="auto_install.lock" +cleaner_script="auto_cleaner.sh" +cron_command="sh $(pwd)/$cleaner_script $(pwd)/" + +# 检查是否已安装 +if [ -f "$lock_file" ]; then + echo "auto_cleaner.sh任务已安装,如需重新安装,请先删除$lock_file文件" + exit 1 +fi + +# 获取当前目录的绝对路径 +current_dir=$(pwd)/ + +# 检查auto_cleaner.sh文件是否存在 +if [ ! -f "$current_dir$cleaner_script" ]; then + echo "未找到$current_dir$cleaner_script文件,退出本次安装" + exit 1 +fi + +# 检查是否已存在定时任务 +existing_cron=$(crontab -l | grep -F "$cron_command") +if [ -n "$existing_cron" ]; then + echo "auto_cleaner.sh任务已安装,退出本次安装" + exit 1 +fi + +# 创建安装标记文件 +timestamp=$(date +"%Y-%m-%d %H:%M:%S") +echo "安装时间: $timestamp" > "$lock_file" + +# 创建定时任务 +(crontab -l 2>/dev/null; echo "*/10 * * * * $cron_command") | crontab - +echo "auto_cleaner.sh任务安装完毕" + +exit 0