bm2 1.0.9 → 1.0.11
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/README.md +4 -5
- package/package.json +1 -1
- package/src/daemon.ts +59 -27
package/README.md
CHANGED
|
@@ -5,13 +5,12 @@ The modern PM2 replacement — zero Node.js dependencies, pure Bun performance.
|
|
|
5
5
|
|
|
6
6
|

|
|
7
7
|

|
|
8
|
-

|
|
8
|
+

|
|
10
9
|
[](https://github.com/bun-bm2/bm2/actions/workflows/test.yml)
|
|
11
10
|
|
|
12
11
|
**Created by the MaxxPainn Team**
|
|
13
12
|
🌐 [https://maxxpainn.com](https://maxxpainn.com)
|
|
14
|
-
📧 Support: [
|
|
13
|
+
📧 Support: [zak@maxxpainn.com](mailto:zak@maxxpainn.com)
|
|
15
14
|
|
|
16
15
|
---
|
|
17
16
|
|
|
@@ -1575,7 +1574,7 @@ bun test
|
|
|
1575
1574
|
|
|
1576
1575
|
## License
|
|
1577
1576
|
|
|
1578
|
-
|
|
1577
|
+
GPL-3.0-only
|
|
1579
1578
|
|
|
1580
1579
|
Copyright (c) 2025 MaxxPainn Team
|
|
1581
1580
|
|
|
@@ -1588,4 +1587,4 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
1588
1587
|
---
|
|
1589
1588
|
|
|
1590
1589
|
**Built with ❤️ by the [MaxxPainn Team](https://maxxpainn.com)**
|
|
1591
|
-
📧 Support: [
|
|
1590
|
+
📧 Support: [zak@maxxpainn.com](mailto:zak@maxxpainn.com)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bm2",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "A blazing-fast, full-featured process manager built entirely on Bun native APIs. The modern PM2 replacement — zero Node.js dependencies, pure Bun performance.",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"module": "src/index.ts",
|
package/src/daemon.ts
CHANGED
|
@@ -26,9 +26,11 @@ import {
|
|
|
26
26
|
import { ensureDirs } from "./utils";
|
|
27
27
|
import { unlinkSync, existsSync } from "fs";
|
|
28
28
|
import type { DaemonMessage, DaemonResponse } from "./types";
|
|
29
|
+
import type { BunRequest, Server } from "bun";
|
|
29
30
|
|
|
30
31
|
ensureDirs();
|
|
31
32
|
|
|
33
|
+
let server: Server<any> | null = null
|
|
32
34
|
const pm = new ProcessManager();
|
|
33
35
|
const dashboard = new Dashboard(pm);
|
|
34
36
|
const moduleManager = new ModuleManager(pm);
|
|
@@ -49,6 +51,37 @@ const metricsInterval = setInterval(() => {
|
|
|
49
51
|
pm.getMetrics();
|
|
50
52
|
}, 2000);
|
|
51
53
|
|
|
54
|
+
|
|
55
|
+
const handleServerRequests = async (req: Request) => {
|
|
56
|
+
|
|
57
|
+
if (req.method !== "POST") {
|
|
58
|
+
return Response.json(
|
|
59
|
+
{ type: "error", error: "Method Not Allowed", success: false },
|
|
60
|
+
{ status: 405 }
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
|
|
66
|
+
const msg: DaemonMessage = await req.json() as DaemonMessage;
|
|
67
|
+
|
|
68
|
+
const response = await handleMessage(msg);
|
|
69
|
+
|
|
70
|
+
return Response.json(response);
|
|
71
|
+
|
|
72
|
+
} catch (err: any) {
|
|
73
|
+
return Response.json(
|
|
74
|
+
{ type: "error", error: err.message, success: false },
|
|
75
|
+
{ status: 500 }
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const serverOptions = {
|
|
81
|
+
unix: DAEMON_SOCKET,
|
|
82
|
+
fetch: handleServerRequests
|
|
83
|
+
}
|
|
84
|
+
|
|
52
85
|
async function handleMessage(msg: DaemonMessage): Promise<DaemonResponse> {
|
|
53
86
|
try {
|
|
54
87
|
switch (msg.type) {
|
|
@@ -156,9 +189,33 @@ async function handleMessage(msg: DaemonMessage): Promise<DaemonResponse> {
|
|
|
156
189
|
await moduleManager.uninstall(msg.data.module);
|
|
157
190
|
return { type: "moduleUninstall", success: true, id: msg.id };
|
|
158
191
|
}
|
|
192
|
+
|
|
159
193
|
case "moduleList": {
|
|
160
194
|
return { type: "moduleList", data: moduleManager.list(), success: true, id: msg.id };
|
|
161
195
|
}
|
|
196
|
+
|
|
197
|
+
case "daemonStart": {
|
|
198
|
+
let status = (server) ? "Active": "Stopped"
|
|
199
|
+
return { type: "daemonStart", success: true, data: { status }, id: msg.id };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
case "daemonStart": {
|
|
203
|
+
if (!server) {
|
|
204
|
+
server = Bun.serve(serverOptions);
|
|
205
|
+
console.log(`Listening on ${server.url}`);
|
|
206
|
+
}
|
|
207
|
+
return { type: "daemonStart", success: true, id: msg.id };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
case "daemonStop": {
|
|
211
|
+
server?.stop();
|
|
212
|
+
return { type: "daemonStop", success: true, id: msg.id };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
case "daemonReload": {
|
|
216
|
+
return { type: "daemonReload", success: true, id: msg.id };
|
|
217
|
+
}
|
|
218
|
+
|
|
162
219
|
case "ping": {
|
|
163
220
|
return {
|
|
164
221
|
type: "pong",
|
|
@@ -167,6 +224,7 @@ async function handleMessage(msg: DaemonMessage): Promise<DaemonResponse> {
|
|
|
167
224
|
id: msg.id,
|
|
168
225
|
};
|
|
169
226
|
}
|
|
227
|
+
|
|
170
228
|
case "kill": {
|
|
171
229
|
await pm.stopAll();
|
|
172
230
|
dashboard.stop();
|
|
@@ -183,32 +241,6 @@ async function handleMessage(msg: DaemonMessage): Promise<DaemonResponse> {
|
|
|
183
241
|
}
|
|
184
242
|
|
|
185
243
|
|
|
186
|
-
|
|
187
|
-
unix: DAEMON_SOCKET,
|
|
188
|
-
async fetch(req) {
|
|
189
|
-
|
|
190
|
-
if (req.method !== "POST") {
|
|
191
|
-
return Response.json(
|
|
192
|
-
{ type: "error", error: "Method Not Allowed", success: false },
|
|
193
|
-
{ status: 405 }
|
|
194
|
-
)
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
try {
|
|
198
|
-
|
|
199
|
-
const msg: DaemonMessage = await req.json() as DaemonMessage;
|
|
200
|
-
|
|
201
|
-
const response = await handleMessage(msg);
|
|
202
|
-
|
|
203
|
-
return Response.json(response);
|
|
204
|
-
|
|
205
|
-
} catch (err: any) {
|
|
206
|
-
return Response.json(
|
|
207
|
-
{ type: "error", error: err.message, success: false },
|
|
208
|
-
{ status: 500 }
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
},
|
|
212
|
-
});
|
|
244
|
+
server = Bun.serve(serverOptions);
|
|
213
245
|
|
|
214
246
|
console.log(`Listening on ${server.url}`);
|