xbp 0.9.4

XBP is a zero-config build pack that can also interact with proxies, kafka, sockets, synthetic monitors.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# XBP CLI Complete Guide


## Overview


XBP (eXtensible Build Pack) is a comprehensive deployment, monitoring, and logging toolkit with native support for Rust, Next.js, Node.js, Python, and more. It integrates tightly with Nginx, PM2, systemctl, and modern cloud DevOps workflows.

## Installation


```bash
cargo install xbp
# or build from source

cargo build --release --features kafka
```

## Core Commands


### 📊 Diagnostics


```bash
# Run full system diagnostics

xbp diag

# Check only Nginx configuration

xbp diag --nginx

# Check specific ports

xbp diag --ports 3000,8080,9090

# Skip internet speed test

xbp diag --no-speed-test
```

**What `xbp diag` checks:**

- CPU usage percentage
- RAM usage and availability
- Disk space
- Network statistics
- System uptime and process count
- Nginx status (running, enabled, config valid)
- Port availability and firewall blocking
- Internet connectivity
- Internet speed (download/upload/ping)

### 🔌 Port Management


```bash
# List all ports

xbp ports

# Check specific port

xbp ports -p 3000

# Kill processes on port

xbp ports -p 3000 --kill

# Check Nginx ports

xbp ports -n
```

### 🔧 Nginx Management


```bash
# Setup Nginx reverse proxy

xbp nginx setup --domain api.example.com --port 3000

# List all Nginx configurations

xbp nginx list

# Update existing configuration

xbp nginx update --domain api.example.com --port 3001
```

### Service Management


```bash
# List all services

xbp services

# Build a service

xbp service build my-api

# Install dependencies

xbp service install my-api

# Start a service

xbp service start my-api

# Run dev mode

xbp service dev my-api

# Show service help

xbp service --help my-api
```

### 🚀 Deployment


```bash
# Redeploy all services

xbp redeploy

# Redeploy specific service

xbp redeploy my-api

# Remote deployment

xbp redeploy-v2 -u username -h host -d /path/to/project
```

### 📝 PM2 Management


```bash
# List PM2 processes

xbp list

# View logs

xbp logs my-service

# Stop process

xbp pm2 my-service stop

# Start process

xbp pm2 my-service start

# Restart process

xbp pm2 my-service restart

# Delete process

xbp pm2 my-service delete
```

### 📡 Monitoring


```bash
# Run single health check

xbp monitor check

# Start monitoring daemon

xbp monitor start
```

**Configuration in `xbp.json`:**

```json
{
  "monitor_url": "https://api.example.com/health",
  "monitor_method": "GET",
  "monitor_expected_code": 200,
  "monitor_interval": 60
}
```

### 📋 Log Management


```bash
# Tail local log files

xbp tail

# Ship logs to Kafka

xbp tail --ship

# Tail Kafka topic

xbp tail --kafka
```

**Configuration in `xbp.json`:**

```json
{
  "log_files": [
    "/var/log/app/api.log",
    "/var/log/app/worker.log"
  ],
  "kafka_brokers": "localhost:9092",
  "kafka_topic": "application-logs",
  "kafka_public_url": "https://kafka.example.com"
}
```

### 🌐 HTTP Utilities


```bash
# Make HTTP request

xbp curl https://api.example.com/health

# With custom URL

xbp curl https://example.com/api/status
```

### Configuration


```bash
# View configuration

xbp config

# Setup XBP

xbp setup
```

### Package Installation


```bash
# Install package

xbp install docker
xbp install nginx
xbp install grafana
```

## Configuration File


### Complete `xbp.json` Example


```json
{
  "project_name": "my-application",
  "port": 3000,
  "build_dir": "/home/user/projects/my-app",
  "app_type": "rust",
  "build_command": "cargo build --release",
  "start_command": "./target/release/my-app",
  "install_command": "cargo fetch",
  
  "services": [
    {
      "name": "api",
      "target": "rust",
      "port": 3000,
      "branch": "main",
      "url": "https://api.example.com"
    },
    {
      "name": "frontend",
      "target": "nextjs",
      "port": 3001,
      "branch": "main",
      "url": "https://app.example.com"
    }
  ],
  
  "monitor_url": "https://api.example.com/health",
  "monitor_method": "GET",
  "monitor_expected_code": 200,
  "monitor_interval": 60,
  
  "log_files": [
    "/var/log/app/api.log",
    "/var/log/app/frontend.log"
  ],
  "kafka_brokers": "localhost:9092",
  "kafka_topic": "app-logs",
  "kafka_public_url": "https://kafka.example.com",
  
  "environment": {
    "NODE_ENV": "production",
    "RUST_LOG": "info"
  }
}
```

## API Mode


Start XBP as an API server:

```bash
export PORT_XBP_API=8080
xbp
```

API documentation available at `openapi.yaml`.

## Advanced Features


### Systemctl Integration


XBP automatically checks systemctl services:

- Nginx status and configuration
- Service health monitoring
- Auto-restart on failures

### Kafka Integration


Enable Kafka support:

```bash
cargo build --release --features kafka
```

Features:

- Real-time log streaming
- Topic tailing
- Bulk log shipping
- Automatic service name detection

### Monitoring Features


- Continuous health checks
- Response time tracking
- Status code validation
- Automatic alerting
- Configurable intervals

### Diagnostics Features


- CPU usage monitoring
- Memory usage tracking
- Disk space analysis
- Network statistics
- Port availability checking
- Firewall status
- Internet speed testing
- Nginx configuration validation

## Environment Variables


```bash
# API server port

PORT_XBP_API=8080

# Logging level

RUST_LOG=info

# Debug mode

XBP_DEBUG=1
```

## Exit Codes


- `0` - Success
- `1` - General error
- `2` - Configuration error
- `3` - Network error
- `4` - Service error

## Best Practices


1. **Always run `xbp diag` before deployment** to ensure system health
2. **Use `xbp monitor start`** for production monitoring
3. **Configure Kafka** for centralized logging in multi-server setups
4. **Keep `xbp.json`** in version control
5. **Use `xbp nginx setup`** for automatic reverse proxy configuration

## Troubleshooting


### Port conflicts


```bash
xbp ports -p 3000 --kill
```

### Nginx issues


```bash
xbp diag --nginx
```

### Service not starting


```bash
xbp service build my-service
xbp service install my-service
xbp service start my-service
```

### Logs not appearing


```bash
# Check log file paths

xbp config

# Verify Kafka connection

xbp tail --kafka
```

## Examples


### Deploy a Rust API


```bash
# Setup project

cd my-rust-api
xbp setup

# Configure Nginx

xbp nginx setup --domain api.example.com --port 3000

# Deploy

xbp service build api
xbp service start api

# Monitor

xbp monitor start
```

### Multi-service deployment


```json
{
  "services": [
    {"name": "api", "target": "rust", "port": 3000},
    {"name": "frontend", "target": "nextjs", "port": 3001},
    {"name": "worker", "target": "python", "port": 3002}
  ]
}
```

```bash
xbp services
xbp redeploy
```

### Centralized logging


```bash
# Ship logs to Kafka

xbp tail --ship

# On monitoring server, tail all logs

xbp tail --kafka
```

## Contributing


See `README.md` for contribution guidelines.

## License


MIT License - see `LICENSE` file.