Skip to content

Server CLI Reference

The stowry binary provides commands for running and managing the Stowry server.

These flags are available for all commands:

Terminal window
--config, -c string Config file paths (can be specified multiple times, merged left-to-right)
--db-type string Database type (sqlite, postgres)
--db-dsn string Database connection string
--storage-path string Storage directory path
-h, --help Help for the command

Start the HTTP server.

Terminal window
stowry serve [flags]

Flags:

FlagTypeDefaultDescription
--portint5708HTTP server port
--modestringstoreServer mode (store, static, spa)

Examples:

Terminal window
# Start with defaults
stowry serve
# Custom port
stowry serve --port 8080
# Static file server mode
stowry serve --mode static
# SPA mode with custom config
stowry serve --mode spa --config /etc/stowry/config.yaml
# Override database via environment
STOWRY_DATABASE_TYPE=postgres \
STOWRY_DATABASE_DSN="postgres://localhost/stowry" \
stowry serve

Behavior:

  • 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

Import files from external paths into stowry storage.

Terminal window
stowry add [flags] <file1> [file2] ...

Flags:

FlagTypeDefaultDescription
--dest, -dstringDestination path prefix in storage
--recursive, -rboolfalseRecursively add directories
--no-clobber, -nboolfalseSkip existing files instead of overwriting
--quiet, -qboolfalseSuppress per-file output

Examples:

Terminal window
# Add a single file
stowry add /path/to/file.txt
# Add with a destination prefix
stowry add --dest images/ /path/to/photo.jpg
# Add a directory recursively
stowry add -r /path/to/assets
# Add files to a specific prefix without overwriting existing
stowry add --dest uploads/ --no-clobber /path/to/file.txt
# Quiet mode for scripting
stowry add -q -r /path/to/assets

Behavior:

  1. Copies files from the source path to the storage directory
  2. Registers metadata in the database (path, content type, hash, size)
  3. Content type is detected from file extension
  4. Existing files are overwritten by default (use --no-clobber to skip)
  5. For directories, requires --recursive flag

Output:

INFO added path=photo.jpg content_type=image/jpeg
INFO add complete added=5 skipped=2

Soft-delete files from stowry storage.

Terminal window
stowry remove [flags] <path1> [path2] ...

Flags:

FlagTypeDefaultDescription
--prefix, -pboolfalseTreat paths as prefixes and remove all matching files
--quiet, -qboolfalseSuppress per-file output

Examples:

Terminal window
# Remove a single file
stowry remove myfile.txt
# Remove multiple files
stowry remove file1.txt file2.txt file3.txt
# Remove all files with a prefix (e.g., a directory)
stowry remove --prefix images/
# Quiet mode for scripting
stowry remove -q file.txt

Behavior:

  1. Marks files as deleted by setting deleted_at timestamp in metadata
  2. Physical files remain on disk until stowry cleanup runs
  3. Deleted files are no longer accessible via the API
  4. With --prefix, removes all files matching the prefix (paginated internally)
  5. Non-existent paths are logged as warnings, not errors

Output:

INFO removed path=myfile.txt
INFO remove complete removed=3 not_found=1

Initialize the metadata database from existing storage files.

Terminal window
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:

Terminal window
# Initialize from default storage path
stowry init
# With custom paths
stowry init --storage-path /var/data --db-dsn /var/lib/stowry/metadata.db
# With PostgreSQL
stowry init --db-type postgres --db-dsn "postgres://localhost/stowry"

Behavior:

  1. Scans the storage directory recursively
  2. For each file found:
    • Calculates SHA256 hash (used as ETag)
    • Detects content type from file extension
    • Creates or updates metadata entry
  3. Reports total files indexed

Output:

INFO scanning storage directory path=./data
INFO initialization complete files_indexed=42

Permanently remove soft-deleted files from storage.

Terminal window
stowry cleanup [flags]

Flags:

FlagTypeDefaultDescription
--limitint100Maximum files to clean up per batch

Examples:

Terminal window
# Clean up with default limit
stowry cleanup
# Clean up more files
stowry cleanup --limit 500
# Clean up with custom config
stowry cleanup --config /etc/stowry/config.yaml --limit 1000

Behavior:

  1. Queries metadata for soft-deleted files (where deleted_at is set but cleaned_up_at is not)
  2. For each file:
    • Deletes the physical file from storage
    • Sets cleaned_up_at timestamp in metadata
  3. Reports total files cleaned

Output:

INFO starting cleanup limit=100
INFO cleanup complete files_cleaned=15

Scheduling:

Run cleanup periodically to reclaim storage space:

Terminal window
# Cron job (every hour)
0 * * * * /usr/local/bin/stowry cleanup --config /etc/stowry/config.yaml
# Systemd timer
[Timer]
OnCalendar=hourly
Persistent=true

Display help for any command.

Terminal window
stowry help [command]
stowry [command] --help

Examples:

Terminal window
stowry help
stowry help serve
stowry serve --help

Generate shell autocompletion scripts.

Terminal window
stowry completion [bash|zsh|fish|powershell]

Examples:

Terminal window
# Bash
stowry completion bash > /etc/bash_completion.d/stowry
# Zsh
stowry completion zsh > "${fpath[1]}/_stowry"
# Fish
stowry completion fish > ~/.config/fish/completions/stowry.fish
CodeMeaning
0Success
1General error

Stowry logs to stdout using structured logging (slog). Control verbosity with the log.level configuration option or STOWRY_LOG_LEVEL environment variable.

Terminal window
# Debug logging
STOWRY_LOG_LEVEL=debug stowry serve
# Quiet mode (errors only)
STOWRY_LOG_LEVEL=error stowry serve

Log format:

INFO starting server addr=:5708 mode=store
INFO connected to sqlite dsn=stowry.db