From dfae4181cbb7283dd19455f96286422eb68efb36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=85=89-k?= <36470587+kxgx@users.noreply.github.com> Date: Mon, 20 Jan 2025 23:16:32 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20e-Paper=5Fclean.service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/e-Paper_clean.service | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/bin/e-Paper_clean.service b/bin/e-Paper_clean.service index e8e27a7..8dd6092 100644 --- a/bin/e-Paper_clean.service +++ b/bin/e-Paper_clean.service @@ -1,14 +1,23 @@ -[Unit] -Description=Run e-Paper clean on shutdown and reboot -DefaultDependencies=no -Before=shutdown.target -Before=reboot.target +#!/bin/bash -[Service] -Type=oneshot -ExecStart=/bin/bash /root/2.13-Ink-screen-clock/bin/clean.sh -RemainAfterExit=yes +f_name="clean.py" +dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +logdir="${dir%/*}/log" +service_name="raspi_e-Paper.service" + +# 停止raspi_e-Paper服务 +echo "正在停止$service_name服务..." +sudo systemctl stop "$service_name" -[Install] -WantedBy=shutdown.target -WantedBy=reboot.target +# 确保日志目录存在 +mkdir -p "${logdir}" + +# 获取并终止所有与脚本相关的进程 +pids=$(pgrep -f "$dir/$f_name") +if [ -n "$pids" ]; then + kill -9 $pids +fi + +echo "正在清除屏幕内容" +# 运行Python脚本,并将输出重定向到日志文件 +/usr/bin/python3 -u "$dir/$f_name" > "${logdir}/info-clean.log" 2>&1 &