Files
2.13-Ink-screen-clock/bin/clean.sh
2025-01-12 16:39:55 +08:00

32 lines
884 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
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
echo "脚本运行完成服务已停止nohup进程已结束。"