xbp 10.13.1

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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
---
title: CLI Reference
description: Complete reference for all XBP CLI commands
---

# CLI Reference

Complete reference for all XBP commands, options, and flags.

## Global Options

Available for all commands:

### `--debug`
Enable debug mode with verbose output.

```bash
xbp --debug diag
```

### `-l, --list`
List PM2 processes (shorthand).

```bash
xbp -l
```

### `-p, --port <PORT>`
Filter by port number (for ports command).

```bash
xbp -p 3000
```

## Commands

### Diagnostics

#### `xbp diag`
System diagnostics and health checks.

```bash
xbp diag [--nginx] [--ports <PORTS>] [--no-speed-test]
```

**Options:**
- `--nginx` - Check only Nginx
- `--ports <PORTS>` - Check specific ports (comma-separated)
- `--no-speed-test` - Skip internet speed test

[Full Documentation](/docs/commands/diag)

### Monitoring

#### `xbp monitor check`
Run single health check.

```bash
xbp monitor check
```

#### `xbp monitor start`
Start monitoring daemon.

```bash
xbp monitor start
```

[Full Documentation](/docs/commands/monitor)

### Logging

#### `xbp tail`
Tail log files.

```bash
xbp tail [--kafka] [--ship]
```

**Options:**
- `--kafka` - Tail from Kafka topic
- `--ship` - Ship logs to Kafka

[Full Documentation](/docs/commands/tail)

### Port Management

#### `xbp ports`
List and manage network ports.

```bash
xbp ports [-p <PORT>] [--kill] [-n]
```

**Options:**
- `-p, --port <PORT>` - Filter by port
- `--kill` - Kill processes on port
- `-n, --nginx` - Show only Nginx ports

[Full Documentation](/docs/commands/ports)

### Service Management

#### `xbp services`
List all services.

```bash
xbp services
```

#### `xbp service <COMMAND> <NAME>`
Run service command.

```bash
xbp service build api
xbp service install frontend
xbp service start worker
xbp service dev api
```

**Commands:**
- `build` - Build the service
- `install` - Install dependencies
- `start` - Start the service
- `dev` - Run in development mode
- `stop` - Stop the service

### Deployment

#### `xbp redeploy [SERVICE]`
Redeploy services.

```bash
xbp redeploy           # All services
xbp redeploy api       # Specific service
```

#### `xbp redeploy-v2`
Remote deployment.

```bash
xbp redeploy-v2 -u <USER> -h <HOST> -d <DIR> [-p <PASSWORD>]
```

**Options:**
- `-u, --username <USER>` - SSH username
- `-h, --host <HOST>` - SSH host
- `-d, --project-dir <DIR>` - Project directory
- `-p, --password <PASSWORD>` - SSH password (optional)

### Nginx Management

#### `xbp nginx setup`
Setup reverse proxy.

```bash
xbp nginx setup --domain <DOMAIN> --port <PORT>
```

**Options:**
- `-d, --domain <DOMAIN>` - Domain name
- `-p, --port <PORT>` - Port to proxy to

#### `xbp nginx list`
List Nginx configurations.

```bash
xbp nginx list
```

#### `xbp nginx update`
Update Nginx configuration.

```bash
xbp nginx update --domain <DOMAIN> --port <PORT>
```

### PM2 Management

#### `xbp list`
List PM2 processes.

```bash
xbp list
```

#### `xbp logs [PROJECT]`
View PM2 logs.

```bash
xbp logs              # All logs
xbp logs api          # Specific service
```

**Options:**
- `--ssh-host <HOST>` - SSH host to stream remote logs from.
- `--ssh-username <USER>` - SSH username for the remote server.
- `--ssh-password <PASSWORD>` - SSH password for the remote server.

### Utilities

#### `xbp config`
View configuration.

```bash
xbp config
```

#### `xbp setup`
Initial setup.

```bash
xbp setup
```

#### `xbp curl <URL>`
Make HTTP request.

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

#### `xbp install <PACKAGE>`
Install package.

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

#### `xbp generate systemd`
Generate systemd service units from the current `.xbp/xbp.yaml`.

```bash
xbp generate systemd [--service <SERVICE>] [--output-dir /etc/systemd/system]
```

**Options:**
- `--service <SERVICE>` - Only emit the unit for a single service name.
- `--output-dir <DIR>` - Write units to a custom directory (default `/etc/systemd/system`).

> Running this command on Linux usually requires root privileges when targeting `/etc/systemd/system`. Review the generated files before enabling them with `systemctl daemon-reload` and `systemctl enable`.

## Command Chaining

### Sequential Execution

```bash
xbp diag && xbp service build api && xbp service start api
```

### Conditional Execution

```bash
xbp monitor check || echo "Health check failed"
```

### Background Execution

```bash
xbp monitor start &
xbp tail --ship &
```

## Environment Variables

### `PORT_XBP_API`
Start XBP in API mode.

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

### `RUST_LOG`
Set logging level.

```bash
export RUST_LOG=debug
xbp diag
```

### `XBP_DEBUG`
Enable debug mode.

```bash
export XBP_DEBUG=1
xbp services
```

## Exit Codes

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

## Output Formats

### Standard Output

```
[component] message
```

### Success

```
[component]  Success message
```

### Warning

```
[component]  Warning message
```

### Error

```
[component]  Error message
```

## Piping and Redirection

### Save Output

```bash
xbp diag > diagnostics.txt
```

### Append to File

```bash
xbp monitor check >> health-checks.log
```

### Filter Output

```bash
xbp tail | grep ERROR
```

### Count Lines

```bash
xbp ports | wc -l
```

## Scripting Examples

### Bash Script

```bash
#!/bin/bash

# Health check script
if xbp monitor check; then
    echo "Service is healthy"
    exit 0
else
    echo "Service is down"
    xbp service start api
    exit 1
fi
```

### Python Script

```python
import subprocess
import sys

result = subprocess.run(['xbp', 'monitor', 'check'], 
                       capture_output=True)
if result.returncode == 0:
    print("Health check passed")
else:
    print("Health check failed")
    sys.exit(1)
```

### Node.js Script

```javascript
const { exec } = require('child_process');

exec('xbp monitor check', (error, stdout, stderr) => {
  if (error) {
    console.error('Health check failed');
    process.exit(1);
  }
  console.log('Health check passed');
});
```

## Aliases

Create shortcuts for common commands:

```bash
# Add to ~/.bashrc or ~/.zshrc
alias xd='xbp diag'
alias xm='xbp monitor check'
alias xl='xbp tail'
alias xp='xbp ports'
alias xs='xbp services'
```

## Tab Completion

### Bash

```bash
# Add to ~/.bashrc
eval "$(xbp --completion bash)"
```

### Zsh

```bash
# Add to ~/.zshrc
eval "$(xbp --completion zsh)"
```

### Fish

```bash
# Add to ~/.config/fish/config.fish
xbp --completion fish | source
```

## Tips and Tricks

1. **Use `--debug`** for troubleshooting
2. **Pipe to `jq`** for JSON formatting
3. **Combine with `watch`** for monitoring
4. **Use `&&` and `||`** for conditional execution
5. **Create aliases** for frequent commands
6. **Save output** for later analysis
7. **Use environment variables** for configuration

## Common Workflows

### Development

```bash
# Start development
xbp diag
xbp service dev api
xbp tail
```

### Deployment

```bash
# Deploy to production
xbp diag
xbp service build api
xbp service start api
xbp monitor start
```

### Troubleshooting

```bash
# Debug issues
xbp diag --debug
xbp ports -p 3000
xbp logs api
xbp monitor check
```

### Monitoring

```bash
# Set up monitoring
xbp monitor start &
xbp tail --ship &
watch xbp ports
```

## See Also

- [Configuration Guide](/docs/configuration)
- [Installation Guide](/docs/installation)
- [Command Documentation](/docs/commands/diag)
- [Guides](/docs/guides/monitoring)