pub fn run(
hexz_path: &str,
port: u16,
bind: &str,
daemon: bool,
nbd: bool,
) -> Result<()>Expand description
Executes the serve command to start a network server.
Opens a Hexz archive and starts a server that exposes it over HTTP, NBD, or S3 protocol. The server runs until interrupted (Ctrl+C) or, in daemon mode, until explicitly killed.
§Arguments
hexz_path- Path to the.hxzarchive file to serveport- TCP port to bind todaemon- If true, daemonize the process and run in backgroundnbd- If true, use NBD protocol; otherwise use HTTPs3- If true, use S3 gateway mode (not yet implemented)
§Server Startup Sequence
-
Daemonization (if requested):
- Detach from terminal
- Redirect stdout to
/tmp/hexz-serve.log - Redirect stderr to
/tmp/hexz-serve.err
-
Archive Loading:
- Open archive file via
MmapBackend - Read and parse header
- Load compression dictionary if present
- Initialize decompressor (LZ4 or Zstd)
- Open archive file via
-
Server Start:
- Create Tokio multi-threaded runtime
- Start HTTP or NBD server on specified port
- Listen for incoming connections
-
Serving:
- Handle requests until process is interrupted
- Each request decompresses data on-demand
- No persistent state or caching
§Protocol Selection
- If
nbd=true: Start NBD server viahexz_server::serve_nbd() - If
s3=true: Reserved for future S3 gateway (currently prints error) - Otherwise: Start HTTP server via
hexz_server::serve_http()
§Errors
Returns an error if:
- Archive file cannot be opened or read
- Header or dictionary cannot be parsed (corrupted archive)
- Port is already in use (address binding fails)
- Daemonization fails (resource limits, permissions)
- Server fails to start (Tokio runtime error)
§Examples
use hexz_cli::cmd::sys::serve;
// Start HTTP server on port 8080
serve::run(
"archive.hxz",
8080,
"127.0.0.1",
false, // not daemon
false, // HTTP mode
)?;
// Start NBD server as daemon
serve::run(
"archive.hxz",
10809,
"127.0.0.1",
true, // daemon mode
true, // NBD mode
)?;