Documentation
¶
Overview ¶
Package natsserver is the flat group under osapi nats: osapi nats start, which runs the embedded NATS server as its own process.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Defaults = config.NATS{ Server: config.NATSServer{ Host: "localhost", Port: 4222, StoreDir: "/var/lib/osapi/jetstream", KeyDir: "/etc/osapi/pki", Namespace: "osapi", Auth: config.NATSServerAuth{Type: "operator"}, Metrics: config.MetricsServer{ Enabled: true, Host: "0.0.0.0", Port: 9092, TLS: config.ServerTLS{Enabled: true}, }, TLS: config.ServerTLS{Enabled: true}, }, Stream: config.NATSStream{ Name: "JOBS", Subjects: "jobs.>", MaxAge: "24h", MaxMsgs: 10000, Storage: "file", Replicas: 1, Discard: "old", }, KV: config.NATSKV{ Bucket: "job-queue", TTL: "1h", MaxBytes: 104857600, Storage: "file", Replicas: 1, }, DLQ: config.NATSDLQ{MaxAge: "168h", MaxMsgs: 1000, Storage: "file", Replicas: 1}, Audit: config.NATSAudit{ Stream: "AUDIT", Subject: "audit", MaxAge: "720h", MaxBytes: 52428800, Storage: "file", Replicas: 1, }, Registry: config.NATSRegistry{ Bucket: "agent-registry", TTL: "30s", Storage: "file", Replicas: 1, }, Facts: config.NATSFacts{Bucket: "agent-facts", TTL: "5m", Storage: "file", Replicas: 1}, State: config.NATSState{Bucket: "agent-state", Storage: "file", Replicas: 1}, Objects: config.NATSObjects{ Bucket: "file-objects", MaxBytes: 10737418240, Storage: "file", Replicas: 1, }, FileState: config.NATSFileState{Bucket: "file-state", Storage: "file", Replicas: 1}, Secrets: config.NATSSecrets{Bucket: "secrets", History: 10, Storage: "file", Replicas: 1}, Enrollment: config.NATSEnrollment{Bucket: "agent-enrollment", Storage: "file", Replicas: 1}, }
Defaults are the defaults of the nats section of the config, which nats start owns: the embedded server, and the names, limits and storage of each stream and bucket that osapi makes. osapi config default get prints them.
var Group = command.Register(command.Define( "nats", "Run the embedded NATS server", command.Flat(), command.Under(command.ParentNATS), command.Uses[Deps](), command.Config("nats", Defaults), command.Process("start"). Short("Start the embedded NATS server"). Long("The server makes the streams, consumers and KV buckets that the job system\n"+ "needs. `osapi start` runs the same server, together with the controller and\n"+ "an agent, in one process. Use this command to run the bus as its own\n"+ "process. The `nats.server` section of the config sets the host, the port and\n"+ "the authentication. Refer to [2. NATS](../../../operate/nats.md)."). Example(""). Logs(StartLogs...). Setup(Start), ))
Group is the nats server group's definition. It is flat, Under nats, so its method is osapi nats start.
var StartLogs = []command.LogLine{ { Level: slog.LevelInfo, Msg: "nats server started successfully", Attrs: []slog.Attr{slog.String("component", "nats")}, }, { Level: slog.LevelInfo, Msg: "embedded NATS server running", Attrs: []slog.Attr{ slog.String("component", "nats"), slog.String("host", "localhost"), slog.Int("port", 4222), slog.String("store_dir", ".nats/jetstream/"), slog.String("namespace", "osapi"), slog.String("auth.type", "none"), }, }, { Level: slog.LevelInfo, Msg: "metrics server started", Attrs: []slog.Attr{ slog.String("component", "nats"), slog.String("subsystem", "metrics"), slog.String("addr", "0.0.0.0:9092"), }, }, { Level: slog.LevelInfo, Msg: "http(s) server started", Attrs: []slog.Attr{ slog.String("component", "nats"), slog.String("subsystem", "metrics"), slog.String("address", "[::]:9092"), }, }, { Level: slog.LevelInfo, Msg: "registered in component registry", Attrs: []slog.Attr{ slog.String("component", "nats"), slog.String("subsystem", "nats.heartbeat"), slog.String("hostname", "web-03"), slog.String("type", "nats"), slog.String("key", "nats.web-03"), }, }, }
StartLogs are the lines that the NATS server writes at the info level when it starts with the default config, which the docs page of the command shows as the log handler writes them. osapi start writes them too.
Functions ¶
func Components ¶
Components makes the NATS server, and its metrics server when the config turns it on: the parts that osapi start runs too. ctx is the command's context: the heartbeat runs until it ends.
Types ¶
type Deps ¶
type Deps struct {
Config config.Config
ConfigFile string
Logger *slog.Logger
Version string
NewServer func(
ctx context.Context,
log *slog.Logger,
cfg config.NATS,
mp *sdkmetric.MeterProvider,
) (Server, error)
}
Deps is what start uses: the config, the log, the version of the binary, and what makes the server.