Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
确保PM2 restart/stop一定出发结束守护进程
确保PM2 restart/stop一定出发结束守护进程
  • Loading branch information
sanshu-rom authored Aug 19, 2025
commit 2de0f1a6fb049c219ab14b2fb650e5b798722158
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,20 @@ export default async function handler(req, res) {
const currentFile = path.normalize(fileURLToPath(import.meta.url)); // 使用 normalize 确保路径一致
const indexFile = path.normalize(path.resolve(__dirname, 'index.js')); // 标准化路径

// 保证 PM2 restart / stop 一定会触发
['SIGINT', 'SIGTERM', 'SIGUSR2'].forEach(sig =>
process.on(sig, async () => {
console.log(`[${sig}] 开始优雅关闭...`);
try {
await daemon.stopDaemon();
console.log('Python 守护进程已停止');
} catch (e) {
console.error(e);
}
process.exit(0);
})
);

if (currentFile === indexFile) {
start();
}