You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Monit无法检测到运行中的Python程序问题排查求助

Monit无法检测到运行中的Python进程问题

环境信息

  • 系统:运行在Proxmox LXC容器中的Ubuntu 22.04.3 LTS
  • Monit版本:5.31.0,也曾尝试5.26.0和5.33.0版本
  • 背景:使用Monit多年,但首次在该系统部署;Monit可成功启动程序,但会在指定超时后重复尝试重启,且误报进程未运行(实际进程正常)

Monit配置片段

check process test MATCHING "/home/pi/monit/test.py"
    start program = "/usr/bin/python3 /home/pi/monit/test.py >> /home/pi/monit/test.log 2>&1" timeout 30 seconds
    stop program = "/usr/bin/pkill -f '/home/pi/monit/test.py'"
    if does not exist then restart

PID文件详情(使用PID方法时)

-rw-r--r--  1 root root     6 Aug 10 16:37 test.pid

Monit日志内容

[2023-08-18T13:40:15+0200] error    : 'test' process is not running
[2023-08-18T13:40:15+0200] info     : 'test' trying to restart
[2023-08-18T13:40:15+0200] info     : 'test' start: '/usr/bin/python3 /home/pi/monit/test.py >> /home/pi/monit/test.log 2>&1'
[2023-08-18T13:40:45+0200] error    : 'test' failed to start (exit status -1) -- Program '/usr/bin/python3 /home/pi/monit/test.py >> /home/pi/monit/test.log 2>&1' timed out after 30 s
[2023-08-18T13:41:46+0200] error    : 'test' process is not running
[2023-08-18T13:41:46+0200] info     : 'test' trying to restart
[2023-08-18T13:41:46+0200] info     : 'test' start: '/usr/bin/python3 /home/pi/monit/test.py >> /home/pi/monit/test.log 2>&1'
[2023-08-18T13:42:16+0200] error    : 'test' failed to start (exit status -1) -- Program '/usr/bin/python3 /home/pi/monit/test.py >> /home/pi/monit/test.log 2>&1' timed out after 30 s
[2023-08-18T13:43:17+0200] error    : 'test' process is not running

关键说明

  • 当Monit报告进程未运行时,test.py实际处于运行状态
  • test.py启动仅需数毫秒,手动启动无任何问题

已尝试的解决方法

  • 多次重装不同版本的Monit
  • 在裸机Ubuntu 22.04.3 LTS上测试运行
  • 同时使用PID文件和MATCHING进程匹配方法
  • 尝试多种start program语法变体

问题

如何解决Monit误报Python进程未运行的问题?

内容的提问来源于stack exchange,提问作者Alfred Elkerbout

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 07:27:52