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", "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§
source§impl RunConfig
impl RunConfig
sourcepub fn bind(self, port: PortDescriptor) -> Self
pub fn bind(self, port: PortDescriptor) -> Self
Adds a PortDescriptor to the Kvarn server.
sourcepub fn disable_ctl(self) -> Self
Available on crate feature handover only.
pub fn disable_ctl(self) -> Self
handover only.sourcepub fn set_ctl_path(self, path: impl AsRef<Path>) -> Self
Available on crate feature handover only.
pub fn set_ctl_path(self, path: impl AsRef<Path>) -> Self
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.
sourcepub fn add_plugin(self, name: impl AsRef<str>, plugin: Plugin) -> Self
Available on crate feature handover only.
pub fn add_plugin(self, name: impl AsRef<str>, plugin: Plugin) -> Self
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.
sourcepub async fn execute(self) -> Arc<Manager>
pub async fn execute(self) -> Arc<Manager>
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
webto serve files only if the featurefsis enabled. Place them inweb/publicto 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 fromweb/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", "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;