bs9 1.0.0 → 1.3.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 +105 -9
- package/bin/bs9 +91 -7
- package/dist/bs9-064xs9r9. +148 -0
- package/dist/bs9-0gqcrp5t. +144 -0
- package/dist/bs9-33vcpmb9. +181 -0
- package/dist/bs9-nv7nseny. +197 -0
- package/dist/bs9-r6b9zpw0. +156 -0
- package/dist/bs9.js +2 -0
- package/package.json +3 -4
- package/src/commands/deps.ts +295 -0
- package/src/commands/profile.ts +338 -0
- package/src/commands/restart.ts +28 -3
- package/src/commands/start.ts +201 -21
- package/src/commands/status.ts +154 -109
- package/src/commands/stop.ts +31 -3
- package/src/commands/update.ts +322 -0
- package/src/commands/web.ts +29 -3
- package/src/database/pool.ts +335 -0
- package/src/discovery/consul.ts +285 -0
- package/src/loadbalancer/manager.ts +481 -0
- package/src/macos/launchd.ts +402 -0
- package/src/monitoring/advanced.ts +341 -0
- package/src/platform/detect.ts +137 -0
- package/src/windows/service.ts +391 -0
package/README.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
# BS9 (Bun Sentinel 9)
|
|
1
|
+
# BS9 (Bun Sentinel 9) 🚀
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
[](https://github.com/bs9/bs9)
|
|
5
|
+
[](SECURITY.md)
|
|
6
|
+
[](PRODUCTION.md)
|
|
7
|
+
[](https://github.com/bs9/bs9)
|
|
8
|
+
|
|
9
|
+
**Enterprise-grade, mission-critical process manager for Bun applications with built-in security, monitoring, and observability. Works on Windows, macOS, and Linux.**
|
|
4
10
|
|
|
5
11
|
---
|
|
6
12
|
|
|
@@ -8,7 +14,7 @@
|
|
|
8
14
|
|
|
9
15
|
```bash
|
|
10
16
|
# One-click installer (installs Bun + BS9)
|
|
11
|
-
curl -fsSL https://raw.githubusercontent.com/xarhang/bs9/
|
|
17
|
+
curl -fsSL https://raw.githubusercontent.com/xarhang/bs9/setup.sh | bash
|
|
12
18
|
|
|
13
19
|
# Or manual install
|
|
14
20
|
git clone https://github.com/xarhang/bs9.git
|
|
@@ -20,14 +26,43 @@ chmod +x ~/.local/bin/bs9
|
|
|
20
26
|
|
|
21
27
|
---
|
|
22
28
|
|
|
29
|
+
### Platform Support
|
|
30
|
+
|
|
31
|
+
BS9 supports all major platforms with native service management:
|
|
32
|
+
|
|
33
|
+
#### 🐧 Linux
|
|
34
|
+
- **Service Manager**: Systemd (user-mode)
|
|
35
|
+
- **Features**: Advanced security hardening, resource limits, sandboxing
|
|
36
|
+
- **Commands**: All standard commands available
|
|
37
|
+
|
|
38
|
+
#### 🍎 macOS
|
|
39
|
+
- **Service Manager**: Launchd
|
|
40
|
+
- **Features**: Native macOS integration, automatic recovery
|
|
41
|
+
- **Commands**: Standard commands + `bs9 macos` for launchd management
|
|
42
|
+
|
|
43
|
+
#### 🪟 Windows
|
|
44
|
+
- **Service Manager**: Windows Services
|
|
45
|
+
- **Features**: PowerShell automation, event log integration
|
|
46
|
+
- **Commands**: Standard commands + `bs9 windows` for service management
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Check your platform
|
|
50
|
+
bs9 platform
|
|
51
|
+
|
|
52
|
+
# Platform-specific service management
|
|
53
|
+
bs9 macos create --name my-app --file app.js # macOS
|
|
54
|
+
bs9 windows create --name my-app --file app.js # Windows
|
|
55
|
+
```
|
|
56
|
+
|
|
23
57
|
## 📋 Complete CLI Commands
|
|
24
58
|
|
|
25
59
|
### Service Management
|
|
26
60
|
```bash
|
|
27
|
-
# Start service with
|
|
28
|
-
bs9 start app.js
|
|
29
|
-
bs9 start app.
|
|
30
|
-
bs9 start app.
|
|
61
|
+
# Start service with flexible host and protocol options
|
|
62
|
+
bs9 start app.js # Default: localhost:3000, HTTP
|
|
63
|
+
bs9 start app.js --host 0.0.0.0 --port 8080 # Custom host and port
|
|
64
|
+
bs9 start app.js --host 192.168.1.100 --https # Custom host with HTTPS
|
|
65
|
+
bs9 start app.ts --build --name myapp --port 8080 --env NODE_ENV=production --host 0.0.0.0 --https
|
|
31
66
|
|
|
32
67
|
# Service lifecycle
|
|
33
68
|
bs9 stop myapp
|
|
@@ -46,6 +81,13 @@ bs9 monit --refresh 5 # Custom refresh interval
|
|
|
46
81
|
bs9 web --port 8080 # Start web dashboard
|
|
47
82
|
bs9 web --detach --port 8080 # Run in background
|
|
48
83
|
|
|
84
|
+
# Advanced monitoring
|
|
85
|
+
bs9 advanced --port 8090
|
|
86
|
+
|
|
87
|
+
# Performance profiling
|
|
88
|
+
bs9 profile --service myapp --duration 60
|
|
89
|
+
bs9 profile --service myapp --duration 60 --output profile.json
|
|
90
|
+
|
|
49
91
|
# Alert management
|
|
50
92
|
bs9 alert --list # Show alert configuration
|
|
51
93
|
bs9 alert --cpu 80 --memory 85 # Set thresholds
|
|
@@ -54,6 +96,7 @@ bs9 alert --test # Test webhook
|
|
|
54
96
|
|
|
55
97
|
# Historical data
|
|
56
98
|
bs9 export --format json --hours 24 # Export metrics
|
|
99
|
+
bs9 export --service myapp --format csv --hours 24
|
|
57
100
|
bs9 export --service myapp --format csv
|
|
58
101
|
```
|
|
59
102
|
|
|
@@ -234,8 +277,8 @@ docker-compose up -d
|
|
|
234
277
|
kubectl apply -f src/k8s/bs9-deployment.yaml
|
|
235
278
|
|
|
236
279
|
# Check deployment
|
|
280
|
+
kubectl get deployments -n bs9-system
|
|
237
281
|
kubectl get pods -n bs9-system
|
|
238
|
-
kubectl get services -n bs9-system
|
|
239
282
|
```
|
|
240
283
|
|
|
241
284
|
### K8s Features
|
|
@@ -528,5 +571,58 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for development guidelines.
|
|
|
528
571
|
|
|
529
572
|
- **GitHub**: https://github.com/xarhang/bs9
|
|
530
573
|
- **Issues**: https://github.com/xarhang/bs9/issues
|
|
531
|
-
- **Documentation**: https://github.com/xarhang/bs9/wiki
|
|
532
574
|
- **Discussions**: https://github.com/xarhang/bs9/discussions
|
|
575
|
+
- **Security**: security@bs9.dev
|
|
576
|
+
- **Enterprise**: enterprise@bs9.dev
|
|
577
|
+
|
|
578
|
+
## 🔒 Security
|
|
579
|
+
|
|
580
|
+
BS9 is built with security as a primary concern:
|
|
581
|
+
|
|
582
|
+
### Built-in Security Features
|
|
583
|
+
- **Input Validation**: Path traversal protection, command injection prevention
|
|
584
|
+
- **Runtime Security**: Process isolation, resource limits, security auditing
|
|
585
|
+
- **Platform Hardening**: Native security integration (systemd, launchd, Windows services)
|
|
586
|
+
- **Web Security**: Session token authentication, XSS protection
|
|
587
|
+
- **Database Security**: SQL injection prevention, connection validation
|
|
588
|
+
- **Network Security**: Header sanitization, rate limiting
|
|
589
|
+
|
|
590
|
+
### Security Best Practices
|
|
591
|
+
```bash
|
|
592
|
+
# Use secure service names
|
|
593
|
+
bs9 start app.js --name my-secure-app
|
|
594
|
+
|
|
595
|
+
# Bind to specific interfaces
|
|
596
|
+
bs9 start app.js --host 127.0.0.1 --port 3000
|
|
597
|
+
|
|
598
|
+
# Use HTTPS in production
|
|
599
|
+
bs9 start app.js --https --host 0.0.0.0 --port 8443
|
|
600
|
+
|
|
601
|
+
# Enable security auditing
|
|
602
|
+
export BS9_AUDIT_LOGGING=true
|
|
603
|
+
bs9 start app.js
|
|
604
|
+
|
|
605
|
+
# Secure web dashboard
|
|
606
|
+
bs9 web --port 8080 # Generates secure session token
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
### Security Documentation
|
|
610
|
+
- **[Security Policy](SECURITY.md)** - Complete security documentation
|
|
611
|
+
- **[Production Security Guide](PRODUCTION.md#security-hardening)** - Production security hardening
|
|
612
|
+
|
|
613
|
+
### Security Checklist
|
|
614
|
+
- [ ] Review service configurations
|
|
615
|
+
- [ ] Enable security audit logging
|
|
616
|
+
- [ ] Use proper file permissions
|
|
617
|
+
- [ ] Configure network firewalls
|
|
618
|
+
- [ ] Monitor security logs
|
|
619
|
+
- [ ] Regular security updates
|
|
620
|
+
|
|
621
|
+
## 📚 Documentation
|
|
622
|
+
|
|
623
|
+
- **[Production Guide](PRODUCTION.md)** - Production deployment and operations
|
|
624
|
+
- **[Security Policy](SECURITY.md)** - Security features and vulnerability reporting
|
|
625
|
+
- **[Architecture](ARCHITECTURE.md)** - System architecture and design
|
|
626
|
+
- **[Installation Guide](INSTALL.md)** - Detailed installation instructions
|
|
627
|
+
- **[Contributing](CONTRIBUTING.md)** - Development and contribution guidelines
|
|
628
|
+
- **[Changelog](CHANGELOG.md)** - Version history and roadmap
|
package/bin/bs9
CHANGED
|
@@ -10,6 +10,15 @@ import { monitCommand } from "../src/commands/monit.js";
|
|
|
10
10
|
import { webCommand } from "../src/commands/web.js";
|
|
11
11
|
import { alertCommand } from "../src/commands/alert.js";
|
|
12
12
|
import { exportCommand } from "../src/commands/export.js";
|
|
13
|
+
import { depsCommand } from "../src/commands/deps.js";
|
|
14
|
+
import { profileCommand } from "../src/commands/profile.js";
|
|
15
|
+
import { loadbalancerCommand } from "../src/loadbalancer/manager.js";
|
|
16
|
+
import { windowsCommand } from "../src/windows/service.js";
|
|
17
|
+
import { launchdCommand } from "../src/macos/launchd.js";
|
|
18
|
+
import { updateCommand } from "../src/commands/update.js";
|
|
19
|
+
import { dbpoolCommand } from "../src/database/pool.js";
|
|
20
|
+
import { advancedMonitoringCommand } from "../src/monitoring/advanced.js";
|
|
21
|
+
import { consulCommand } from "../src/discovery/consul.js";
|
|
13
22
|
|
|
14
23
|
const program = new Command();
|
|
15
24
|
|
|
@@ -21,13 +30,15 @@ program
|
|
|
21
30
|
program
|
|
22
31
|
.command("start")
|
|
23
32
|
.description("Start a process with hardened systemd unit")
|
|
24
|
-
.argument("<file>", "
|
|
25
|
-
.option("-n, --name <name>", "Service name
|
|
26
|
-
.option("-p, --port <port>", "Port
|
|
27
|
-
.option("--
|
|
28
|
-
.option("--
|
|
29
|
-
.option("--
|
|
30
|
-
.option("--
|
|
33
|
+
.argument("<file>", "Application file to start")
|
|
34
|
+
.option("-n, --name <name>", "Service name")
|
|
35
|
+
.option("-p, --port <port>", "Port number", "3000")
|
|
36
|
+
.option("-h, --host <host>", "Host address", "localhost")
|
|
37
|
+
.option("--https", "Use HTTPS protocol")
|
|
38
|
+
.option("-e, --env <env>", "Environment variables (can be used multiple times)", (value, previous) => [...(previous || []), value])
|
|
39
|
+
.option("--otel", "Enable OpenTelemetry instrumentation", true)
|
|
40
|
+
.option("--prometheus", "Enable Prometheus metrics", true)
|
|
41
|
+
.option("--build", "Build TypeScript to JavaScript before starting")
|
|
31
42
|
.action(startCommand);
|
|
32
43
|
|
|
33
44
|
program
|
|
@@ -94,4 +105,77 @@ program
|
|
|
94
105
|
.option("-s, --service <name>", "Export specific service metrics")
|
|
95
106
|
.action(exportCommand);
|
|
96
107
|
|
|
108
|
+
program
|
|
109
|
+
.command("deps")
|
|
110
|
+
.description("Visualize service dependencies")
|
|
111
|
+
.option("-f, --format <format>", "Output format (text|dot|json)", "text")
|
|
112
|
+
.option("-o, --output <file>", "Output file path")
|
|
113
|
+
.action(depsCommand);
|
|
114
|
+
|
|
115
|
+
program
|
|
116
|
+
.command("profile")
|
|
117
|
+
.description("Performance profiling for services")
|
|
118
|
+
.option("-d, --duration <seconds>", "Profiling duration", "60")
|
|
119
|
+
.option("-i, --interval <ms>", "Sampling interval", "1000")
|
|
120
|
+
.option("-s, --service <name>", "Service name to profile")
|
|
121
|
+
.option("-o, --output <file>", "Output file path")
|
|
122
|
+
.action(profileCommand);
|
|
123
|
+
|
|
124
|
+
program
|
|
125
|
+
.command("loadbalancer")
|
|
126
|
+
.description("Load balancer management")
|
|
127
|
+
.argument("<action>", "Action to perform")
|
|
128
|
+
.option("-p, --port <port>", "Load balancer port", "8080")
|
|
129
|
+
.option("-a, --algorithm <type>", "Load balancing algorithm", "round-robin")
|
|
130
|
+
.option("-b, --backends <list>", "Backend servers (host:port,host:port)")
|
|
131
|
+
.option("--health-check", "Enable health checking", true)
|
|
132
|
+
.option("--health-path <path>", "Health check path", "/healthz")
|
|
133
|
+
.option("--health-interval <ms>", "Health check interval", "10000")
|
|
134
|
+
.action(loadbalancerCommand);
|
|
135
|
+
|
|
136
|
+
program
|
|
137
|
+
.command("dbpool")
|
|
138
|
+
.description("Database connection pool management")
|
|
139
|
+
.argument("<action>", "Action to perform")
|
|
140
|
+
.option("--host <host>", "Database host", "localhost")
|
|
141
|
+
.option("--port <port>", "Database port", "5432")
|
|
142
|
+
.option("--database <name>", "Database name", "testdb")
|
|
143
|
+
.option("--username <user>", "Database username", "user")
|
|
144
|
+
.option("--password <pass>", "Database password", "password")
|
|
145
|
+
.option("--max-connections <num>", "Maximum connections", "10")
|
|
146
|
+
.option("--min-connections <num>", "Minimum connections", "2")
|
|
147
|
+
.option("--concurrency <num>", "Test concurrency", "10")
|
|
148
|
+
.option("--iterations <num>", "Test iterations", "100")
|
|
149
|
+
.action(dbpoolCommand);
|
|
150
|
+
|
|
151
|
+
program
|
|
152
|
+
.command("update")
|
|
153
|
+
.description("Update BS9 to latest version")
|
|
154
|
+
.option("--check", "Check for updates without installing")
|
|
155
|
+
.option("--force", "Force update even if already latest")
|
|
156
|
+
.option("--rollback", "Rollback to previous version")
|
|
157
|
+
.option("--version <version>", "Update to specific version")
|
|
158
|
+
.action(updateCommand);
|
|
159
|
+
|
|
160
|
+
program
|
|
161
|
+
.command("advanced")
|
|
162
|
+
.description("Advanced monitoring dashboard")
|
|
163
|
+
.option("--port <port>", "Dashboard port", "8090")
|
|
164
|
+
.action(advancedMonitoringCommand);
|
|
165
|
+
|
|
166
|
+
program
|
|
167
|
+
.command("consul")
|
|
168
|
+
.description("Consul service discovery")
|
|
169
|
+
.argument("<action>", "Action to perform")
|
|
170
|
+
.option("--consul-url <url>", "Consul URL", "http://localhost:8500")
|
|
171
|
+
.option("--name <name>", "Service name")
|
|
172
|
+
.option("--id <id>", "Service ID")
|
|
173
|
+
.option("--address <address>", "Service address")
|
|
174
|
+
.option("--port <port>", "Service port")
|
|
175
|
+
.option("--tags <tags>", "Service tags (comma-separated)")
|
|
176
|
+
.option("--health-check <url>", "Health check URL")
|
|
177
|
+
.option("--meta <json>", "Service metadata (JSON)")
|
|
178
|
+
.option("--service <service>", "Service name for discovery")
|
|
179
|
+
.action(consulCommand);
|
|
180
|
+
|
|
97
181
|
program.parse();
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { startCommand } from "../src/commands/start.js";
|
|
5
|
+
import { stopCommand } from "../src/commands/stop.js";
|
|
6
|
+
import { restartCommand } from "../src/commands/restart.js";
|
|
7
|
+
import { statusCommand } from "../src/commands/status.js";
|
|
8
|
+
import { logsCommand } from "../src/commands/logs.js";
|
|
9
|
+
import { monitCommand } from "../src/commands/monit.js";
|
|
10
|
+
import { webCommand } from "../src/commands/web.js";
|
|
11
|
+
import { alertCommand } from "../src/commands/alert.js";
|
|
12
|
+
import { exportCommand } from "../src/commands/export.js";
|
|
13
|
+
import { depsCommand } from "../src/commands/deps.js";
|
|
14
|
+
import { profileCommand } from "../src/commands/profile.js";
|
|
15
|
+
import { loadbalancerCommand } from "../src/loadbalancer/manager.js";
|
|
16
|
+
import { windowsCommand } from "../src/windows/service.js";
|
|
17
|
+
import { launchdCommand } from "../src/macos/launchd.js";
|
|
18
|
+
import { dbpoolCommand } from "../src/database/pool.js";
|
|
19
|
+
|
|
20
|
+
const program = new Command();
|
|
21
|
+
|
|
22
|
+
program
|
|
23
|
+
.name("bs9")
|
|
24
|
+
.description("BS9 (Bun Sentinel 9) — Mission-critical process manager CLI")
|
|
25
|
+
.version("1.0.0");
|
|
26
|
+
|
|
27
|
+
program
|
|
28
|
+
.command("start")
|
|
29
|
+
.description("Start a process with hardened systemd unit")
|
|
30
|
+
.argument("<file>", "Application file to start")
|
|
31
|
+
.option("-n, --name <name>", "Service name")
|
|
32
|
+
.option("-p, --port <port>", "Port number", "3000")
|
|
33
|
+
.option("-h, --host <host>", "Host address", "localhost")
|
|
34
|
+
.option("--https", "Use HTTPS protocol")
|
|
35
|
+
.option("-e, --env <env>", "Environment variables (can be used multiple times)", (value, previous) => [...(previous || []), value])
|
|
36
|
+
.option("--otel", "Enable OpenTelemetry instrumentation", true)
|
|
37
|
+
.option("--prometheus", "Enable Prometheus metrics", true)
|
|
38
|
+
.option("--build", "Build TypeScript to JavaScript before starting")
|
|
39
|
+
.action(startCommand);
|
|
40
|
+
|
|
41
|
+
program
|
|
42
|
+
.command("stop")
|
|
43
|
+
.description("Stop a managed service")
|
|
44
|
+
.argument("<name>", "Service name")
|
|
45
|
+
.action(stopCommand);
|
|
46
|
+
|
|
47
|
+
program
|
|
48
|
+
.command("restart")
|
|
49
|
+
.description("Restart a managed service")
|
|
50
|
+
.argument("<name>", "Service name")
|
|
51
|
+
.action(restartCommand);
|
|
52
|
+
|
|
53
|
+
program
|
|
54
|
+
.command("status")
|
|
55
|
+
.description("Show status and SRE metrics for all services")
|
|
56
|
+
.option("-w, --watch", "Watch mode (refresh every 2s)")
|
|
57
|
+
.action(statusCommand);
|
|
58
|
+
|
|
59
|
+
program
|
|
60
|
+
.command("logs")
|
|
61
|
+
.description("Show logs for a service (via journalctl)")
|
|
62
|
+
.argument("<name>", "Service name")
|
|
63
|
+
.option("-f, --follow", "Follow logs")
|
|
64
|
+
.option("-n, --lines <number>", "Number of lines", "50")
|
|
65
|
+
.action(logsCommand);
|
|
66
|
+
|
|
67
|
+
program
|
|
68
|
+
.command("monit")
|
|
69
|
+
.description("Real-time terminal dashboard for all services")
|
|
70
|
+
.option("-r, --refresh <seconds>", "Refresh interval in seconds", "2")
|
|
71
|
+
.action(monitCommand);
|
|
72
|
+
|
|
73
|
+
program
|
|
74
|
+
.command("web")
|
|
75
|
+
.description("Start web-based monitoring dashboard")
|
|
76
|
+
.option("-p, --port <port>", "Port for web dashboard", "8080")
|
|
77
|
+
.option("-d, --detach", "Run in background")
|
|
78
|
+
.action(webCommand);
|
|
79
|
+
|
|
80
|
+
program
|
|
81
|
+
.command("alert")
|
|
82
|
+
.description("Configure alert thresholds and webhooks")
|
|
83
|
+
.option("--enable", "Enable alerts")
|
|
84
|
+
.option("--disable", "Disable alerts")
|
|
85
|
+
.option("--webhook <url>", "Set webhook URL for alerts")
|
|
86
|
+
.option("--cpu <percentage>", "CPU threshold percentage")
|
|
87
|
+
.option("--memory <percentage>", "Memory threshold percentage")
|
|
88
|
+
.option("--errorRate <percentage>", "Error rate threshold percentage")
|
|
89
|
+
.option("--uptime <percentage>", "Uptime threshold percentage")
|
|
90
|
+
.option("--cooldown <seconds>", "Alert cooldown period in seconds")
|
|
91
|
+
.option("--service <name>", "Configure alerts for specific service")
|
|
92
|
+
.option("--list", "List current alert configuration")
|
|
93
|
+
.option("--test", "Test webhook connectivity")
|
|
94
|
+
.action(alertCommand);
|
|
95
|
+
|
|
96
|
+
program
|
|
97
|
+
.command("export")
|
|
98
|
+
.description("Export historical metrics data")
|
|
99
|
+
.option("-f, --format <format>", "Export format (json|csv)", "json")
|
|
100
|
+
.option("-h, --hours <hours>", "Hours of data to export", "24")
|
|
101
|
+
.option("-o, --output <file>", "Output file path")
|
|
102
|
+
.option("-s, --service <name>", "Export specific service metrics")
|
|
103
|
+
.action(exportCommand);
|
|
104
|
+
|
|
105
|
+
program
|
|
106
|
+
.command("deps")
|
|
107
|
+
.description("Visualize service dependencies")
|
|
108
|
+
.option("-f, --format <format>", "Output format (text|dot|json)", "text")
|
|
109
|
+
.option("-o, --output <file>", "Output file path")
|
|
110
|
+
.action(depsCommand);
|
|
111
|
+
|
|
112
|
+
program
|
|
113
|
+
.command("profile")
|
|
114
|
+
.description("Performance profiling for services")
|
|
115
|
+
.option("-d, --duration <seconds>", "Profiling duration", "60")
|
|
116
|
+
.option("-i, --interval <ms>", "Sampling interval", "1000")
|
|
117
|
+
.option("-s, --service <name>", "Service name to profile")
|
|
118
|
+
.option("-o, --output <file>", "Output file path")
|
|
119
|
+
.action(profileCommand);
|
|
120
|
+
|
|
121
|
+
program
|
|
122
|
+
.command("loadbalancer")
|
|
123
|
+
.description("Load balancer management")
|
|
124
|
+
.argument("<action>", "Action to perform")
|
|
125
|
+
.option("-p, --port <port>", "Load balancer port", "8080")
|
|
126
|
+
.option("-a, --algorithm <type>", "Load balancing algorithm", "round-robin")
|
|
127
|
+
.option("-b, --backends <list>", "Backend servers (host:port,host:port)")
|
|
128
|
+
.option("--health-check", "Enable health checking", true)
|
|
129
|
+
.option("--health-path <path>", "Health check path", "/healthz")
|
|
130
|
+
.option("--health-interval <ms>", "Health check interval", "10000")
|
|
131
|
+
.action(loadbalancerCommand);
|
|
132
|
+
|
|
133
|
+
program
|
|
134
|
+
.command("dbpool")
|
|
135
|
+
.description("Database connection pool management")
|
|
136
|
+
.argument("<action>", "Action to perform")
|
|
137
|
+
.option("--host <host>", "Database host", "localhost")
|
|
138
|
+
.option("--port <port>", "Database port", "5432")
|
|
139
|
+
.option("--database <name>", "Database name", "testdb")
|
|
140
|
+
.option("--username <user>", "Database username", "user")
|
|
141
|
+
.option("--password <pass>", "Database password", "password")
|
|
142
|
+
.option("--max-connections <num>", "Maximum connections", "10")
|
|
143
|
+
.option("--min-connections <num>", "Minimum connections", "2")
|
|
144
|
+
.option("--concurrency <num>", "Test concurrency", "10")
|
|
145
|
+
.option("--iterations <num>", "Test iterations", "100")
|
|
146
|
+
.action(dbpoolCommand);
|
|
147
|
+
|
|
148
|
+
program.parse();
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { startCommand } from "../src/commands/start.js";
|
|
5
|
+
import { stopCommand } from "../src/commands/stop.js";
|
|
6
|
+
import { restartCommand } from "../src/commands/restart.js";
|
|
7
|
+
import { statusCommand } from "../src/commands/status.js";
|
|
8
|
+
import { logsCommand } from "../src/commands/logs.js";
|
|
9
|
+
import { monitCommand } from "../src/commands/monit.js";
|
|
10
|
+
import { webCommand } from "../src/commands/web.js";
|
|
11
|
+
import { alertCommand } from "../src/commands/alert.js";
|
|
12
|
+
import { exportCommand } from "../src/commands/export.js";
|
|
13
|
+
import { depsCommand } from "../src/commands/deps.js";
|
|
14
|
+
import { profileCommand } from "../src/commands/profile.js";
|
|
15
|
+
import { loadbalancerCommand } from "../src/loadbalancer/manager.js";
|
|
16
|
+
import { dbpoolCommand } from "../src/database/pool.js";
|
|
17
|
+
|
|
18
|
+
const program = new Command();
|
|
19
|
+
|
|
20
|
+
program
|
|
21
|
+
.name("bs9")
|
|
22
|
+
.description("BS9 (Bun Sentinel 9) — Mission-critical process manager CLI")
|
|
23
|
+
.version("1.0.0");
|
|
24
|
+
|
|
25
|
+
program
|
|
26
|
+
.command("start")
|
|
27
|
+
.description("Start a process with hardened systemd unit")
|
|
28
|
+
.argument("<file>", "Script or executable to run")
|
|
29
|
+
.option("-n, --name <name>", "Service name (defaults to filename)")
|
|
30
|
+
.option("-p, --port <port>", "Port to expose (for metrics/health)", "3000")
|
|
31
|
+
.option("--env <env...>", "Environment variables (KEY=VALUE)")
|
|
32
|
+
.option("--no-otel", "Disable automatic OpenTelemetry injection")
|
|
33
|
+
.option("--no-prometheus", "Disable automatic Prometheus metrics")
|
|
34
|
+
.option("--build", "Build TypeScript to optimized JavaScript for production (AOT)")
|
|
35
|
+
.action(startCommand);
|
|
36
|
+
|
|
37
|
+
program
|
|
38
|
+
.command("stop")
|
|
39
|
+
.description("Stop a managed service")
|
|
40
|
+
.argument("<name>", "Service name")
|
|
41
|
+
.action(stopCommand);
|
|
42
|
+
|
|
43
|
+
program
|
|
44
|
+
.command("restart")
|
|
45
|
+
.description("Restart a managed service")
|
|
46
|
+
.argument("<name>", "Service name")
|
|
47
|
+
.action(restartCommand);
|
|
48
|
+
|
|
49
|
+
program
|
|
50
|
+
.command("status")
|
|
51
|
+
.description("Show status and SRE metrics for all services")
|
|
52
|
+
.option("-w, --watch", "Watch mode (refresh every 2s)")
|
|
53
|
+
.action(statusCommand);
|
|
54
|
+
|
|
55
|
+
program
|
|
56
|
+
.command("logs")
|
|
57
|
+
.description("Show logs for a service (via journalctl)")
|
|
58
|
+
.argument("<name>", "Service name")
|
|
59
|
+
.option("-f, --follow", "Follow logs")
|
|
60
|
+
.option("-n, --lines <number>", "Number of lines", "50")
|
|
61
|
+
.action(logsCommand);
|
|
62
|
+
|
|
63
|
+
program
|
|
64
|
+
.command("monit")
|
|
65
|
+
.description("Real-time terminal dashboard for all services")
|
|
66
|
+
.option("-r, --refresh <seconds>", "Refresh interval in seconds", "2")
|
|
67
|
+
.action(monitCommand);
|
|
68
|
+
|
|
69
|
+
program
|
|
70
|
+
.command("web")
|
|
71
|
+
.description("Start web-based monitoring dashboard")
|
|
72
|
+
.option("-p, --port <port>", "Port for web dashboard", "8080")
|
|
73
|
+
.option("-d, --detach", "Run in background")
|
|
74
|
+
.action(webCommand);
|
|
75
|
+
|
|
76
|
+
program
|
|
77
|
+
.command("alert")
|
|
78
|
+
.description("Configure alert thresholds and webhooks")
|
|
79
|
+
.option("--enable", "Enable alerts")
|
|
80
|
+
.option("--disable", "Disable alerts")
|
|
81
|
+
.option("--webhook <url>", "Set webhook URL for alerts")
|
|
82
|
+
.option("--cpu <percentage>", "CPU threshold percentage")
|
|
83
|
+
.option("--memory <percentage>", "Memory threshold percentage")
|
|
84
|
+
.option("--errorRate <percentage>", "Error rate threshold percentage")
|
|
85
|
+
.option("--uptime <percentage>", "Uptime threshold percentage")
|
|
86
|
+
.option("--cooldown <seconds>", "Alert cooldown period in seconds")
|
|
87
|
+
.option("--service <name>", "Configure alerts for specific service")
|
|
88
|
+
.option("--list", "List current alert configuration")
|
|
89
|
+
.option("--test", "Test webhook connectivity")
|
|
90
|
+
.action(alertCommand);
|
|
91
|
+
|
|
92
|
+
program
|
|
93
|
+
.command("export")
|
|
94
|
+
.description("Export historical metrics data")
|
|
95
|
+
.option("-f, --format <format>", "Export format (json|csv)", "json")
|
|
96
|
+
.option("-h, --hours <hours>", "Hours of data to export", "24")
|
|
97
|
+
.option("-o, --output <file>", "Output file path")
|
|
98
|
+
.option("-s, --service <name>", "Export specific service metrics")
|
|
99
|
+
.action(exportCommand);
|
|
100
|
+
|
|
101
|
+
program
|
|
102
|
+
.command("deps")
|
|
103
|
+
.description("Visualize service dependencies")
|
|
104
|
+
.option("-f, --format <format>", "Output format (text|dot|json)", "text")
|
|
105
|
+
.option("-o, --output <file>", "Output file path")
|
|
106
|
+
.action(depsCommand);
|
|
107
|
+
|
|
108
|
+
program
|
|
109
|
+
.command("profile")
|
|
110
|
+
.description("Performance profiling for services")
|
|
111
|
+
.option("-d, --duration <seconds>", "Profiling duration", "60")
|
|
112
|
+
.option("-i, --interval <ms>", "Sampling interval", "1000")
|
|
113
|
+
.option("-s, --service <name>", "Service name to profile")
|
|
114
|
+
.option("-o, --output <file>", "Output file path")
|
|
115
|
+
.action(profileCommand);
|
|
116
|
+
|
|
117
|
+
program
|
|
118
|
+
.command("loadbalancer")
|
|
119
|
+
.description("Load balancer management")
|
|
120
|
+
.argument("<action>", "Action to perform")
|
|
121
|
+
.option("-p, --port <port>", "Load balancer port", "8080")
|
|
122
|
+
.option("-a, --algorithm <type>", "Load balancing algorithm", "round-robin")
|
|
123
|
+
.option("-b, --backends <list>", "Backend servers (host:port,host:port)")
|
|
124
|
+
.option("--health-check", "Enable health checking", true)
|
|
125
|
+
.option("--health-path <path>", "Health check path", "/healthz")
|
|
126
|
+
.option("--health-interval <ms>", "Health check interval", "10000")
|
|
127
|
+
.action(loadbalancerCommand);
|
|
128
|
+
|
|
129
|
+
program
|
|
130
|
+
.command("dbpool")
|
|
131
|
+
.description("Database connection pool management")
|
|
132
|
+
.argument("<action>", "Action to perform")
|
|
133
|
+
.option("--host <host>", "Database host", "localhost")
|
|
134
|
+
.option("--port <port>", "Database port", "5432")
|
|
135
|
+
.option("--database <name>", "Database name", "testdb")
|
|
136
|
+
.option("--username <user>", "Database username", "user")
|
|
137
|
+
.option("--password <pass>", "Database password", "password")
|
|
138
|
+
.option("--max-connections <num>", "Maximum connections", "10")
|
|
139
|
+
.option("--min-connections <num>", "Minimum connections", "2")
|
|
140
|
+
.option("--concurrency <num>", "Test concurrency", "10")
|
|
141
|
+
.option("--iterations <num>", "Test iterations", "100")
|
|
142
|
+
.action(dbpoolCommand);
|
|
143
|
+
|
|
144
|
+
program.parse();
|