mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 06:46:09 +08:00
31 lines
897 B
TypeScript
31 lines
897 B
TypeScript
import { ServerUnaryCall, sendUnaryData } from '@grpc/grpc-js';
|
|
import { HealthCheckRequest, HealthCheckResponse } from '../protos/health';
|
|
import { exec } from 'child_process';
|
|
import config from '../config';
|
|
import { promiseExec } from '../config/util';
|
|
|
|
const check = async (
|
|
call: ServerUnaryCall<HealthCheckRequest, HealthCheckResponse>,
|
|
callback: sendUnaryData<HealthCheckResponse>,
|
|
) => {
|
|
switch (call.request.service) {
|
|
case 'cron':
|
|
const res = await promiseExec(
|
|
`curl -sf http://localhost:${config.port}/api/system`,
|
|
);
|
|
console.log(res);
|
|
if (res.includes('200')) {
|
|
return callback(null, { status: 1 });
|
|
}
|
|
const errLog = await promiseExec(
|
|
`tail -n 300 ~/.pm2/logs/panel-error.log`,
|
|
);
|
|
return callback(new Error(errLog));
|
|
|
|
default:
|
|
return callback(null, { status: 1 });
|
|
}
|
|
};
|
|
|
|
export { check };
|