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
impl State
sourcepub fn start(&mut self, args: &StartArgs) -> Result<ProcessStatus>
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
sourcepub fn output(&mut self, args: PID) -> Result<&Vec<u8>>
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
sourcepub fn status(&mut self, count: &Option<usize>) -> Vec<ProcessStatus>
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
sourcepub fn stop(&mut self, args: PID) -> Result<ProcessStatus>
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
sourcepub fn restart(&mut self, args: PID, retry: bool) -> Result<ProcessStatus>
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
sourcepub fn send(&mut self, args: &SendArgs) -> Result<()>
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
)
sourcepub fn status_of(&mut self, pid: PID) -> ProcessStatus
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!
sourcepub fn change_restart_policy(
&mut self,
args: &ChangeRestartPolicyArgs
) -> Result<ProcessStatus>
pub fn change_restart_policy( &mut self, args: &ChangeRestartPolicyArgs ) -> Result<ProcessStatus>
changes the restart policy of the specified process to the specified policy
sourcepub fn check_pid(&self, pid: PID) -> Result<PID>
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
sourcepub fn upkeep(&mut self) -> Result<UpkeepInfo>
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