Struct kvarn::RunConfig

source ·
pub struct RunConfig { /* private fields */ }
Expand description

Configuration for Self::execute. This mainly consists of an array of PortDescriptors.

It also allows control of handover.

Will bind a TcpListener on every port added using Self::bind

This ↑ will change when HTTP/3 support arrives, then Udp will also be used.

Examples

See Self::execute as it uses this, created by a macro invocation.

let host = Host::unsecure("localhost", PathBuf::from("web"), Extensions::default(), host::Options::default());
let data = HostCollection::builder().insert(host).build();
let port_descriptor = PortDescriptor::new(8080, data);

let config = RunConfig::new()
    .bind(port_descriptor)
    .set_ctl_path("/run/kvarn-instance-1.sock");
config.execute().await.shutdown();

Implementations

Creates an empty RunConfig.

Adds a PortDescriptor to the Kvarn server.

Available on crate feature handover only.

Disables handover and ctl for the instance of Kvarn.

This can enable multiple Kvarn servers to run on the same machine.

Available on crate feature handover only.

Sets the path of the socket where the handover and ctl is managed.

By default, this is /run/user/<uid>/kvarn.sock for users and /run/kvarn.sock for root users.

This can enable multiple Kvarn servers to run on the same machine. If each application (as in an use for Kvarn) has it’s own path, multiple can coexist.

Available on crate feature handover only.

Add plugin to be executed when a command with name is received from kvarnctl.

Adding multiple with the same name overrides the old one.

See ctl::Plugins for the default ctl::Plugins that are added.

Run the Kvarn web server on ports.

This is the last step in getting Kvarn spinning. You can interact with the caches through the Host and HostCollection you created, and the returned shutdown::Manager, if you have the graceful-shutdown feature enabled.

Examples

Will start a bare-bones web server on port 8080, using the dir web to serve files.

Note: it uses web to serve files only if the feature fs is enabled. Place them in web/public to access them in your user-agent. It’s done this way to enable you to have domain-specific files not being public to the web, and for a place to store other important files. Kvarn extensions’ template system will in this case read template files from web/templates.

use kvarn::prelude::*;

// Create a host with hostname "localhost", serving files from directory "./web/public/", with the default extensions and the default options.
let host = Host::unsecure("localhost", PathBuf::from("web"), Extensions::default(), host::Options::default());
// Create a set of virtual hosts (`HostCollection`) with `host` as the default.
let data = HostCollection::builder().insert(host).build();
// Bind port 8080 with `data`.
let port_descriptor = PortDescriptor::new(8080, data);

// Run with the configured ports.
let shutdown_manager = run_config![port_descriptor].execute().await;
// Waits for shutdown.
shutdown_manager.wait().await;

Trait Implementations

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more