bm2 1.0.34 → 1.0.35
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/package.json +1 -1
- package/src/index.ts +47 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bm2",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.35",
|
|
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/api.ts",
|
|
6
6
|
"module": "src/api.ts",
|
package/src/index.ts
CHANGED
|
@@ -52,6 +52,7 @@ ensureDirs();
|
|
|
52
52
|
// Daemon communication helpers
|
|
53
53
|
// ---------------------------------------------------------------------------
|
|
54
54
|
|
|
55
|
+
|
|
55
56
|
function isDaemonRunning(): boolean {
|
|
56
57
|
if (!existsSync(DAEMON_PID_FILE)) return false;
|
|
57
58
|
try {
|
|
@@ -99,6 +100,25 @@ async function startDaemon(): Promise<void> {
|
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
|
|
103
|
+
async function stopDaemon(): Promise<void> {
|
|
104
|
+
try {
|
|
105
|
+
|
|
106
|
+
if (!isDaemonRunning()) return;
|
|
107
|
+
|
|
108
|
+
const pidText = await Bun.file(DAEMON_PID_FILE).text();
|
|
109
|
+
const pid = Number(pidText);
|
|
110
|
+
|
|
111
|
+
process.kill(pid, "SIGTERM"); // graceful stop
|
|
112
|
+
|
|
113
|
+
console.error("Daemon stopped");
|
|
114
|
+
|
|
115
|
+
// cleanup
|
|
116
|
+
await Bun.write(DAEMON_PID_FILE, "");
|
|
117
|
+
} catch (err) {
|
|
118
|
+
console.error("Failed to stop daemon:", err);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
102
122
|
async function sendToDaemon(msg: DaemonMessage): Promise<DaemonResponse> {
|
|
103
123
|
|
|
104
124
|
//start the daemon
|
|
@@ -853,29 +873,42 @@ async function cmdModule(args: string[]) {
|
|
|
853
873
|
}
|
|
854
874
|
|
|
855
875
|
async function cmdDaemon(args: string[]) {
|
|
876
|
+
|
|
877
|
+
|
|
878
|
+
const daemonStatus = () => {
|
|
879
|
+
if (isDaemonRunning()) {
|
|
880
|
+
console.log(colorize("running", "green"));
|
|
881
|
+
} else {
|
|
882
|
+
console.error(colorize("stopped", "red"));
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
process.exit(1);
|
|
886
|
+
}
|
|
887
|
+
|
|
856
888
|
const subCmd = args[0];
|
|
857
|
-
let type;
|
|
858
889
|
|
|
859
890
|
switch (subCmd) {
|
|
891
|
+
case "status":
|
|
892
|
+
daemonStatus();
|
|
893
|
+
break;
|
|
894
|
+
case "start":
|
|
895
|
+
await startDaemon();
|
|
896
|
+
process.exit(1);
|
|
897
|
+
break
|
|
898
|
+
case "stop":
|
|
899
|
+
await stopDaemon();
|
|
900
|
+
process.exit(1);
|
|
901
|
+
break;
|
|
860
902
|
case "reload":
|
|
861
|
-
|
|
903
|
+
await stopDaemon();
|
|
904
|
+
await startDaemon();
|
|
905
|
+
process.exit(1);
|
|
862
906
|
break;
|
|
863
907
|
default:
|
|
864
|
-
console.error(colorize("Usage: bm2 daemon <reload>", "red"));
|
|
908
|
+
console.error(colorize("Usage: bm2 daemon <status|start|stop|reload>", "red"));
|
|
865
909
|
process.exit(1);
|
|
866
910
|
}
|
|
867
|
-
|
|
868
|
-
const res = await sendToDaemon({ type });
|
|
869
911
|
|
|
870
|
-
if (res?.error) {
|
|
871
|
-
console.error(colorize(`Error: ${res.error}`, "red"));
|
|
872
|
-
process.exit(1);
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
console.log(colorize(res.data, "green"));
|
|
876
|
-
|
|
877
|
-
process.exit(1);
|
|
878
|
-
|
|
879
912
|
}
|
|
880
913
|
|
|
881
914
|
async function cmdPrometheus() {
|