pm2-rust/instruction.md
2025-01-13 17:08:11 +08:00

50 lines
3.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# AI Instruction
1.
在当前文件夹下创建rust工程编写 pmr 命令行工具,用于守护进程的管理:
1. 支持windowns、Linux、MacOS
2. 支持命令直接启动,例如 pmr start --name [别名] [程序名] -- [参数]
3. 支持配置文件启动,例如 pmr start --config config.json:
{
"name": "test",
"program": "python",
"args": ["-m", "test"]
}
4. 支持查看进程列表,例如 pmr listalias命令ls在终端显示列表例如┌────┬───────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├────┼───────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ naive │ default │ N/A │ fork │ 1492097 │ 22h │ 39 │ online │ 0% │ 8.1mb │ root │ disabled │
│ 1 │ naive-http │ default │ N/A │ fork │ 1492102 │ 22h │ 9 │ online │ 0% │ 8.3mb │ root │ disabled │
└────┴───────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
5.
每次执行pmr命令检查用户目录下是否有.pmr 文件夹如果没有则创建并在文件夹下创建dump.json文件用于管理使用pmr命令启动的进程例如:
[
{
"id": 1,
"name": "test",
"program": "python",
"args": ["-m", "test"]
},
{
"id": 2,
"name": "test2",
"program": "python",
"args": ["-m", "test2"]
}
]
修改listls命令添加参数 --system用于显示系统所有进程如果不添加该参数只显示在~/.pmr/dump.json中的进程
增加stop命令用于关闭指定进程例如pmr stop 1关闭~/.pmr/dump.json中id为1的进程或者pmr stop test关闭~/.pmr/dump.json中name为test的进程
6.
验证start命令成功执行notepad程序后相关信息是否写入dump.json并且执行stop命令能正常结束进程
7.继续修改pmr start命令使得以下几种方式均可成功
pmr start pmr_id // 启动存在于dump.json中的进程
pmr start name // 启动存在于dump.json中的进程
pmr start --config config.json // 从配置文件启动进程
pmr start program_name // 从程序启动进程
8.增加pmr stop命令用于关闭指定进程例如pmr stop 1关闭~/.pmr/dump.json中id为1的进程或者pmr stop test关闭~/.pmr/dump.json中name为test的进程
9.增加命令restart, 例如 pmr restart 1重启~/.pmr/dump.json中id为1的进程或者pmr restart test重启~/.pmr/dump.json中name为test的进程, pmr restart --config config.json, 从配置文件重启进程