Jrohy/trojan

自动解决trojan死掉以后重启的问题!还得感谢Chatgpt

earth-5G opened this issue · 2 comments

4f5eaf472c8cfd64f3988381227acec

`#!/bin/bash

提示用户输入需要监控的服务名称

read -p "trojan" service_name

检查系统是否安装了systemd

if ! command -v systemctl &> /dev/null; then
echo "Error: systemd is not installed on this system." >&2
exit 1
fi

检查当前用户是否具有sudo权限

if [ "$EUID" -ne 0 ]; then
echo "Error: Please run this script as root or using sudo." >&2
exit 1
fi

定义函数,用于检测服务状态并重启服务

check_and_restart_service() {
if systemctl status "$service_name" | grep -q "inactive"; then
systemctl restart "$service_name"
echo "Service $service_name restarted at $(date)"
else
echo "Service $service_name is running normally."
fi
}

执行函数,并在一定时间间隔内持续检测和重启服务

while true; do
check_and_restart_service
sleep 60 # 间隔60秒进行下一次检测
done`

经本人测试,确实有用!

现在新版的还是有trojan卡掉的问题么?

现在新版的还是有trojan卡掉的问题么?

ying应该没有了!