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
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();
}