Struct Daemon

Source
pub struct Daemon<Other: Deref<Target: WarrantsRestart> + Clone, F: FnOnce(DaemonCheckExit<'_, Other>) -> Result<()>> {
    pub opts: DaemonOpts,
    pub restart_on_failures_default: bool,
    pub local_time_default: bool,
    pub restart_opts: Option<LoopWithBackoff>,
    pub timestamp_opts: TimestampOpts,
    pub paths: DaemonPaths,
    pub other_restart_checks: Other,
    pub run: F,
}

Fields§

§opts: DaemonOpts§restart_on_failures_default: bool

The default value for opts.restart_on_failures.eval_with_default()

§local_time_default: bool

The default value for opts.logging_opts.local_time_default.eval_with_default()

§restart_opts: Option<LoopWithBackoff>

The settings for the restarting; if not provided, uses its Default values. The daemon field is overwritten with the string “daemon service process restart “.

§timestamp_opts: TimestampOpts§paths: DaemonPaths

The code to run; the daemon ends/stops when this function returns. The function should periodically call want() on its argument and stop processing when it doesn’t give DaemonWant::Up.

§other_restart_checks: Other

A value that implements WarrantsRestart, checking other conditions warranting restart than the daemon state indicating it. Used as part of the argument to run. See chj_unix_util::daemon::warrants_restart for reusable implementations.

§run: F

The code to run in the daemon. Should return when calling want_exit() on the argument returns true.

Implementations§

Source§

impl<Other: Deref<Target: WarrantsRestart> + Clone, F: FnOnce(DaemonCheckExit<'_, Other>) -> Result<()>> Daemon<Other, F>

Source

pub fn create_dirs(&self) -> Result<(), PathIOError>

Source

pub fn state_dir(&self) -> Arc<Path>

Source

pub fn log_dir(&self) -> Arc<Path>

Source

pub fn to_logger(&self) -> Logger

Source

pub fn daemon_state_path(&self) -> Arc<Path>

Path to a file that is used as a 8-byte mmap file, and for flock. Protect this file from modification by other parties–doing so can segfault the app!

Source

pub fn lock_path(&self) -> Arc<Path>

The same as daemon_state_path

Source

pub fn is_running(&self) -> Result<bool, Error>

Check via flock (sufficient, although the DaemonState should also provide a pid in this case). Slightly costly as it involves memory allocations and multiple syscalls.

Source

pub fn send_signal(&self, signal: Option<Signal>) -> Result<bool>

Send the signal once or twice (once via the process group, then individually if still around) to all processes belonging to the session that the daemon is running in.

Source

pub fn status_string(&self, additional_info: bool) -> Result<Cow<'static, str>>

Source

pub fn print_status(&self, additional_info: bool) -> Result<()>

Source

pub fn execute( self, mode: DaemonMode, default_is_hard: bool, ) -> Result<ExecutionResult, DaemonError>

Note: actions involving forking a new instance must be run while there are no running threads–they panic otherwise!

Auto Trait Implementations§

§

impl<Other, F> Freeze for Daemon<Other, F>
where Other: Freeze, F: Freeze,

§

impl<Other, F> RefUnwindSafe for Daemon<Other, F>
where Other: RefUnwindSafe, F: RefUnwindSafe,

§

impl<Other, F> Send for Daemon<Other, F>
where Other: Send, F: Send,

§

impl<Other, F> Sync for Daemon<Other, F>
where Other: Sync, F: Sync,

§

impl<Other, F> Unpin for Daemon<Other, F>
where Other: Unpin, F: Unpin,

§

impl<Other, F> UnwindSafe for Daemon<Other, F>
where Other: UnwindSafe, F: UnwindSafe,

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

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.