ProcessSupervisor

Struct ProcessSupervisor 

Source
pub struct ProcessSupervisor { /* private fields */ }
Expand description

Process supervisor for managing upstream application servers

The ProcessSupervisor spawns and monitors a child process, forwarding signals and handling graceful shutdown. It’s designed to work with application servers that listen on a specific port.

Implementations§

Source§

impl ProcessSupervisor

Source

pub fn new(command: String, args: Vec<String>) -> Self

Create a new process supervisor

§Arguments
  • command - The command to execute (e.g., “bundle”, “node”)
  • args - Command-line arguments
§Example
use warpdrive::process::ProcessSupervisor;

let supervisor = ProcessSupervisor::new(
    "bundle".to_string(),
    vec!["exec".to_string(), "puma".to_string()],
);
Source

pub async fn start(&self, port: u16) -> Result<()>

Start the child process with the specified port

Spawns the child process with the PORT environment variable set. The process inherits stdin, stdout, and stderr from the parent.

§Arguments
  • port - Port number to pass via PORT environment variable
§Errors

Returns an error if:

  • The command cannot be found or executed
  • The process is already running
§Example
let mut supervisor = ProcessSupervisor::new("rails".to_string(), vec!["server".to_string()]);
supervisor.start(3000).await?;
Source

pub async fn wait(&self) -> Result<i32>

Wait for the child process to exit

This method blocks until the child process terminates and returns the exit code. A non-zero exit code indicates the process was terminated by a signal or crashed.

§Errors

Returns an error if:

  • No process is running
  • Failed to wait for the process
§Returns

The exit code of the process (0 for success, non-zero for error/signal)

§Example
let exit_code = supervisor.wait().await?;
println!("Process exited with code: {}", exit_code);
Source

pub async fn stop(&self) -> Result<()>

Stop the child process gracefully

Sends SIGTERM to the process and waits for it to exit within the timeout period. If the process doesn’t exit within the timeout, sends SIGKILL to force termination.

§Errors

Returns an error if:

  • No process is running
  • Failed to send signals to the process
§Example
supervisor.stop().await?;
Source

pub async fn handle_signals(&self)

Handle signals and forward them to the child process

This method listens for SIGTERM and SIGINT signals and forwards them to the child process. It should be spawned in a background task.

The method will block until a signal is received or the shutdown notification is triggered.

§Example
// Spawn signal handler in background
let signal_handle = tokio::spawn({
    let supervisor = supervisor.clone();
    async move {
        supervisor.handle_signals().await;
    }
});

// Later, clean up
signal_handle.abort();
Source

pub async fn wait_for_start(&self)

Wait for the process to start

This method blocks until the start() method has been called and the process has been spawned.

§Example
// Start in background
let supervisor_clone = supervisor.clone();
tokio::spawn(async move {
    supervisor_clone.start(3000).await.unwrap();
});

// Wait for startup
supervisor.wait_for_start().await;
println!("Process has started");
Source

pub fn trigger_shutdown(&self)

Trigger shutdown notification

This notifies the signal handler to stop listening for signals.

Source

pub async fn is_running(&self) -> bool

Check if the process is currently running

Returns true if a child process is running, false otherwise.

§Example
if supervisor.is_running().await {
    println!("Process is running");
}

Trait Implementations§

Source§

impl Clone for ProcessSupervisor

Source§

fn clone(&self) -> ProcessSupervisor

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,