mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
修改系统重启逻辑
This commit is contained in:
@@ -5,28 +5,6 @@ import Sock from './sock';
|
||||
export default async ({ server }: { server: Server }) => {
|
||||
await Sock({ server });
|
||||
Logger.info('✌️ Sock loaded');
|
||||
let exitTime = 0;
|
||||
let timer: NodeJS.Timeout;
|
||||
|
||||
process.on('SIGINT', (singal) => {
|
||||
Logger.warn(`Server need close, singal ${singal}`);
|
||||
console.warn(`Server need close, singal ${singal}`);
|
||||
exitTime++;
|
||||
if (exitTime >= 3) {
|
||||
Logger.warn('Forcing server close');
|
||||
console.warn('Forcing server close');
|
||||
clearTimeout(timer);
|
||||
process.exit(1);
|
||||
}
|
||||
server.close(() => {
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
timer = setTimeout(() => {
|
||||
process.exit();
|
||||
}, 15000);
|
||||
});
|
||||
});
|
||||
|
||||
process.on('uncaughtException', (error) => {
|
||||
Logger.error('Uncaught exception:', error);
|
||||
|
||||
+16
-1
@@ -4,9 +4,9 @@ import cors from 'cors';
|
||||
import { Application, NextFunction, Request, Response } from 'express';
|
||||
import jwt from 'express-jwt';
|
||||
import Container from 'typedi';
|
||||
import Logger from './logger';
|
||||
import config from '../config';
|
||||
import SystemService from '../services/system';
|
||||
import Logger from './logger';
|
||||
|
||||
export default ({ app }: { app: Application }) => {
|
||||
app.set('trust proxy', 'loopback');
|
||||
@@ -22,6 +22,20 @@ export default ({ app }: { app: Application }) => {
|
||||
}),
|
||||
);
|
||||
|
||||
app.put(
|
||||
'/api/reload',
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const systemService = Container.get(SystemService);
|
||||
const result = await systemService.reloadSystem();
|
||||
res.send(result);
|
||||
} catch (e) {
|
||||
Logger.error('🔥 error: %o', e);
|
||||
return next(e);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
app.put(
|
||||
'/api/system',
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
@@ -35,6 +49,7 @@ export default ({ app }: { app: Application }) => {
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
app.put(
|
||||
'/api/data',
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
|
||||
Reference in New Issue
Block a user