Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Getting Started with the gRPC Server

Starting the Server

The gRPC server is started via the serve subcommand of the laurus CLI:

laurus serve [OPTIONS]

Options

OptionShortEnv VariableDefaultDescription
--config <PATH>-cLAURUS_CONFIG–Path to a TOML configuration file
--host <HOST>-HLAURUS_HOST0.0.0.0Listen address
--port <PORT>-pLAURUS_PORT50051Listen port
--http-port <PORT>–LAURUS_HTTP_PORT–HTTP Gateway port (enables HTTP gateway when set)
--max-result-window <N>–LAURUS_MAX_RESULT_WINDOW10000Largest offset + limit per search; larger searches are rejected

Log verbosity is controlled by the standard RUST_LOG environment variable (default: info). See env_logger syntax for filter directives such as RUST_LOG=laurus=debug,tonic=warn.

The global --index-dir option (env: LAURUS_INDEX_DIR) specifies the index data directory:

# Using CLI arguments
laurus --index-dir ./my_index serve --port 8080

# Using environment variables
export LAURUS_INDEX_DIR=./my_index
export LAURUS_PORT=8080
export RUST_LOG=debug
laurus serve

Startup Behavior

On startup, the server attempts to open an existing index at the configured data directory:

  • No index at that directory (no schema.toml) – the server starts without one; you can create an index later via the CreateIndex RPC.
  • An index exists and opens successfully – the server serves it immediately.
  • An index exists but fails to open (a stale lock left by an unclean shutdown, a corrupt schema.toml, a failed WAL replay, …) – the server logs the cause at error level and exits with a non-zero status instead of starting as if the directory were empty. See Recovering from an Unclean Shutdown.
  • Another process is creating or opening the index at that moment (for example, a laurus create index or a binding’s Index on the same directory) – the server exits the same way, with an error saying that the index is being created or opened by another call (Issue #1665). Start it again once that call has finished.

Configuration

You can use a TOML configuration file instead of (or in addition to) command-line options. See Configuration for the full reference.

laurus serve --config config.toml

HTTP Gateway

When --http-port is set, an HTTP/JSON gateway starts alongside the gRPC server. See HTTP Gateway for the full endpoint reference and examples.

laurus serve --http-port 8080

Graceful Shutdown

When the server receives a shutdown signal – Ctrl+C / SIGINT, or SIGTERM (the signal docker stop, Kubernetes and systemd send) on Unix – it automatically:

  1. Stops accepting new connections
  2. Commits any pending changes to the index
  3. Releases the index lock
  4. Exits cleanly

On non-Unix platforms, only Ctrl+C / SIGINT triggers this sequence.

Recovering from an Unclean Shutdown

A running server holds an exclusive lock on its data directory, <data-dir>/store/engine.lock. The lock is released as part of the graceful shutdown above, so a normal docker stop, systemctl stop, or Ctrl+C never leaves it behind.

If the process is killed outright – kill -9, a container OOM-kill, a host crash – the lock file can survive the process. The next start then fails to open the index (see Startup Behavior above) with an error naming the lock file. To recover:

  1. Confirm no laurus serve process is still using the data directory (e.g. ps aux | grep laurus and check its index directory, or confirm the host that held it has in fact restarted).
  2. Delete <data-dir>/store/engine.lock.
  3. Start the server again.

Removing the lock does not touch the index data itself; it only stops the engine from refusing to reopen a directory it believes is already in use.

Do not delete <data-dir>/index.lock. It is not a stale lock: the operating system releases its lock when the process that holds it exits, and it only keeps creates and opens of the index from running at the same moment (see Concurrent creates and opens).

Connecting via gRPC

Any gRPC client can connect to the server. For quick testing, grpcurl is useful:

# Health check
grpcurl -plaintext localhost:50051 laurus.v1.HealthService/Check

# Create an index
grpcurl -plaintext -d '{
  "schema": {
    "fields": {
      "title": {"text": {"indexed": true, "stored": true, "term_vectors": true}},
      "body": {"text": {"indexed": true, "stored": true, "term_vectors": true}}
    },
    "default_fields": ["title", "body"]
  }
}' localhost:50051 laurus.v1.IndexService/CreateIndex

# Add a document
grpcurl -plaintext -d '{
  "id": "doc1",
  "document": {
    "fields": {
      "title": {"text_value": "Hello World"},
      "body": {"text_value": "This is a test document."}
    }
  }
}' localhost:50051 laurus.v1.DocumentService/AddDocument

# Commit
grpcurl -plaintext localhost:50051 laurus.v1.DocumentService/Commit

# Search
grpcurl -plaintext -d '{"query": "body:test", "limit": 10}' \
  localhost:50051 laurus.v1.SearchService/Search

See gRPC API Reference for the full API documentation, or try the Hands-on Tutorial for a step-by-step walkthrough using the HTTP Gateway.