bm2 1.0.21 → 1.0.23

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bm2",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
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",
@@ -15,7 +15,8 @@
15
15
  */
16
16
 
17
17
  import { join } from "path";
18
-
18
+ import { $ } from "bun";
19
+
19
20
  export class StartupManager {
20
21
  async generate(platform?: string): Promise<string> {
21
22
  const os = platform || process.platform;
@@ -34,39 +35,41 @@
34
35
  }
35
36
 
36
37
  private generateSystemd(bunPath: string, bm2Path: string, daemonPath: string): string {
38
+
37
39
  const unit = `[Unit]
38
- Description=BM2 Process Manager
39
- Documentation=https://github.com/bm2
40
- After=network.target
41
-
42
- [Service]
43
- Type=forking
44
- User=${process.env.USER || "root"}
45
- LimitNOFILE=infinity
46
- LimitNPROC=infinity
47
- LimitCORE=infinity
48
- Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${join(bunPath, "..")}
49
- Environment=BM2_HOME=${join(process.env.HOME || "/root", ".bm2")}
50
- PIDFile=${join(process.env.HOME || "/root", ".bm2", "daemon.pid")}
51
- Restart=on-failure
52
-
53
- ExecStart=${bunPath} run ${daemonPath}
54
- ExecReload=${bunPath} run ${bm2Path} reload all
55
- ExecStop=${bunPath} run ${bm2Path} kill
56
-
57
- [Install]
58
- WantedBy=multi-user.target`;
59
-
60
- const servicePath = "/etc/systemd/system/bm2.service";
61
- return `# BM2 Systemd Service
62
- # Save to: ${servicePath}
63
- # Then run:
64
- # sudo systemctl daemon-reload
65
- # sudo systemctl enable bm2
66
- # sudo systemctl start bm2
67
-
68
- ${unit}`;
69
- }
40
+ Description=BM2 Process Manager
41
+ Documentation=https://github.com/bm2
42
+ After=network.target
43
+
44
+ [Service]
45
+ Type=simple
46
+ User=${process.env.USER || "root"}
47
+ LimitNOFILE=infinity
48
+ LimitNPROC=infinity
49
+ LimitCORE=infinity
50
+ Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${join(bunPath, "..")}
51
+ Environment=BM2_HOME=${join(process.env.HOME || "/root", ".bm2")}
52
+ Restart=on-failure
53
+
54
+ ExecStart=${bunPath} run ${daemonPath}
55
+ ExecStartPost=${bunPath} run ${bm2Path} resurrect
56
+ ExecReload=${bunPath} run ${bm2Path} reload all
57
+ ExecStop=${bunPath} run ${bm2Path} kill
58
+
59
+ [Install]
60
+ WantedBy=multi-user.target
61
+ `;
62
+
63
+ const servicePath = "/etc/systemd/system/bm2.service";
64
+ return `# BM2 Systemd Service
65
+ # Save to: ${servicePath}
66
+ # Then run:
67
+ # sudo systemctl daemon-reload
68
+ # sudo systemctl enable bm2
69
+ # sudo systemctl start bm2
70
+
71
+ ${unit}`;
72
+ }
70
73
 
71
74
  private generateLaunchd(bunPath: string, bm2Path: string, daemonPath: string): string {
72
75
  const plist = `<?xml version="1.0" encoding="UTF-8"?>
@@ -99,29 +102,41 @@
99
102
  </dict>
100
103
  </plist>`;
101
104
 
102
- const plistPath = `${process.env.HOME}/Library/LaunchAgents/com.bm2.daemon.plist`;
103
- return `# BM2 LaunchAgent (macOS)
104
- # Save to: ${plistPath}
105
- # Then run:
106
- # launchctl load ${plistPath}
105
+ const plistPath = `${process.env.HOME}/Library/LaunchAgents/com.bm2.daemon.plist`;
106
+
107
+ return `# BM2 LaunchAgent (macOS)
108
+ # Save to: ${plistPath}
109
+ # Then run:
110
+ # launchctl load ${plistPath}
107
111
 
108
- ${plist}`;
109
- }
112
+ ${plist}`;
113
+ }
110
114
 
111
115
  async install(): Promise<string> {
112
116
  const os = process.platform;
113
117
  const content = await this.generate(os);
114
118
 
115
119
  if (os === "linux") {
120
+
116
121
  const servicePath = "/etc/systemd/system/bm2.service";
117
- // Extract just the unit content
118
- const unitContent = content.split("\n\n").slice(1).join("\n\n");
119
- await Bun.write(servicePath, unitContent);
120
-
121
- Bun.spawn(["sudo", "systemctl", "daemon-reload"], { stdout: "inherit" });
122
- Bun.spawn(["sudo", "systemctl", "enable", "bm2"], { stdout: "inherit" });
123
-
124
- return `Service installed at ${servicePath}\nRun: sudo systemctl start bm2`;
122
+
123
+ const unitStart = content.indexOf("[Unit]");
124
+ const unitContent = content.substring(unitStart);
125
+
126
+ try {
127
+ await Bun.write(servicePath, unitContent);
128
+ } catch {
129
+ return "Failed to create the service file. Please ensure you have sufficient permissions (try running with sudo).";
130
+ }
131
+
132
+ // Bun.spawn(["sudo", "systemctl", "daemon-reload"], { stdout: "inherit" }).exited;
133
+ // Bun.spawn(["sudo", "systemctl", "enable", "bm2"], { stdout: "inherit" }).exited;
134
+
135
+ await $`systemctl daemon-reload`;
136
+ await $`systemctl enable bm2`;
137
+ await $`systemctl start bm2`;
138
+
139
+ return `Service installed at ${servicePath}`;
125
140
  } else if (os === "darwin") {
126
141
  const plistPath = `${process.env.HOME}/Library/LaunchAgents/com.bm2.daemon.plist`;
127
142
  // Extract plist content
@@ -139,17 +154,21 @@
139
154
  const os = process.platform;
140
155
 
141
156
  if (os === "linux") {
142
- Bun.spawn(["sudo", "systemctl", "stop", "bm2"], { stdout: "inherit" });
143
- Bun.spawn(["sudo", "systemctl", "disable", "bm2"], { stdout: "inherit" });
144
- const { unlinkSync } = require("fs");
145
- try { unlinkSync("/etc/systemd/system/bm2.service"); } catch {}
146
- Bun.spawn(["sudo", "systemctl", "daemon-reload"], { stdout: "inherit" });
157
+
158
+ await $`systemctl stop bm2`;
159
+ await $`systemctl disable bm2`;
160
+
161
+ await $`rm -f /etc/systemd/system/bm2.service`;
162
+ await $`systemctl daemon-reload`;
163
+
147
164
  return "BM2 service removed";
165
+
148
166
  } else if (os === "darwin") {
167
+
149
168
  const plistPath = `${process.env.HOME}/Library/LaunchAgents/com.bm2.daemon.plist`;
150
- Bun.spawn(["launchctl", "unload", plistPath], { stdout: "inherit" });
151
- const { unlinkSync } = require("fs");
152
- try { unlinkSync(plistPath); } catch {}
169
+
170
+ await $`launchctl unload ${plistPath}`;
171
+ await $`rm -f ${plistPath}`;
153
172
  return "BM2 launch agent removed";
154
173
  }
155
174