bs9 1.4.3 → 1.5.0
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 +41 -13
- package/bin/bs9 +33 -10
- package/dist/bs9-cbcmk6jy. +389 -0
- package/dist/bs9-cd3btjpw. +312 -0
- package/dist/bs9-hp4w75sv. +281 -0
- package/dist/bs9-nfpea7ta. +269 -0
- package/dist/bs9-ws85s3p9. +270 -0
- package/dist/bs9-xaw2xcxz. +270 -0
- package/dist/bs9-xf46r11y. +269 -0
- package/dist/bs9-zmxbnn8g. +255 -0
- package/dist/bs9.js +1 -1
- package/package.json +1 -1
- package/src/commands/delete.ts +79 -2
- package/src/commands/deploy.ts +1 -7
- package/src/commands/doctor.ts +332 -0
- package/src/commands/inspect.ts +603 -0
- package/src/commands/restart.ts +77 -1
- package/src/commands/start.ts +93 -1
- package/src/commands/status.ts +163 -110
- package/src/commands/stop.ts +77 -1
- package/src/utils/array-parser.ts +131 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { join, dirname } from "node:path";
|
|
6
|
+
|
|
7
|
+
// Read version from package.json
|
|
8
|
+
const packageJsonPath = join(dirname(import.meta.path), '..', 'package.json');
|
|
9
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
10
|
+
const version = packageJson.version;
|
|
11
|
+
|
|
12
|
+
import { startCommand } from "../src/commands/start.js";
|
|
13
|
+
import { stopCommand } from "../src/commands/stop.js";
|
|
14
|
+
import { restartCommand } from "../src/commands/restart.js";
|
|
15
|
+
import { statusCommand } from "../src/commands/status.js";
|
|
16
|
+
import { logsCommand } from "../src/commands/logs.js";
|
|
17
|
+
import { monitCommand } from "../src/commands/monit.js";
|
|
18
|
+
import { webCommand } from "../src/commands/web.js";
|
|
19
|
+
import { alertCommand } from "../src/commands/alert.js";
|
|
20
|
+
import { exportCommand } from "../src/commands/export.js";
|
|
21
|
+
import { depsCommand } from "../src/commands/deps.js";
|
|
22
|
+
import { profileCommand } from "../src/commands/profile.js";
|
|
23
|
+
import { deleteCommand } from "../src/commands/delete.js";
|
|
24
|
+
import { saveCommand } from "../src/commands/save.js";
|
|
25
|
+
import { resurrectCommand } from "../src/commands/resurrect.js";
|
|
26
|
+
import { deployCommand } from "../src/commands/deploy.js";
|
|
27
|
+
import { loadbalancerCommand } from "../src/loadbalancer/manager.js";
|
|
28
|
+
import { windowsCommand } from "../src/windows/service.js";
|
|
29
|
+
import { launchdCommand } from "../src/macos/launchd.js";
|
|
30
|
+
import { updateCommand } from "../src/commands/update.js";
|
|
31
|
+
import { dbpoolCommand } from "../src/database/pool.js";
|
|
32
|
+
import { advancedMonitoringCommand } from "../src/monitoring/advanced.js";
|
|
33
|
+
import { consulCommand } from "../src/discovery/consul.js";
|
|
34
|
+
import { doctorCommand } from "../src/commands/doctor.js";
|
|
35
|
+
|
|
36
|
+
const program = new Command();
|
|
37
|
+
|
|
38
|
+
program
|
|
39
|
+
.name("bs9")
|
|
40
|
+
.description("BS9 (Bun Sentinel 9) — Mission-critical process manager CLI")
|
|
41
|
+
.version(version);
|
|
42
|
+
|
|
43
|
+
program
|
|
44
|
+
.command("start")
|
|
45
|
+
.description("Start a process with hardened systemd unit")
|
|
46
|
+
.argument("<file>", "Application file to start")
|
|
47
|
+
.option("-n, --name <name>", "Service name")
|
|
48
|
+
.option("-p, --port <port>", "Port number", "3000")
|
|
49
|
+
.option("-h, --host <host>", "Host address", "localhost")
|
|
50
|
+
.option("--https", "Use HTTPS protocol")
|
|
51
|
+
.option("-e, --env <env>", "Environment variables (can be used multiple times)", (value, previous) => [...(previous || []), value])
|
|
52
|
+
.option("--otel", "Enable OpenTelemetry instrumentation", true)
|
|
53
|
+
.option("--prometheus", "Enable Prometheus metrics", true)
|
|
54
|
+
.option("--build", "Build TypeScript to JavaScript before starting")
|
|
55
|
+
.action(startCommand);
|
|
56
|
+
|
|
57
|
+
program
|
|
58
|
+
.command("stop")
|
|
59
|
+
.description("Stop a managed service")
|
|
60
|
+
.argument("<name>", "Service name")
|
|
61
|
+
.action(stopCommand);
|
|
62
|
+
|
|
63
|
+
program
|
|
64
|
+
.command("restart")
|
|
65
|
+
.description("Restart a managed service")
|
|
66
|
+
.argument("<name>", "Service name")
|
|
67
|
+
.action(restartCommand);
|
|
68
|
+
|
|
69
|
+
program
|
|
70
|
+
.command("status")
|
|
71
|
+
.description("Show status and SRE metrics for all services")
|
|
72
|
+
.option("-w, --watch", "Watch mode (refresh every 2s)")
|
|
73
|
+
.action(statusCommand);
|
|
74
|
+
|
|
75
|
+
program
|
|
76
|
+
.command("logs")
|
|
77
|
+
.description("Show logs for a service (via journalctl)")
|
|
78
|
+
.argument("<name>", "Service name")
|
|
79
|
+
.option("-f, --follow", "Follow logs")
|
|
80
|
+
.option("-n, --lines <number>", "Number of lines", "50")
|
|
81
|
+
.action(logsCommand);
|
|
82
|
+
|
|
83
|
+
program
|
|
84
|
+
.command("monit")
|
|
85
|
+
.description("Real-time terminal dashboard for all services")
|
|
86
|
+
.option("-r, --refresh <seconds>", "Refresh interval in seconds", "2")
|
|
87
|
+
.action(monitCommand);
|
|
88
|
+
|
|
89
|
+
program
|
|
90
|
+
.command("web")
|
|
91
|
+
.description("Start web-based monitoring dashboard")
|
|
92
|
+
.option("-p, --port <port>", "Port for web dashboard", "8080")
|
|
93
|
+
.option("-d, --detach", "Run in background")
|
|
94
|
+
.action(webCommand);
|
|
95
|
+
|
|
96
|
+
program
|
|
97
|
+
.command("alert")
|
|
98
|
+
.description("Configure alert thresholds and webhooks")
|
|
99
|
+
.option("--enable", "Enable alerts")
|
|
100
|
+
.option("--disable", "Disable alerts")
|
|
101
|
+
.option("--webhook <url>", "Set webhook URL for alerts")
|
|
102
|
+
.option("--cpu <percentage>", "CPU threshold percentage")
|
|
103
|
+
.option("--memory <percentage>", "Memory threshold percentage")
|
|
104
|
+
.option("--errorRate <percentage>", "Error rate threshold percentage")
|
|
105
|
+
.option("--uptime <percentage>", "Uptime threshold percentage")
|
|
106
|
+
.option("--cooldown <seconds>", "Alert cooldown period in seconds")
|
|
107
|
+
.option("--service <name>", "Configure alerts for specific service")
|
|
108
|
+
.option("--list", "List current alert configuration")
|
|
109
|
+
.option("--test", "Test webhook connectivity")
|
|
110
|
+
.action(alertCommand);
|
|
111
|
+
|
|
112
|
+
program
|
|
113
|
+
.command("export")
|
|
114
|
+
.description("Export historical metrics data")
|
|
115
|
+
.option("-f, --format <format>", "Export format (json|csv)", "json")
|
|
116
|
+
.option("-h, --hours <hours>", "Hours of data to export", "24")
|
|
117
|
+
.option("-o, --output <file>", "Output file path")
|
|
118
|
+
.option("-s, --service <name>", "Export specific service metrics")
|
|
119
|
+
.action(exportCommand);
|
|
120
|
+
|
|
121
|
+
program
|
|
122
|
+
.command("deps")
|
|
123
|
+
.description("Visualize service dependencies")
|
|
124
|
+
.option("-f, --format <format>", "Output format (text|dot|json)", "text")
|
|
125
|
+
.option("-o, --output <file>", "Output file path")
|
|
126
|
+
.action(depsCommand);
|
|
127
|
+
|
|
128
|
+
program
|
|
129
|
+
.command("profile")
|
|
130
|
+
.description("Performance profiling for services")
|
|
131
|
+
.option("-d, --duration <seconds>", "Profiling duration", "60")
|
|
132
|
+
.option("-i, --interval <ms>", "Sampling interval", "1000")
|
|
133
|
+
.option("-s, --service <name>", "Service name to profile")
|
|
134
|
+
.option("--flamegraph", "Generate flame graph")
|
|
135
|
+
.option("--top <number>", "Show top N functions", "10")
|
|
136
|
+
.action(profileCommand);
|
|
137
|
+
|
|
138
|
+
program
|
|
139
|
+
.command("delete")
|
|
140
|
+
.description("Delete managed services")
|
|
141
|
+
.argument("[name]", "Service name (optional)")
|
|
142
|
+
.option("-a, --all", "Delete all services")
|
|
143
|
+
.option("-f, --force", "Force deletion without errors")
|
|
144
|
+
.option("-r, --remove", "Remove service configuration files")
|
|
145
|
+
.option("-t, --timeout <seconds>", "Timeout for graceful shutdown (default: 30)")
|
|
146
|
+
.action(deleteCommand);
|
|
147
|
+
|
|
148
|
+
program
|
|
149
|
+
.command("save")
|
|
150
|
+
.description("Save service configurations to backup")
|
|
151
|
+
.argument("[name]", "Service name (optional)")
|
|
152
|
+
.option("-a, --all", "Save all services")
|
|
153
|
+
.option("-f, --force", "Force save without errors")
|
|
154
|
+
.option("-b, --backup", "Create timestamped backup")
|
|
155
|
+
.action(saveCommand);
|
|
156
|
+
|
|
157
|
+
program
|
|
158
|
+
.command("resurrect")
|
|
159
|
+
.description("Resurrect services from backup")
|
|
160
|
+
.argument("[name]", "Service name (optional)")
|
|
161
|
+
.option("-a, --all", "Resurrect all services")
|
|
162
|
+
.option("-f, --force", "Force resurrection without errors")
|
|
163
|
+
.option("-c, --config <file>", "Configuration file to use")
|
|
164
|
+
.action(resurrectCommand);
|
|
165
|
+
|
|
166
|
+
program
|
|
167
|
+
.command("deploy")
|
|
168
|
+
.description("🚀 Deploy applications with zero-config production setup")
|
|
169
|
+
.argument("<file>", "Application file to deploy")
|
|
170
|
+
.option("-n, --name <name>", "Service name")
|
|
171
|
+
.option("-p, --port <port>", "Port number", "3000")
|
|
172
|
+
.option("-h, --host <host>", "Host address", "localhost")
|
|
173
|
+
.option("-e, --env <env>", "Environment variables (multiple)", (value, previous) => [...(previous || []), value])
|
|
174
|
+
.option("-i, --instances <number>", "Number of instances")
|
|
175
|
+
.option("--memory <memory>", "Memory limit")
|
|
176
|
+
.option("--cpu <cpu>", "CPU limit")
|
|
177
|
+
.option("--log-level <level>", "Log level")
|
|
178
|
+
.option("--log-file <file>", "Log file path")
|
|
179
|
+
.option("--restart <policy>", "Restart policy")
|
|
180
|
+
.option("--no-health", "Skip health check")
|
|
181
|
+
.option("--no-metrics", "Disable metrics")
|
|
182
|
+
.option("--no-otel", "Disable OpenTelemetry")
|
|
183
|
+
.option("--no-prometheus", "Disable Prometheus")
|
|
184
|
+
.option("--https", "Enable HTTPS")
|
|
185
|
+
.option("--no-linger", "Don't enable linger")
|
|
186
|
+
.option("-f, --force", "Force deployment")
|
|
187
|
+
.option("--reload", "Reload existing service")
|
|
188
|
+
.option("--build", "Build TypeScript")
|
|
189
|
+
.action(deployCommand);
|
|
190
|
+
|
|
191
|
+
program
|
|
192
|
+
.command("loadbalancer")
|
|
193
|
+
.description("Load balancer management")
|
|
194
|
+
.argument("<action>", "Action to perform")
|
|
195
|
+
.option("-p, --port <port>", "Load balancer port", "8080")
|
|
196
|
+
.option("-a, --algorithm <type>", "Load balancing algorithm", "round-robin")
|
|
197
|
+
.option("-b, --backends <list>", "Backend servers (host:port,host:port)")
|
|
198
|
+
.option("--health-check", "Enable health checking", true)
|
|
199
|
+
.option("--health-path <path>", "Health check path", "/healthz")
|
|
200
|
+
.option("--health-interval <ms>", "Health check interval", "10000")
|
|
201
|
+
.action(loadbalancerCommand);
|
|
202
|
+
|
|
203
|
+
program
|
|
204
|
+
.command("dbpool")
|
|
205
|
+
.description("Database connection pool management")
|
|
206
|
+
.argument("<action>", "Action to perform")
|
|
207
|
+
.option("--host <host>", "Database host", "localhost")
|
|
208
|
+
.option("--port <port>", "Database port", "5432")
|
|
209
|
+
.option("--database <name>", "Database name", "testdb")
|
|
210
|
+
.option("--username <user>", "Database username", "user")
|
|
211
|
+
.option("--password <pass>", "Database password", "password")
|
|
212
|
+
.option("--max-connections <num>", "Maximum connections", "10")
|
|
213
|
+
.option("--min-connections <num>", "Minimum connections", "2")
|
|
214
|
+
.option("--concurrency <num>", "Test concurrency", "10")
|
|
215
|
+
.option("--iterations <num>", "Test iterations", "100")
|
|
216
|
+
.action(dbpoolCommand);
|
|
217
|
+
|
|
218
|
+
program
|
|
219
|
+
.command("update")
|
|
220
|
+
.description("Update BS9 to latest version")
|
|
221
|
+
.option("--check", "Check for updates without installing")
|
|
222
|
+
.option("--force", "Force update even if already latest")
|
|
223
|
+
.option("--rollback", "Rollback to previous version")
|
|
224
|
+
.option("--version <version>", "Update to specific version")
|
|
225
|
+
.action(updateCommand);
|
|
226
|
+
|
|
227
|
+
program
|
|
228
|
+
.command("advanced")
|
|
229
|
+
.description("Advanced monitoring dashboard")
|
|
230
|
+
.option("--port <port>", "Dashboard port", "8090")
|
|
231
|
+
.action(advancedMonitoringCommand);
|
|
232
|
+
|
|
233
|
+
program
|
|
234
|
+
.command("consul")
|
|
235
|
+
.description("Consul service discovery")
|
|
236
|
+
.argument("<action>", "Action to perform")
|
|
237
|
+
.option("--consul-url <url>", "Consul URL", "http://localhost:8500")
|
|
238
|
+
.option("--name <name>", "Service name")
|
|
239
|
+
.option("--id <id>", "Service ID")
|
|
240
|
+
.option("--address <address>", "Service address")
|
|
241
|
+
.option("--port <port>", "Service port")
|
|
242
|
+
.option("--tags <tags>", "Service tags (comma-separated)")
|
|
243
|
+
.option("--health-check <url>", "Health check URL")
|
|
244
|
+
.option("--meta <json>", "Service metadata (JSON)")
|
|
245
|
+
.option("--service <service>", "Service name for discovery")
|
|
246
|
+
.action(consulCommand);
|
|
247
|
+
|
|
248
|
+
program
|
|
249
|
+
.command("doctor")
|
|
250
|
+
.description("Perform comprehensive health check")
|
|
251
|
+
.option("--check <type>", "Specific check to run (dependencies|configuration|platform)")
|
|
252
|
+
.option("-v, --verbose", "Verbose output with system information")
|
|
253
|
+
.action(doctorCommand);
|
|
254
|
+
|
|
255
|
+
program.parse();
|
package/dist/bs9.js
CHANGED
package/package.json
CHANGED
package/src/commands/delete.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import { execSync } from "node:child_process";
|
|
13
13
|
import { join } from "node:path";
|
|
14
14
|
import { getPlatformInfo } from "../platform/detect.js";
|
|
15
|
+
import { parseServiceArray, confirmAction } from "../utils/array-parser.js";
|
|
15
16
|
|
|
16
17
|
interface DeleteOptions {
|
|
17
18
|
all?: boolean;
|
|
@@ -28,15 +29,66 @@ function isValidServiceName(name: string): boolean {
|
|
|
28
29
|
return validPattern.test(name) && name.length <= 64 && !name.includes('..') && !name.includes('/');
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
export async function deleteCommand(
|
|
32
|
+
export async function deleteCommand(names: string[], options: DeleteOptions): Promise<void> {
|
|
32
33
|
const platformInfo = getPlatformInfo();
|
|
33
34
|
|
|
34
|
-
// Handle
|
|
35
|
+
// Handle multiple arguments
|
|
36
|
+
const name = names.length > 0 ? names.join(' ') : '';
|
|
37
|
+
|
|
38
|
+
// Handle multi-service operations
|
|
39
|
+
if (name.includes('[') || name === 'all') {
|
|
40
|
+
await handleMultiServiceDelete(name, options);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Handle delete all services (legacy)
|
|
35
45
|
if (options.all) {
|
|
36
46
|
await deleteAllServices(platformInfo, options);
|
|
37
47
|
return;
|
|
38
48
|
}
|
|
39
49
|
|
|
50
|
+
// Single service operation (existing logic)
|
|
51
|
+
await handleSingleServiceDelete(name, platformInfo, options);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function handleMultiServiceDelete(name: string, options: DeleteOptions): Promise<void> {
|
|
55
|
+
const services = await parseServiceArray(name);
|
|
56
|
+
|
|
57
|
+
if (services.length === 0) {
|
|
58
|
+
console.log("❌ No services found matching the pattern");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Safety confirmation for bulk operations
|
|
63
|
+
if (!options.force) {
|
|
64
|
+
console.log(`⚠️ About to delete ${services.length} services:`);
|
|
65
|
+
services.forEach(service => console.log(` - ${service}`));
|
|
66
|
+
|
|
67
|
+
const confirmed = await confirmAction('Are you sure? This action cannot be undone. (y/N): ');
|
|
68
|
+
if (!confirmed) {
|
|
69
|
+
console.log('❌ Delete operation cancelled');
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
console.log(`🗑️ Deleting ${services.length} services...`);
|
|
75
|
+
|
|
76
|
+
const results = await Promise.allSettled(
|
|
77
|
+
services.map(async (serviceName) => {
|
|
78
|
+
try {
|
|
79
|
+
const platformInfo = getPlatformInfo();
|
|
80
|
+
await handleSingleServiceDelete(serviceName, platformInfo, { ...options, force: true });
|
|
81
|
+
return { service: serviceName, status: 'success', error: null };
|
|
82
|
+
} catch (error) {
|
|
83
|
+
return { service: serviceName, status: 'failed', error: error instanceof Error ? error.message : String(error) };
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
displayBatchResults(results, 'delete');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function handleSingleServiceDelete(name: string, platformInfo: any, options: DeleteOptions): Promise<void> {
|
|
40
92
|
// Security: Validate service name
|
|
41
93
|
if (!isValidServiceName(name)) {
|
|
42
94
|
console.error(`❌ Security: Invalid service name: ${name}`);
|
|
@@ -176,3 +228,28 @@ async function deleteAllServices(platformInfo: any, options: DeleteOptions): Pro
|
|
|
176
228
|
}
|
|
177
229
|
}
|
|
178
230
|
}
|
|
231
|
+
|
|
232
|
+
function displayBatchResults(results: PromiseSettledResult<{ service: string; status: string; error: string | null }>[], operation: string): void {
|
|
233
|
+
console.log(`\n📊 Batch ${operation} Results`);
|
|
234
|
+
console.log("=".repeat(50));
|
|
235
|
+
|
|
236
|
+
const successful = results.filter(r => r.status === 'fulfilled' && r.value.status === 'success');
|
|
237
|
+
const failed = results.filter(r => r.status === 'fulfilled' && r.value.status === 'failed');
|
|
238
|
+
|
|
239
|
+
successful.forEach(result => {
|
|
240
|
+
if (result.status === 'fulfilled') {
|
|
241
|
+
console.log(`✅ ${result.value.service} - ${operation} successful`);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
failed.forEach(result => {
|
|
246
|
+
if (result.status === 'fulfilled') {
|
|
247
|
+
console.log(`❌ ${result.value.service} - Failed: ${result.value.error}`);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
console.log(`\n📈 Summary:`);
|
|
252
|
+
console.log(` Total: ${results.length} services`);
|
|
253
|
+
console.log(` Success: ${successful.length}/${results.length} (${((successful.length / results.length) * 100).toFixed(1)}%)`);
|
|
254
|
+
console.log(` Failed: ${failed.length}/${results.length} (${((failed.length / results.length) * 100).toFixed(1)}%)`);
|
|
255
|
+
}
|
package/src/commands/deploy.ts
CHANGED
|
@@ -237,12 +237,6 @@ function showDeploymentSummary(serviceName: string, options: DeployOptions): voi
|
|
|
237
237
|
console.log(` bs9 delete ${serviceName}`);
|
|
238
238
|
console.log(` bs9 save ${serviceName}`);
|
|
239
239
|
|
|
240
|
-
|
|
241
|
-
console.log(" ✅ Zero-config systemd setup");
|
|
242
|
-
console.log(" ✅ Built-in health checks & restart policies");
|
|
243
|
-
console.log(" ✅ Hot reload with environment updates");
|
|
244
|
-
console.log(" ✅ Automatic metrics & observability");
|
|
245
|
-
console.log(" ✅ One-command deployment");
|
|
246
|
-
|
|
240
|
+
|
|
247
241
|
console.log("\n🚀 Your service is now running in production mode!");
|
|
248
242
|
}
|