Struct sopht::manager::State

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

the state of the sopht process manager. contains all processes started and all other configuration/state

Implementations§

source§

impl State

source

pub fn new(stay_alive_secs: u64) -> Self

creates a new State with the specified configuration

source

pub fn start(&mut self, args: &StartArgs) -> Result<ProcessStatus>

starts a process given a command string and adds it to the processes list. the process must stay alive for the stay_alive_duration to be considered started. if the process does not stay alive long enough, a StayAliveError will be returned. the process’s output will still be collected and it will still be assigned a PID and stored in the process list. if the process fail to start, a ProcessError will be returned

source

pub fn output(&mut self, args: PID) -> Result<&Vec<u8>>

retrieves the output of the specified process as a slice of its lines of output. this function can fail if the PID supplied is out of range with an InvalidPID error

source

pub fn status(&mut self, count: &Option<usize>) -> Vec<ProcessStatus>

retrieves the status of all processes unless count is specified, in which case the last count processes’ status

source

pub fn stop(&mut self, args: PID) -> Result<ProcessStatus>

attempts to stop a process given its PID. this function can fail if the PID supplied is out of range (InvalidPID) or if killing the process fails (ProcessError). additionally, this function sets the restart policy of the process to Never so it won’t be restarted

source

pub fn restart(&mut self, args: PID, retry: bool) -> Result<ProcessStatus>

stops a particular process and then start it again with a new PID. this function just calls State::start and State::stop internally, so it can fail in exactly the same ways those functions can. the retry parameter signifies whether or not this restart is a manual restart or an automatic retry by State::upkeep. if retry is true, then the restart policy will be copied to the restartd process. in the case of the RestartPolicy::OnFailure policy, then this restart will count against its retries and subtract 1 from it

source

pub fn send(&mut self, args: &SendArgs) -> Result<()>

send input to a process given its PID and input. this function can fail if the PID is invalid (InvalidPID) or if the input fails to send (ProcessError)

source

pub fn status_of(&mut self, pid: PID) -> ProcessStatus

generates a ProcessStatus for a PID. this function will panic if supplied an invalid PID, so checking the PID is up to the caller!

source

pub fn change_restart_policy( &mut self, args: &ChangeRestartPolicyArgs ) -> Result<ProcessStatus>

changes the restart policy of the specified process to the specified policy

source

pub fn check_pid(&self, pid: PID) -> Result<PID>

utility method for checking if a PID is valid. fails with InvalidPID if the PID is invalid and returns the PID itself otherwise

source

pub fn upkeep(&mut self) -> Result<UpkeepInfo>

handles any periodic upkeep the state needs. currently, this is only restarting any crashed processes that have their restart policy set. returns an UpkeepInfo structure containing which processes were restarted

Trait Implementations§

source§

impl Drop for State

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for State

§

impl Send for State

§

impl !Sync for State

§

impl Unpin for State

§

impl !UnwindSafe for State

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.