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

推荐订阅源

Engineering at Meta
Engineering at Meta
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
量子位
腾讯CDC
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
The Hacker News
The Hacker News
T
The Exploit Database - CXSecurity.com
B
Blog
S
SegmentFault 最新的问题
P
Privacy & Cybersecurity Law Blog
T
Threatpost
博客园 - 聂微东
T
Tailwind CSS Blog
The Last Watchdog
The Last Watchdog
C
Check Point Blog
N
Netflix TechBlog - Medium
D
DataBreaches.Net
爱范儿
爱范儿
IT之家
IT之家
S
Secure Thoughts
M
MIT News - Artificial intelligence
NISL@THU
NISL@THU
C
Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
有赞技术团队
有赞技术团队
A
Arctic Wolf
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Proofpoint News Feed
Spread Privacy
Spread Privacy
Schneier on Security
Schneier on Security
Simon Willison's Weblog
Simon Willison's Weblog
G
GRAHAM CLULEY
雷峰网
雷峰网
Project Zero
Project Zero
博客园 - Franky
H
Heimdal Security Blog
A
About on SuperTechFans
Security Latest
Security Latest
Webroot Blog
Webroot Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - 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