mirror of
https://github.com/kxgx/2.13-Ink-screen-clock.git
synced 2026-04-02 10:05:08 +08:00
Update clean.sh
This commit is contained in:
32
bin/clean.sh
32
bin/clean.sh
@@ -3,29 +3,25 @@
|
||||
f_name="clean.py"
|
||||
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
logdir="${dir}/log"
|
||||
screen_name="clean_screen"
|
||||
service_name="raspi_e-Paper.service"
|
||||
hold_time_seconds=3 # 设置维持时间,例如300秒(5分钟)
|
||||
|
||||
# 创建日志目录,如果它不存在的话
|
||||
mkdir -p "${logdir}"
|
||||
|
||||
# 使用nohup在后台运行Python脚本,并将输出重定向到日志文件
|
||||
nohup /usr/bin/python3 -u "$dir/$f_name" > "${logdir}/clean-info.log" 2>&1 &
|
||||
|
||||
# 获取nohup进程的PID
|
||||
nohup_pid=$!
|
||||
|
||||
# 等待维持时间
|
||||
echo "正在运行脚本,将在 ${hold_time_seconds} 秒后停止服务..."
|
||||
sleep $hold_time_seconds
|
||||
|
||||
# 停止raspi_e-Paper服务
|
||||
echo "正在停止$service_name服务..."
|
||||
sudo systemctl stop "$service_name"
|
||||
|
||||
# 结束nohup进程
|
||||
echo "正在结束nohup进程..."
|
||||
kill -9 $nohup_pid
|
||||
# 确保日志目录存在
|
||||
mkdir -p "${logdir}"
|
||||
|
||||
echo "脚本运行完成,服务已停止,nohup进程已结束。"
|
||||
# 获取并终止所有与脚本相关的进程
|
||||
pids=$(pgrep -f "$dir/$f_name")
|
||||
if [ -n "$pids" ]; then
|
||||
kill -9 $pids
|
||||
fi
|
||||
|
||||
# 使用nohup在后台运行Python脚本,并将输出重定向到日志文件
|
||||
nohup /usr/bin/python3 -u "$dir/$f_name" > "${logdir}/info-clean.log" 2>&1 &
|
||||
|
||||
# 等待维持时间
|
||||
echo "正在运行脚本,将在 ${hold_time_seconds} 秒后停止服务..."
|
||||
sleep $hold_time_seconds
|
||||
|
||||
Reference in New Issue
Block a user