CLI Reference
CLI Reference
Section titled “CLI Reference”Stowry provides a command-line interface for managing the server and performing administrative tasks.
Global Flags
Section titled “Global Flags”These flags are available for all commands:
--config string Config file path (default "config.yaml")--db-type string Database type (sqlite, postgres)--db-dsn string Database connection string--db-table string Database table name--storage-path string Storage directory path-h, --help Help for the commandCommands
Section titled “Commands”Start the HTTP server.
stowry serve [flags]Flags:
| Flag | Type | Default | Description |
|---|---|---|---|
--port | int | 5708 | HTTP server port |
--mode | string | store | Server mode (store, static, spa) |
Examples:
# Start with defaultsstowry serve
# Custom portstowry serve --port 8080
# Static file server modestowry serve --mode static
# SPA mode with custom configstowry serve --mode spa --config /etc/stowry/config.yaml
# Override database via environmentSTOWRY_DATABASE_TYPE=postgres \STOWRY_DATABASE_DSN="postgres://localhost/stowry" \stowry serveBehavior:
- Creates the storage directory if it doesn’t exist
- Runs database migrations automatically
- Gracefully shuts down on SIGINT or SIGTERM
- Default read timeout: 30 seconds
- Default write timeout: 30 seconds
- Default idle timeout: 120 seconds
Initialize the metadata database from existing storage files.
stowry init [flags]Use Cases:
- Setting up Stowry with pre-existing files
- Recovering metadata after database loss or corruption
- Migrating from another storage system
Examples:
# Initialize from default storage pathstowry init
# With custom pathsstowry init --storage-path /var/data --db-dsn /var/lib/stowry/metadata.db
# With PostgreSQLstowry init --db-type postgres --db-dsn "postgres://localhost/stowry"Behavior:
- Scans the storage directory recursively
- For each file found:
- Calculates SHA256 hash (used as ETag)
- Detects content type from file extension
- Creates or updates metadata entry
- Reports total files indexed
Output:
INFO scanning storage directory path=./dataINFO initialization complete files_indexed=42cleanup
Section titled “cleanup”Permanently remove soft-deleted files from storage.
stowry cleanup [flags]Flags:
| Flag | Type | Default | Description |
|---|---|---|---|
--limit | int | 100 | Maximum files to clean up per batch |
Examples:
# Clean up with default limitstowry cleanup
# Clean up more filesstowry cleanup --limit 500
# Clean up with custom configstowry cleanup --config /etc/stowry/config.yaml --limit 1000Behavior:
- Queries metadata for soft-deleted files (where
deleted_atis set butcleaned_up_atis not) - For each file:
- Deletes the physical file from storage
- Sets
cleaned_up_attimestamp in metadata
- Reports total files cleaned
Output:
INFO starting cleanup limit=100INFO cleanup complete files_cleaned=15Scheduling:
Run cleanup periodically to reclaim storage space:
# Cron job (every hour)0 * * * * /usr/local/bin/stowry cleanup --config /etc/stowry/config.yaml
# Systemd timer[Timer]OnCalendar=hourlyPersistent=trueDisplay help for any command.
stowry help [command]stowry [command] --helpExamples:
stowry helpstowry help servestowry serve --helpcompletion
Section titled “completion”Generate shell autocompletion scripts.
stowry completion [bash|zsh|fish|powershell]Examples:
# Bashstowry completion bash > /etc/bash_completion.d/stowry
# Zshstowry completion zsh > "${fpath[1]}/_stowry"
# Fishstowry completion fish > ~/.config/fish/completions/stowry.fishExit Codes
Section titled “Exit Codes”| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General error |
Logging
Section titled “Logging”Stowry logs to stdout using structured logging (slog). Control verbosity with the log.level configuration option or STOWRY_LOG_LEVEL environment variable.
# Debug loggingSTOWRY_LOG_LEVEL=debug stowry serve
# Quiet mode (errors only)STOWRY_LOG_LEVEL=error stowry serveLog format:
INFO starting server addr=:5708 mode=storeINFO connected to sqlite dsn=stowry.db