onebots 1.0.0 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/adapter-schema-presets.d.ts +8 -0
- package/lib/adapter-schema-presets.js +118 -0
- package/lib/app.d.ts +20 -0
- package/lib/app.js +711 -30
- package/lib/bin.js +2 -36
- package/lib/cli.d.ts +2 -0
- package/lib/cli.js +293 -0
- package/lib/config-schema.d.ts +9 -0
- package/lib/config-schema.js +81 -0
- package/lib/daemon.d.ts +30 -0
- package/lib/daemon.js +94 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/service-manager.d.ts +4 -0
- package/lib/service-manager.js +171 -0
- package/package.json +10 -5
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 网关系统服务:systemd / launchd / Windows
|
|
3
|
+
*/
|
|
4
|
+
import * as fs from "fs";
|
|
5
|
+
import * as path from "path";
|
|
6
|
+
import { execSync } from "child_process";
|
|
7
|
+
const SERVICE_NAME = "onebots-gateway";
|
|
8
|
+
function getConfigDir(configPath) {
|
|
9
|
+
return path.dirname(path.resolve(process.cwd(), configPath));
|
|
10
|
+
}
|
|
11
|
+
export async function serviceInstall(configPath) {
|
|
12
|
+
const configDir = getConfigDir(configPath);
|
|
13
|
+
const resolvedConfig = path.resolve(process.cwd(), configPath);
|
|
14
|
+
const nodePath = process.execPath;
|
|
15
|
+
const binPath = process.argv[1];
|
|
16
|
+
const startCmd = `"${nodePath}" "${binPath}" gateway start -c "${resolvedConfig}"`;
|
|
17
|
+
if (process.platform === "darwin") {
|
|
18
|
+
const plistPath = path.join(process.env.HOME, "Library", "LaunchAgents", `com.onebots.${SERVICE_NAME}.plist`);
|
|
19
|
+
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
20
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
21
|
+
<plist version="1.0">
|
|
22
|
+
<dict>
|
|
23
|
+
<key>Label</key>
|
|
24
|
+
<string>com.onebots.${SERVICE_NAME}</string>
|
|
25
|
+
<key>ProgramArguments</key>
|
|
26
|
+
<array>
|
|
27
|
+
<string>${nodePath}</string>
|
|
28
|
+
<string>${binPath}</string>
|
|
29
|
+
<string>gateway</string>
|
|
30
|
+
<string>start</string>
|
|
31
|
+
<string>-c</string>
|
|
32
|
+
<string>${resolvedConfig}</string>
|
|
33
|
+
</array>
|
|
34
|
+
<key>WorkingDirectory</key>
|
|
35
|
+
<string>${configDir}</string>
|
|
36
|
+
<key>RunAtLoad</key>
|
|
37
|
+
<true/>
|
|
38
|
+
<key>KeepAlive</key>
|
|
39
|
+
<dict>
|
|
40
|
+
<key>SuccessfulExit</key>
|
|
41
|
+
<false/>
|
|
42
|
+
</dict>
|
|
43
|
+
</dict>
|
|
44
|
+
</plist>
|
|
45
|
+
`;
|
|
46
|
+
const dir = path.dirname(plistPath);
|
|
47
|
+
if (!fs.existsSync(dir))
|
|
48
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
49
|
+
fs.writeFileSync(plistPath, plist, "utf8");
|
|
50
|
+
console.log("已安装 launchd 服务:", plistPath);
|
|
51
|
+
console.log("启用: launchctl load " + plistPath);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (process.platform === "linux") {
|
|
55
|
+
const unitDir = path.join(process.env.HOME, ".config", "systemd", "user");
|
|
56
|
+
if (!fs.existsSync(unitDir))
|
|
57
|
+
fs.mkdirSync(unitDir, { recursive: true });
|
|
58
|
+
const unitPath = path.join(unitDir, `${SERVICE_NAME}.service`);
|
|
59
|
+
const unit = `[Unit]
|
|
60
|
+
Description=OneBots Gateway
|
|
61
|
+
After=network.target
|
|
62
|
+
|
|
63
|
+
[Service]
|
|
64
|
+
Type=simple
|
|
65
|
+
WorkingDirectory=${configDir}
|
|
66
|
+
ExecStart=${nodePath} ${binPath} gateway start -c ${resolvedConfig}
|
|
67
|
+
Restart=on-failure
|
|
68
|
+
RestartSec=5
|
|
69
|
+
|
|
70
|
+
[Install]
|
|
71
|
+
WantedBy=default.target
|
|
72
|
+
`;
|
|
73
|
+
fs.writeFileSync(unitPath, unit, "utf8");
|
|
74
|
+
console.log("已安装 systemd 用户服务:", unitPath);
|
|
75
|
+
try {
|
|
76
|
+
execSync("systemctl --user daemon-reload", { stdio: "inherit" });
|
|
77
|
+
console.log("启用: systemctl --user enable --now " + SERVICE_NAME);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
console.log("请执行: systemctl --user daemon-reload && systemctl --user enable --now " + SERVICE_NAME);
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (process.platform === "win32") {
|
|
85
|
+
console.log("Windows 请使用 onebots gateway daemon 配合「任务计划程序」实现开机自启:");
|
|
86
|
+
console.log(" 1. 打开 任务计划程序");
|
|
87
|
+
console.log(" 2. 创建基本任务,触发器选「计算机启动时」");
|
|
88
|
+
console.log(" 3. 操作:启动程序");
|
|
89
|
+
console.log(" 程序/脚本: " + nodePath);
|
|
90
|
+
console.log(" 添加参数: " + [binPath, "gateway", "daemon", "-c", resolvedConfig].map((a) => `"${a}"`).join(" "));
|
|
91
|
+
console.log(" 起始于: " + configDir);
|
|
92
|
+
process.exit(0);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
console.error("当前系统暂不支持 service install");
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
export async function serviceUninstall() {
|
|
99
|
+
if (process.platform === "darwin") {
|
|
100
|
+
const plistPath = path.join(process.env.HOME, "Library", "LaunchAgents", `com.onebots.${SERVICE_NAME}.plist`);
|
|
101
|
+
try {
|
|
102
|
+
execSync(`launchctl unload "${plistPath}"`, { stdio: "inherit" });
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
// ignore
|
|
106
|
+
}
|
|
107
|
+
if (fs.existsSync(plistPath)) {
|
|
108
|
+
fs.unlinkSync(plistPath);
|
|
109
|
+
console.log("已卸载 launchd 服务");
|
|
110
|
+
}
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (process.platform === "linux") {
|
|
114
|
+
const unitPath = path.join(process.env.HOME, ".config", "systemd", "user", `${SERVICE_NAME}.service`);
|
|
115
|
+
try {
|
|
116
|
+
execSync("systemctl --user disable " + SERVICE_NAME, { stdio: "inherit" });
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// ignore
|
|
120
|
+
}
|
|
121
|
+
if (fs.existsSync(unitPath)) {
|
|
122
|
+
fs.unlinkSync(unitPath);
|
|
123
|
+
console.log("已卸载 systemd 服务");
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
execSync("systemctl --user daemon-reload", { stdio: "inherit" });
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
// ignore
|
|
130
|
+
}
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (process.platform === "win32") {
|
|
134
|
+
console.log("Windows 请在「任务计划程序」中手动删除对应任务");
|
|
135
|
+
process.exit(0);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
console.error("当前系统暂不支持 service uninstall");
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
export async function serviceStatus() {
|
|
142
|
+
if (process.platform === "darwin") {
|
|
143
|
+
try {
|
|
144
|
+
const out = execSync("launchctl list | grep onebots", { encoding: "utf8" });
|
|
145
|
+
console.log(out || "未找到 onebots 服务");
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
console.log("未找到 onebots 服务或未加载");
|
|
149
|
+
}
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (process.platform === "linux") {
|
|
153
|
+
try {
|
|
154
|
+
execSync("systemctl --user status " + SERVICE_NAME, { stdio: "inherit" });
|
|
155
|
+
}
|
|
156
|
+
catch (e) {
|
|
157
|
+
const code = e?.status;
|
|
158
|
+
if (code !== 0)
|
|
159
|
+
console.log("服务未运行或未安装");
|
|
160
|
+
}
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (process.platform === "win32") {
|
|
164
|
+
console.log("Windows 请在「任务计划程序」中查看任务状态");
|
|
165
|
+
process.exit(0);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
console.error("当前系统暂不支持 service status");
|
|
169
|
+
process.exit(1);
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=service-manager.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onebots",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "OneBots 整合适配器和协议,提供HTTP/WebSocket服务",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"/lib/**/*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@types/node": "^22.0.0",
|
|
34
|
-
"@types/koa-static": "^4.0.4",
|
|
35
33
|
"@types/koa": "^3.0.1",
|
|
34
|
+
"@types/koa-static": "^4.0.4",
|
|
35
|
+
"@types/node": "^22.0.0",
|
|
36
36
|
"tsc-alias": "latest",
|
|
37
37
|
"tsconfig-paths": "latest",
|
|
38
38
|
"tsx": "latest",
|
|
@@ -40,9 +40,14 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@karinjs/node-pty": "^1.1.3",
|
|
43
|
+
"commander": "^14.0.3",
|
|
43
44
|
"koa-static": "^5.0.0",
|
|
44
|
-
"@onebots/
|
|
45
|
-
"@onebots/
|
|
45
|
+
"@onebots/core": "1.0.4",
|
|
46
|
+
"@onebots/web": "1.0.5"
|
|
47
|
+
},
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/lc-cn/onebots.git"
|
|
46
51
|
},
|
|
47
52
|
"scripts": {
|
|
48
53
|
"start": "node lib/bin.js",
|