ubuntu系统自动重启保护程序

ubuntu系统自动重启保护程序,第1张

这里所需要的python依赖项相对较少,只需要安装下schedule即可(这个包很小,无需镜像也会很快装完),这个是定时任务时会用到的,直接在运行的python环境下执行以下命令
pip install schedule
1
1
二、重启任务
这一部分我们将贴出代码,大致逻辑是先检测到我们要重启的程序id,然后kill掉之后,进行重新启动,代码如下:
import os,sys,schedule
import subprocess,time
def restart_frp():
child =subprocessPopen(["pgrep","-f","xxx"],stdout=subprocessPIPE,)
pid=childstdoutread()decode("utf-8")strip()
#print(pid)
if pid!="":
ossystem("kill -9 "+pid)
child2=subprocessPopen("xxx",stdout=subprocessPIPE,shell=True)
print(timestrftime("%Y-%m-%d %H:%M",timelocaltime()))
if __name__ == '__main__':
restart_frp()
scheduleevery()hourdo(restart_frp)
while True:
schedulerun_pending()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
其中的xxx均为你要 *** 作的程序名称
三、bug记录
自己在运行中若遇到如下错误:在这里插入描述
则执行如下 *** 作:
第一步,执行命令
ls -l /bin/sh
1
1
若显示结果为:/bin/sh -> dash,那就执行第二步:
sudo dpkg-reconfigure dash (出现窗口选择no)
1
1
第三步,再次执行命令:
ls -l /bin/sh
1
1
显示为 /bin/sh -> bash后,重新运行程

frp 是一个可用于内网穿透的高性能的反向代理应用,支持 tcp, udp, >

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zz/13447472.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-08-08
下一篇 2023-08-08

发表评论

登录后才能评论

评论列表(0条)

保存