增加public服务,查询panel日志

This commit is contained in:
whyour 2022-02-24 23:50:04 +08:00
parent 531fc48bdf
commit ee52f09bcb
5 changed files with 56 additions and 4 deletions

View File

@ -1,3 +1,4 @@
PUBLIC_PORT=5400
CRON_PORT=5500
BACK_PORT=5600
PORT=5700

View File

@ -37,6 +37,7 @@ if (envFound.error) {
export default {
port: parseInt(process.env.BACK_PORT as string, 10),
cronPort: parseInt(process.env.CRON_PORT as string, 10),
publicPort: parseInt(process.env.PUBLIC_PORT as string, 10),
secret: process.env.SECRET || createRandomString(16, 32),
logs: {
level: process.env.LOG_LEVEL || 'silly',

34
back/public.ts Normal file
View File

@ -0,0 +1,34 @@
import express from 'express';
import { exec } from 'child_process';
import Logger from './loaders/logger';
import config from './config';
const app = express();
const run = async () => {
app.get('/api/public/panel/log', (req, res) => {
exec('pm2 logs panel --lines 500', (err, stdout, stderr) => {
if (err || stderr) {
return res.send({ code: 400, data: err || stderr });
}
return res.send({ code: 200, data: stdout });
});
});
};
app
.listen(config.publicPort, async () => {
await require('./loaders/sentry').default({ expressApp: app });
await require('./loaders/db').default();
await run();
Logger.info(`
################################################
🛡 Public listening on port: ${config.publicPort} 🛡
################################################
`);
})
.on('error', (err) => {
Logger.error(err);
process.exit(1);
});

View File

@ -20,24 +20,29 @@ echo -e "======================3. 启动nginx========================\n"
nginx -s reload 2>/dev/null || nginx -c /etc/nginx/nginx.conf
echo -e "nginx启动成功...\n"
echo -e "======================4. 启动控制面板========================\n"
echo -e "======================4. 启动面板监控========================\n"
pm2 delete public &>/dev/null
pm2 start $dir_static/build/public.js -n public --source-map-support --time
echo -e "监控服务启动成功...\n"
echo -e "======================5. 启动控制面板========================\n"
pm2 delete panel &>/dev/null
pm2 start $dir_static/build/app.js -n panel --source-map-support --time
echo -e "控制面板启动成功...\n"
echo -e "======================5. 启动定时任务========================\n"
echo -e "======================6. 启动定时任务========================\n"
pm2 delete schedule &>/dev/null
pm2 start $dir_static/build/schedule.js -n schedule --source-map-support --time
echo -e "定时任务启动成功...\n"
if [[ $AutoStartBot == true ]]; then
echo -e "======================6. 启动bot========================\n"
echo -e "======================7. 启动bot========================\n"
nohup ql bot >>$dir_log/start.log 2>&1 &
echo -e "bot后台启动中...\n"
fi
if [[ $EnableExtraShell == true ]]; then
echo -e "======================7. 执行自定义脚本========================\n"
echo -e "======================8. 执行自定义脚本========================\n"
nohup ql extra >>$dir_log/start.log 2>&1 &
echo -e "自定义脚本后台执行中...\n"
fi

View File

@ -2,6 +2,10 @@ upstream api {
server 0.0.0.0:5600;
}
upstream public {
server 0.0.0.0:5400;
}
map $http_upgrade $connection_upgrade {
default keep-alive;
'websocket' upgrade;
@ -12,6 +16,13 @@ server {
root /ql/static/dist;
ssl_session_timeout 5m;
location /api/public {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://public;
}
location /api {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;