mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
增加 pm2 平滑重启
This commit is contained in:
parent
3d11210aeb
commit
5baa8e4391
|
@ -18,6 +18,7 @@ async function startServer() {
|
|||
const server = app
|
||||
.listen(config.port, () => {
|
||||
Logger.debug(`✌️ 后端服务启动成功!`);
|
||||
process.send?.('ready');
|
||||
})
|
||||
.on('error', (err) => {
|
||||
Logger.error(err);
|
||||
|
|
|
@ -9,8 +9,14 @@ export default async ({ server }: { server: Server }) => {
|
|||
process.on('SIGINT', () => {
|
||||
Logger.info('✌️ Server need close');
|
||||
server.close(() => {
|
||||
Logger.info('✌️ Server closed');
|
||||
process.exit(0);
|
||||
setTimeout(() => {
|
||||
process.exit();
|
||||
}, 10000);
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
console.log('Forcing server close !!!');
|
||||
process.exit(1);
|
||||
}, 15000);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -25,6 +25,7 @@ app
|
|||
await require('./loaders/db').default();
|
||||
|
||||
Logger.debug(`✌️ 公共服务启动成功!`);
|
||||
process.send?.('ready');
|
||||
})
|
||||
.on('error', (err) => {
|
||||
Logger.error(err);
|
||||
|
|
|
@ -16,5 +16,6 @@ server.bindAsync(
|
|||
() => {
|
||||
server.start();
|
||||
Logger.debug(`✌️ 定时服务启动成功!`);
|
||||
process.send?.('ready');
|
||||
},
|
||||
);
|
||||
|
|
|
@ -12,7 +12,6 @@ make_dir /run/nginx
|
|||
init_nginx
|
||||
|
||||
pm2 l &>/dev/null
|
||||
pm2 flush &>/dev/null
|
||||
|
||||
echo -e "======================2. 安装依赖========================\n"
|
||||
patch_version
|
||||
|
@ -32,36 +31,17 @@ 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"
|
||||
pm2 delete schedule &>/dev/null
|
||||
pm2 start $dir_static/build/schedule/index.js -n schedule --source-map-support --time
|
||||
echo -e "定时任务启动成功...\n"
|
||||
|
||||
echo -e "======================5. 启动面板监控========================\n"
|
||||
pm2 delete public &>/dev/null
|
||||
pm2 start $dir_static/build/public.js -n public --source-map-support --time
|
||||
echo -e "监控服务启动成功...\n"
|
||||
|
||||
echo -e "======================6. 启动主服务========================\n"
|
||||
pm2 delete panel &>/dev/null
|
||||
pm2 start $dir_static/build/app.js -n panel --source-map-support --time
|
||||
echo -e "主服务启动成功...\n"
|
||||
|
||||
if [[ $AutoStartBot == true ]]; then
|
||||
echo -e "======================7. 启动bot========================\n"
|
||||
nohup ql -l bot >$dir_log/bot.log 2>&1 &
|
||||
echo -e "bot后台启动中...\n"
|
||||
fi
|
||||
echo -e "======================4. 启动pm2服务========================\n"
|
||||
reload_pm2
|
||||
|
||||
if [[ $EnableExtraShell == true ]]; then
|
||||
echo -e "======================8. 执行自定义脚本========================\n"
|
||||
echo -e "====================5. 执行自定义脚本========================\n"
|
||||
nohup ql -l extra >$dir_log/extra.log 2>&1 &
|
||||
echo -e "自定义脚本后台执行中...\n"
|
||||
fi
|
||||
|
||||
echo -e "############################################################\n"
|
||||
echo -e "容器启动成功..."
|
||||
echo -e "\n请先访问5700端口,登录成功面板之后再执行添加定时任务..."
|
||||
echo -e "############################################################\n"
|
||||
|
||||
crond -f >/dev/null
|
||||
|
|
31
ecosystem.config.js
Normal file
31
ecosystem.config.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
module.exports = {
|
||||
apps: [
|
||||
{
|
||||
name: 'schedule',
|
||||
max_restarts: 10,
|
||||
kill_timeout: 15000,
|
||||
wait_ready: true,
|
||||
source_map_support: true,
|
||||
time: true,
|
||||
script: 'static/build/schedule/index.js',
|
||||
},
|
||||
{
|
||||
name: 'public',
|
||||
max_restarts: 10,
|
||||
kill_timeout: 15000,
|
||||
wait_ready: true,
|
||||
source_map_support: true,
|
||||
time: true,
|
||||
script: 'static/build/public.js',
|
||||
},
|
||||
{
|
||||
name: 'panel',
|
||||
max_restarts: 10,
|
||||
kill_timeout: 15000,
|
||||
wait_ready: true,
|
||||
source_map_support: true,
|
||||
time: true,
|
||||
script: 'static/build/app.js',
|
||||
},
|
||||
],
|
||||
};
|
|
@ -74,12 +74,6 @@ check_pm2() {
|
|||
fi
|
||||
}
|
||||
|
||||
start_public() {
|
||||
echo -e "=====> 启动公开服务\n"
|
||||
pm2 delete public --source-map-support --time &>/dev/null
|
||||
pm2 start $dir_static/build/public.js -n public --source-map-support --time &>/dev/null
|
||||
}
|
||||
|
||||
main() {
|
||||
echo -e "=====> 开始检测"
|
||||
npm i -g pnpm@8.3.1
|
||||
|
@ -97,7 +91,6 @@ main() {
|
|||
|
||||
pnpm add -g pm2 tsx
|
||||
reset_env
|
||||
start_public
|
||||
copy_dep
|
||||
check_ql
|
||||
check_nginx
|
||||
|
|
|
@ -18,6 +18,7 @@ dir_update_log=$dir_log/update
|
|||
ql_static_repo=$dir_repo/static
|
||||
|
||||
## 文件
|
||||
file_ecosystem_js=$dir_root/ecosystem.config.js
|
||||
file_config_sample=$dir_sample/config.sample.sh
|
||||
file_env=$dir_config/env.sh
|
||||
file_sharecode=$dir_config/sharecode.sh
|
||||
|
@ -316,6 +317,8 @@ git_pull_scripts() {
|
|||
echo -e "开始更新仓库:$dir_work"
|
||||
|
||||
local pre_commit_id=$(git rev-parse --short HEAD)
|
||||
reset_branch "$branch"
|
||||
|
||||
set_proxy "$proxy"
|
||||
git fetch --depth=1 --all
|
||||
git pull --depth=1 &>/dev/null
|
||||
|
@ -353,10 +356,10 @@ reset_branch() {
|
|||
local part_cmd="HEAD"
|
||||
if [[ $branch ]]; then
|
||||
part_cmd="origin/${branch}"
|
||||
git checkout -B "$branch" &>/dev/null
|
||||
git branch --set-upstream-to=$part_cmd $branch &>/dev/null
|
||||
git remote set-branches --add origin $branch &>/dev/null
|
||||
fi
|
||||
git reset --hard $part_cmd &>/dev/null
|
||||
git checkout --track $part_cmd &>/dev/null
|
||||
}
|
||||
|
||||
random_range() {
|
||||
|
@ -366,16 +369,9 @@ random_range() {
|
|||
}
|
||||
|
||||
reload_pm2() {
|
||||
pm2 l &>/dev/null
|
||||
cd $dir_root
|
||||
pm2 flush &>/dev/null
|
||||
|
||||
echo -e "启动面板服务\n"
|
||||
pm2 delete panel --source-map-support --time &>/dev/null
|
||||
pm2 start $dir_static/build/app.js -n panel --source-map-support --time &>/dev/null
|
||||
|
||||
echo -e "启动定时服务\n"
|
||||
pm2 delete schedule --source-map-support --time &>/dev/null
|
||||
pm2 start $dir_static/build/schedule/index.js -n schedule --source-map-support --time &>/dev/null
|
||||
pm2 startOrGracefulReload $file_ecosystem_js
|
||||
}
|
||||
|
||||
diff_time() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user