惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
阮一峰的网络日志
阮一峰的网络日志
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Threat Research - Cisco Blogs
P
Privacy & Cybersecurity Law Blog
The Hacker News
The Hacker News
H
Heimdal Security Blog
W
WeLiveSecurity
L
LINUX DO - 热门话题
Hacker News: Ask HN
Hacker News: Ask HN
WordPress大学
WordPress大学
The Last Watchdog
The Last Watchdog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
D
DataBreaches.Net
I
Intezer
Webroot Blog
Webroot Blog
C
Cisco Blogs
AWS News Blog
AWS News Blog
博客园 - 聂微东
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
罗磊的独立博客
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
Schneier on Security
Schneier on Security
宝玉的分享
宝玉的分享
博客园 - 叶小钗
PCI Perspectives
PCI Perspectives
D
Docker
Scott Helme
Scott Helme
NISL@THU
NISL@THU
J
Java Code Geeks
B
Blog RSS Feed
Google Online Security Blog
Google Online Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Exploit Database - CXSecurity.com
AI
AI
美团技术团队
Cloudbric
Cloudbric
月光博客
月光博客
P
Proofpoint News Feed
T
Tailwind CSS Blog
Google DeepMind News
Google DeepMind News
小众软件
小众软件
www.infosecurity-magazine.com
www.infosecurity-magazine.com
The Cloudflare Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org

博客园 - uestc2007

AI 智能体项目的测试 vllm方式部署Deepseek R1、Embedding、Reranker、Qwen 磁盘挂载 LibreOffice 批量将.doc文件转换为.docx 容器异常或停止自动启动脚本 资源监控脚本 Docker 安全及日志管理 Docker资源控制 做项目管理需要哪些技能 项目管理的基本工作是什么 知识图谱介绍(三) 知识图谱介绍(二) 知识图谱介绍(一) 安装Kuboard管理k8s Registry&Harbor私有仓库构建 EMQX配置用户名和密码开启emqx_auth_mnesia认证方式连接 开关量、数字量、模拟量、离散量和脉冲量它们之间有什么区别? Kubernetes基础总结 Kubernetes管理应用程序、服务常用命令、集群监视
Supervisor 监控 Python 服务
uestc2007 · 2025-12-17 · via 博客园 - uestc2007

使用 Supervisor 来监控并自动重启 Python 应用。以下是配置步骤:

1. 安装 Supervisor

#ubuntu
sudo apt update
sudo apt install supervisor

#centos
sudo yum update
sudo yum install supervisor

2. 创建 Supervisor 配置文件

在 /etc/supervisor/conf.d/ 目录下创建一个配置文件(例如 kg.conf):

vi /etc/supervisor/conf.d/kg.conf,将以下内容写入配置文件:

[program:kg_ai_service2]
command=python3 /home/iot/wh/kg/run.py  ; 运行命令
directory=/home/iot/wh/kg               ; 工作目录
user=iot                                            ; 运行用户
autostart=true                                      ; 是否随 Supervisor 启动
autorestart=true                                    ; 自动重启
startretries=3                                      ; 启动失败时的重试次数
startsecs=10                                        ; 启动 10 秒后无异常则视为正常
stderr_logfile=/var/log/kg_err.log      ; 错误日志路径
stdout_logfile=/var/log/kg_out.log      ; 输出日志路径
environment=PYTHONPATH="/home/iot/wh/kg" ; 环境变量(可选)

方法1:直接使用虚拟环境的 Python 路径

[program:kg]
command=/root/python/uie/bin/python /home/iot/wh/kg/run.py
directory=/home/iot/wh/kg
user=root  # 如果虚拟环境在 /root 目录下,可能需要使用 root 用户
autostart=true
autorestart=true
startretries=3
startsecs=10
stderr_logfile=/var/log/kg_err.log
stdout_logfile=/var/log/kg_out.log
environment=PYTHONPATH="/home/iot/wh/kg"

方法2:使用 bash -c 激活虚拟环境


[program:kg]
command=bash -c 'source /root/python/uie/bin/activate && python /root/wh/kg/run.py'
directory=/root/wh/kg
user=root
autostart=true
autorestart=true
startretries=3
startsecs=10
stopwaitsecs=60
stopsignal=TERM
stdout_logfile=/var/log/supervisor/kg_out.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=10
stderr_logfile=/var/log/supervisor/kg_err.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=10
environment=
PYTHONPATH="/root/wh/kg:/root/python/uie/lib/python3.X/site-packages",PATH="/root/python/uie/bin:%(ENV_PATH)s"

方法3:使用虚拟环境中的 python 并添加路径

[program:kg_ai_service2]
command=/root/python/uie/bin/python /home/iot/wh/kg_ai_service2/run.py
directory=/home/iot/wh/kg_ai_service2
user=root
autostart=true
autorestart=true
startretries=3
startsecs=10
stderr_logfile=/var/log/kg_ai_service2.err.log
stdout_logfile=/var/log/kg_ai_service2.out.log
environment=HOME="/root",PYTHONPATH="/home/iot/wh/kg_ai_service2",PATH="/root/python/uie/bin:%(ENV_PATH)s"

3. 重新加载 Supervisor 配置

# 更新 Supervisor 配置
sudo supervisorctl reread
sudo supervisorctl update

# 启动服务
sudo supervisorctl start kg

# 查看服务状态
sudo supervisorctl status kg

# 查看服务日志
sudo tail -f /var/log/kg_out.log

4. 管理应用

# 查看所有服务状态
sudo supervisorctl status

# 重启服务
sudo supervisorctl restart kg

# 停止服务
sudo supervisorctl stop kg

# 重新启动所有服务
sudo supervisorctl reload

# 查看 Supervisor 日志
sudo tail -f tail -f /var/log/kg_out.log