Server CLI: serve, migrate, validate, populate
Server CLI Reference
Section titled “Server CLI Reference”The stowry binary provides commands for running and managing the Stowry server.
Global Flags
Section titled “Global Flags”Every configuration setting is reachable three ways, highest first: a flag, an
environment variable, then the config files. stowry <command> --help lists
each flag alongside the variable that reaches the same setting.
The ones used most often:
| Flag | Environment variable | Default | Description |
|---|---|---|---|
-c, --config |
STOWRY_CONFIG |
./config.yaml |
Config files, merged left to right |
--db-type |
STOWRY_DATABASE_TYPE |
sqlite |
Database type |
-d, --db-dsn |
STOWRY_DATABASE_DSN |
:memory: |
Database connection string |
-s, --storage-path |
STOWRY_STORAGE_PATH |
:memory: |
Storage directory |
-a, --access-key |
STOWRY_ACCESS_KEY |
- | Access key for signed requests |
-k, --secret-key |
STOWRY_SECRET_KEY |
- | Secret key for signed requests |
Both stores default to :memory:, so with no configuration the server keeps
nothing once it exits.
Commands
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) |
-m, --migrate |
bool | false | Create the metadata schema before serving |
-p, --populate |
bool | false | Record the files already in the storage directory before serving |
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, owner-only
- Migrates an in-memory database, since nothing else could have. A database on
disk is migrated only with
--migrate, or by runningstowry migratefirst - Rejects
auth.read: privateinstaticandspamodes at startup, because a browser cannot sign a request - Gracefully shuts down on SIGINT or SIGTERM
- Default read timeout: 30 seconds
- Default write timeout: 30 seconds
- Default idle timeout: 120 seconds
migrate
Section titled “migrate”Create the tables and indexes stowry needs, then confirm the result.
stowry migrate [flags]Run this before serving from a database on disk: serve migrates an in-memory
database only.
Flags:
| Flag | Type | Default | Description |
|---|---|---|---|
-p, --populate |
bool | false | Record the files already in the storage directory once the schema is in place |
Examples:
# Create the schemastowry migrate --db-dsn stowry.db
# Create it and record an existing directory of files in one gostowry migrate --db-dsn stowry.db --storage-path ./data --populate
# PostgreSQLstowry migrate --db-type postgres --db-dsn "postgres://localhost/stowry"Behavior:
- Idempotent: running it twice changes nothing
- Never alters a table that already exists. A table stowry did not build is reported rather than changed, so migrating onto an older or foreign schema fails instead of half-working
- Warns when the database is in memory, since nothing it creates will outlive the process
validate
Section titled “validate”Report whether the existing schema is the one stowry expects.
stowry validateNothing is created or altered, so this is what a deployment that migrates out
of band runs in place of migrate. It exits non-zero when the schema is
missing or wrong.
It checks the metadata table’s columns, their types and nullability, and the
unique constraint on path that every write depends on.
Examples:
stowry validate --db-dsn stowry.dbstowry validate --db-type postgres --db-dsn "postgres://localhost/stowry"populate
Section titled “populate”Record metadata for the files already in the storage directory, so a directory of existing files can be served without uploading anything.
stowry populate [flags]The files are read, never written: their layout under the storage path becomes the object paths.
Flags:
| Flag | Type | Default | Description |
|---|---|---|---|
-m, --migrate |
bool | false | Create the metadata schema first |
Examples:
# Record an existing directorystowry populate --db-dsn stowry.db --storage-path ./data
# Create the schema and record in one gostowry populate --db-dsn stowry.db --storage-path ./data --migrate
# Pick up whatever changed on diskstowry populate --db-dsn stowry.db --storage-path ./dataBehavior:
- Repeatable: an entry that already exists is updated in place, picking up whatever changed on disk
- The schema must already exist unless
--migrateis passed - A file whose path the server could not serve stops the run, and the entries recorded before it are kept
- This is how content reaches a
staticorspaserver, which route no writes
Display 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 connected to database type=sqliteINFO starting server addr=:5708