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 +1 -1
- package/src/startup-manager.ts +75 -56
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bm2",
|
|
3
|
-
"version": "1.0.
|
|
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",
|
package/src/startup-manager.ts
CHANGED
|
@@ -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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
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
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
169
|
+
|
|
170
|
+
await $`launchctl unload ${plistPath}`;
|
|
171
|
+
await $`rm -f ${plistPath}`;
|
|
153
172
|
return "BM2 launch agent removed";
|
|
154
173
|
}
|
|
155
174
|
|