import psutil
import os

cmd = [('wxwork_approval_data_consumer.py', "systemctl {0} wxwork_approval_data_consumer.service"),
       ('/opt/work_wechat/run.sh', "systemctl {0} run_work_wechat.service")
       ]
pre_run = list()

for single_cmd in cmd:
    x = single_cmd[0]
    count = 0
    for pid in psutil.pids():
        p = psutil.Process(pid)
        for z in p.cmdline():
            if x in z:
                if p.is_running():
                    print(str(pid) + ' is running.')
                    count += 1
                    break
        if count > 0:
            break
    if count == 0:
        pre_run.append(single_cmd[1])
for pr in pre_run:
    os.system(pr.format('start'))
# 利用系统定时器  每隔一秒执行上面的watch_dog程序
crontab -e
*/1 * * * * /opt/work_wechat/watch_dog.py

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2021-09-16
  • 2022-12-23
  • 2021-07-19
  • 2022-12-23
猜你喜欢
  • 2021-08-01
  • 2022-02-28
  • 2021-09-23
  • 2021-11-15
  • 2021-05-26
  • 2022-12-23
相关资源
相似解决方案