feat: 增加进程托管

This commit is contained in:
ningmengchongshui 2024-06-10 00:37:59 +08:00
parent d2b2673fc4
commit 6b2e4a0738
4 changed files with 56 additions and 25 deletions

View File

@ -10,9 +10,9 @@
> 必要环境 Windows/Linux + Chrome/Chromium/Edge
> 必要环境 18.18.2>Node.js>16.14.0 + Redis>5.0.0
> 必要环境 Node.js>16.14.0 + Redis>5.0.0
如果你的系统不支持18.18.2版本最低能下载16.14.0版本这是最新的puppeteer版本限制。
推荐使用`18.18.2`版本,如果系统不支持,最低要求`16.14.0`,这是新版`puppeteer`的限制
## 开发者
@ -49,29 +49,23 @@ pnpm install
- 启动
```sh
npm run ts:app
npm run app
```
- 重新登录
```sh
npm run ts:app login
npm run app login
```
> 暂不支持PM2托管进程
## Unknown file ".ts"
node >= 20.0.0
- 启动
- 进程托管
```sh
npm run latest:app
npm run start
```
- 重新登录
- 杀死进程
```sh
npm run latest:app login
npm run kill
```

25
index.js Normal file
View File

@ -0,0 +1,25 @@
import { spawn } from 'child_process'
const argv = [...process.argv].splice(2)
const argvs = argv.join(' ').replace(/(\S+\.js|\S+\.ts)/g, '')
/**
* ***************
* 启动内部运行脚本
* ***************
*/
const child = spawn(
'node --no-warnings=ExperimentalWarning --loader ts-node/esm src/main.ts',
argvs.split(' '),
{
shell: true,
stdio: 'inherit'
}
)
/**
* *************
* exit
* *************
*/
process.on('SIGINT', () => {
if (child.pid) process.kill(child.pid)
if (process.pid) process.exit()
})

View File

@ -3,19 +3,19 @@
"version": "4.0.0-rc.0",
"author": "Yoimiya-Kokomi, Le-niao",
"description": "QQ Group Bot",
"main": "app.js",
"main": "./index.js",
"type": "module",
"scripts": {
"app": "node .",
"login": "node . login",
"start": "pm2 start ./config/pm2/pm2.json",
"stop": "pm2 stop ./config/pm2/pm2.json",
"restart": "pm2 restart ./config/pm2/pm2.json",
"ts:app": "ts-node src/main.ts",
"ts:login": "ts-node src/main.ts login",
"ts:build": "rollup --config rollup.config.js",
"latest:app": "node --no-warnings=ExperimentalWarning --loader ts-node/esm src/main.ts",
"latest:login": "node --no-warnings=ExperimentalWarning --loader ts-node/esm src/main.ts login",
"app": "node index.js",
"login": "node index.js login",
"build": "rollup --config rollup.config.js",
"start": "pm2 startOrRestart pm2.config.cjs",
"stop": "pm2 stop pm2.config.cjs",
"delete": "pm2 delete pm2.config.cjs",
"kill": "pm2 kill",
"logs": "pm2 logs",
"monit": "pm2 monit",
"pm2": "pm2",
"docs": "typedoc --options typedoc.json",
"format": "prettier --write .",
"prepare": "husky"

12
pm2.config.cjs Normal file
View File

@ -0,0 +1,12 @@
const argv = [...process.argv].slice(4)
module.exports = {
apps: [
{
name: 'Miao-Yunzai',
script: './index.js',
args: argv,
max_memory_restart: '512M',
restart_delay: 60000
}
]
}