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
impl Server
Sourcepub(crate) const MAX_BLOCKING_THREADS: usize = 16
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.
Sourceconst BLOCKING_THREAD_STACK_SIZE: usize
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.
Sourceconst SHUTDOWN_TIMEOUT: Duration
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.
Sourceconst TRACER_SHUTDOWN_TIMEOUT: Duration
const TRACER_SHUTDOWN_TIMEOUT: Duration
How long the tracer may take to export the remaining spans, at the end of the shutdown.
Sourceconst RUNTIME_SHUTDOWN_TIMEOUT: Duration
const RUNTIME_SHUTDOWN_TIMEOUT: Duration
How long the runtime waits for the threads of the blocking pool, at the very end of the shutdown.
Sourceconst CLEANUP_TIMEOUT: Duration
const CLEANUP_TIMEOUT: Duration
How long the cleanup may take: the grandchildren and the socket, whatever the tracer and the runtime leave.
Sourceconst SOCKET_REMOVAL_TIMEOUT: Duration
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.
Sourceconst TERMINATE_GRACE: Duration
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.
Sourceconst RPC_BUFFER_SIZE: usize = 4096
const RPC_BUFFER_SIZE: usize = 4096
The read and write buffers of an RPC connection, which most messages fit into. Larger segments bypass them.
Sourcepub(crate) fn reaper(&self) -> &Arc<ChildReaper> ⓘ
pub(crate) fn reaper(&self) -> &Arc<ChildReaper> ⓘ
The reaper of the containers and execs.
Sourcepub(crate) fn streaming_server(&self) -> &Arc<StreamingServer> ⓘ
pub(crate) fn streaming_server(&self) -> &Arc<StreamingServer> ⓘ
The streaming server of the exec, attach and port forward sessions.
Sourcepub(crate) fn new(config: Config) -> Result<Self>
pub(crate) fn new(config: Config) -> Result<Self>
Create a new server for a validated and prepared configuration.
Sourcepub(crate) fn with_config(config: Config) -> Self
pub(crate) fn with_config(config: Config) -> Self
A server for the configuration without the setup of the process, which tests must not change.
Sourcefn exit_parent(&self, child: Pid) -> !
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.
Sourcefn build_runtime() -> Result<Runtime>
fn build_runtime() -> Result<Runtime>
The runtime of the server, see Server::MAX_BLOCKING_THREADS.
Sourcefn log_early(&self, e: Error) -> Error
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.
Sourceasync fn serve(self) -> Result<()>
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.
Sourcefn logged(result: Result<Result<()>>) -> Result<()>
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.
Sourcefn shutdown_tracer(
rt: &Runtime,
tracer: Option<SdkTracerProvider>,
) -> Result<()>
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.
fn init_logging(&mut self) -> Result<()>
Sourceasync fn run_tasks(self) -> Result<Result<()>>
async fn run_tasks(self) -> Result<Result<()>>
Run the backend and the signal handler until the server ends, see
Server::logged for the result.
Sourcefn traced<F: Future>(future: F, span: Span) -> impl Future<Output = F::Output>
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.
Sourceasync fn start_signal_handler<T: AsRef<Path>>(
signals: Result<[SignalStream; 3]>,
reaper: Arc<ChildReaper>,
socket: T,
shutdown_tx: Sender<Result<()>>,
)
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.
Sourcefn listen_for_signals() -> Result<[SignalStream; 3]>
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.
Sourceasync fn wait_for_signal(
signals: Result<[SignalStream; 3]>,
reaper: &ChildReaper,
) -> Result<Instant>
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.
Sourceasync fn shutdown<T: AsRef<Path>>(
reaper: Arc<ChildReaper>,
socket: T,
deadline: Instant,
) -> Result<()>
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.
Sourcefn shutdown_result(
received: Result<Result<()>, RecvError>,
) -> Result<Result<()>>
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.
Sourceasync fn cleanup<T: AsRef<Path>>(
reaper: Arc<ChildReaper>,
socket: T,
deadline: Instant,
) -> Result<()>
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.
Sourceasync fn until(
deadline: Instant,
future: impl Future<Output = Result<()>>,
) -> Result<()>
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.
Sourcefn all_ok(results: impl IntoIterator<Item = Result<()>>) -> Result<()>
fn all_ok(results: impl IntoIterator<Item = Result<()>>) -> Result<()>
Succeed if all succeeded, fail with every failure otherwise.
Sourceasync fn start_backend(
self,
shutdown_rx: Receiver<Result<()>>,
) -> Result<Result<()>>
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 Server for Server
impl Server for Server
Source§fn version(
self: Rc<Self>,
params: VersionParams,
results: VersionResults,
) -> Promise<(), Error> ⓘ
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> ⓘ
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> ⓘ
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> ⓘ
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> ⓘ
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> ⓘ
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> ⓘ
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> ⓘ
fn start_fd_socket_old( self: Rc<Self>, _: StartFdSocketOldParams, _: StartFdSocketOldResults, ) -> Promise<(), Error> ⓘ
Retired, the fd socket is gone.
fn serve_exec_container( self: Rc<Self>, params: ServeExecContainerParams, results: ServeExecContainerResults, ) -> Promise<(), Error> ⓘ
fn serve_attach_container( self: Rc<Self>, params: ServeAttachContainerParams, results: ServeAttachContainerResults, ) -> Promise<(), Error> ⓘ
fn serve_port_forward_container( self: Rc<Self>, params: ServePortForwardContainerParams, results: ServePortForwardContainerResults, ) -> Promise<(), Error> ⓘ
Auto Trait Implementations§
impl !RefUnwindSafe for Server
impl !UnwindSafe for Server
impl Freeze for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl UnsafeUnpin for Server
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].