Skip to main content

Server

Struct Server 

Source
pub(crate) struct Server {
    config: Arc<Config>,
    reaper: Arc<ChildReaper>,
    tracer: Option<SdkTracerProvider>,
    streaming_server: Arc<StreamingServer>,
}
Expand description

The conmonrs process: it serves the RPCs of its configuration and holds what the calls share, the reaper of the containers and execs and the streaming server.

Fields§

§config: Arc<Config>§reaper: Arc<ChildReaper>§tracer: Option<SdkTracerProvider>

The tracer provider which exports the spans, if tracing is enabled.

§streaming_server: Arc<StreamingServer>

Implementations§

Source§

impl Server

Source

pub(crate) const MAX_BLOCKING_THREADS: usize = 16

Upper bound for the threads of the blocking pool, which serve file I/O like log writes, exit files and journald. Without a bound a burst of container exits or log reopens spawns a thread per operation (tokio’s default allows 512), each with its own stack. Work which blocks for an unbounded time, like waiting for a process, must run on a dedicated thread instead, or be capped, like ContainerLog::sync, otherwise it can starve the pool.

Source

const BLOCKING_THREAD_STACK_SIZE: usize

Stack size of the threads of the blocking pool, which only run short file and socket operations. The shutdown of the tracer, which exports the remaining spans, runs on one as well.

Source

const SHUTDOWN_TIMEOUT: Duration

How long the shutdown may take from the signal on, below the CLIENT_STOP_TIMEOUT of the clients, which send SIGINT. After SIGTERM, the Server::TERMINATE_GRACE is part of it. Every part of the shutdown gets its time from it.

Source

const TRACER_SHUTDOWN_TIMEOUT: Duration

How long the tracer may take to export the remaining spans, at the end of the shutdown.

Source

const RUNTIME_SHUTDOWN_TIMEOUT: Duration

How long the runtime waits for the threads of the blocking pool, at the very end of the shutdown.

Source

const CLEANUP_TIMEOUT: Duration

How long the cleanup may take: the grandchildren and the socket, whatever the tracer and the runtime leave.

Source

const SOCKET_REMOVAL_TIMEOUT: Duration

How long the removal of the socket may take at the end of the cleanup, through a blocking pool which stuck threads may fill up.

Source

const TERMINATE_GRACE: Duration

How long the containers may take to exit on SIGTERM before they get killed, as part of the Server::CLEANUP_TIMEOUT, so that SIGTERM does not make the shutdown take longer. Those which exited wrote their exit files by then. The rest of the cleanup kills the others, whose watchers then drain their output within DRAIN_MAX_WAIT, unless a log driver is slow, which they wait for up to DRAIN_MAX_LOG_WAIT, more than the rest of the cleanup leaves.

Source

const RPC_BUFFER_SIZE: usize = 4096

The read and write buffers of an RPC connection, which most messages fit into. Larger segments bypass them.

Source

pub(crate) fn config(&self) -> &Arc<Config> ⓘ

The configuration of the server.

Source

pub(crate) fn reaper(&self) -> &Arc<ChildReaper> ⓘ

The reaper of the containers and execs.

Source

pub(crate) fn streaming_server(&self) -> &Arc<StreamingServer> ⓘ

The streaming server of the exec, attach and port forward sessions.

Source

pub(crate) fn new(config: Config) -> Result<Self>

Create a new server for a validated and prepared configuration.

Source

pub(crate) fn with_config(config: Config) -> Self

A server for the configuration without the setup of the process, which tests must not change.

Source

pub(crate) fn start(self) -> Result<()>

Start the Server instance and consume it.

Source

fn exit_parent(&self, child: Pid) -> !

Write the PID of the forked child to the PID file and exit, which is all the parent does. It is the process which got started, still with its only thread, so it can exit the usual way: nothing but the profile runtime of a coverage build registered an exit handler, stdout holds no output, and the destructors of the thread locals, which the libc may run, only free memory.

Source

fn build_runtime() -> Result<Runtime>

The runtime of the server, see Server::MAX_BLOCKING_THREADS.

Source

fn log_early(&self, e: Error) -> Error

Log an error from before the logging got set up, and return it. The systemd driver still gets it into the journal, the standard streams are gone after the fork, see init::redirect_stdio. With the stdout driver, main prints it to the stderr of the caller.

Source

async fn serve(self) -> Result<()>

Set up the process to serve, once the logging is, and serve until the server ends. Its failures get logged, also the one of the backend, see Server::logged.

Source

fn logged(result: Result<Result<()>>) -> Result<()>

The result of the server, logged unless the shutdown logged it already: the outer one is a failure of the server itself, the inner one the result of the shutdown, see Server::start_signal_handler.

Source

fn shutdown_tracer( rt: &Runtime, tracer: Option<SdkTracerProvider>, ) -> Result<()>

Export the remaining spans. That needs the runtime the exporter was created on, so shut down from a blocking task while it is driven.

Source

fn init_logging(&mut self) -> Result<()>

Source

async fn run_tasks(self) -> Result<Result<()>>

Run the backend and the signal handler until the server ends, see Server::logged for the result.

Source

fn traced<F: Future>(future: F, span: Span) -> impl Future<Output = F::Output>

Run the future inside the span, which also carries the OpenTelemetry context if the feature is enabled.

Source

async fn start_signal_handler<T: AsRef<Path>>( signals: Result<[SignalStream; 3]>, reaper: Arc<ChildReaper>, socket: T, shutdown_tx: Sender<Result<()>>, )

Wait for a signal which shuts the server down and clean up, then end the backend with the result, which the server exits with. A server which cannot listen for the signals ends right away, after the same cleanup.

Source

fn listen_for_signals() -> Result<[SignalStream; 3]>

Listen for SIGTERM, SIGINT and SIGQUIT, which shut the server down. SIGQUIT like conmon, whose default action would end the server without the cleanup and leave its containers without a monitor. The other signals keep their default action.

Source

async fn wait_for_signal( signals: Result<[SignalStream; 3]>, reaper: &ChildReaper, ) -> Result<Instant>

Wait for SIGTERM, SIGINT or SIGQUIT, see Server::listen_for_signals, and return the deadline of the cleanup, counted from the signal. On SIGTERM, the containers get the Server::TERMINATE_GRACE of it to exit on it first, unless another SIGTERM, a SIGINT or a SIGQUIT asks for the shutdown meanwhile.

Source

async fn shutdown<T: AsRef<Path>>( reaper: Arc<ChildReaper>, socket: T, deadline: Instant, ) -> Result<()>

Clean up until the deadline, and report what did not finish.

Source

fn shutdown_result( received: Result<Result<()>, RecvError>, ) -> Result<Result<()>>

The result of the server once the signal handler sent the shutdown message, see Server::start_signal_handler, which logged it.

Source

async fn cleanup<T: AsRef<Path>>( reaper: Arc<ChildReaper>, socket: T, deadline: Instant, ) -> Result<()>

Kill the grandchildren and remove the socket file, until the deadline. Failures are collected rather than returned early, the server must stop in any case.

Source

async fn until( deadline: Instant, future: impl Future<Output = Result<()>>, ) -> Result<()>

Run the future until the deadline, fail if it did not finish by then.

Source

fn all_ok(results: impl IntoIterator<Item = Result<()>>) -> Result<()>

Succeed if all succeeded, fail with every failure otherwise.

Source

async fn start_backend( self, shutdown_rx: Receiver<Result<()>>, ) -> Result<Result<()>>

Serve the RPC socket until the shutdown message, see Server::logged for the result.

Trait Implementations§

Source§

impl Debug for Server

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Server for Server

Source§

fn version( self: Rc<Self>, params: VersionParams, results: VersionResults, ) -> Promise<(), Error> ⓘ

Retrieve version information from the server.

Source§

fn create_container( self: Rc<Self>, params: CreateContainerParams, results: CreateContainerResults, ) -> Promise<(), Error> ⓘ

Create a new container for the provided parameters.

Source§

fn exec_sync_container( self: Rc<Self>, params: ExecSyncContainerParams, results: ExecSyncContainerResults, ) -> Promise<(), Error> ⓘ

Execute a command in sync inside of a container.

Source§

fn attach_container( self: Rc<Self>, params: AttachContainerParams, _: AttachContainerResults, ) -> Promise<(), Error> ⓘ

Attach to a running container.

Source§

fn reopen_log_container( self: Rc<Self>, params: ReopenLogContainerParams, _: ReopenLogContainerResults, ) -> Promise<(), Error> ⓘ

Rotate all log drivers for a running container.

Source§

fn set_window_size_container( self: Rc<Self>, params: SetWindowSizeContainerParams, _: SetWindowSizeContainerResults, ) -> Promise<(), Error> ⓘ

Adjust the window size of a container running inside of a terminal.

Source§

fn create_namespaces_old( self: Rc<Self>, _: CreateNamespacesOldParams, _: CreateNamespacesOldResults, ) -> Promise<(), Error> ⓘ

Retired, the pause process which created the namespaces is gone.

Source§

fn start_fd_socket_old( self: Rc<Self>, _: StartFdSocketOldParams, _: StartFdSocketOldResults, ) -> Promise<(), Error> ⓘ

Retired, the fd socket is gone.

Source§

fn serve_exec_container( self: Rc<Self>, params: ServeExecContainerParams, results: ServeExecContainerResults, ) -> Promise<(), Error> ⓘ

Source§

fn serve_attach_container( self: Rc<Self>, params: ServeAttachContainerParams, results: ServeAttachContainerResults, ) -> Promise<(), Error> ⓘ

Source§

fn serve_port_forward_container( self: Rc<Self>, params: ServePortForwardContainerParams, results: ServePortForwardContainerResults, ) -> Promise<(), Error> ⓘ

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

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

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more