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: boolThe default value for opts.restart_on_failures.eval_with_default()
local_time_default: boolThe 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: DaemonPathsThe 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: OtherA 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: FThe 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>
impl<Other: Deref<Target: WarrantsRestart> + Clone, F: FnOnce(DaemonCheckExit<'_, Other>) -> Result<()>> Daemon<Other, F>
pub fn create_dirs(&self) -> Result<(), PathIOError>
pub fn state_dir(&self) -> Arc<Path>
pub fn log_dir(&self) -> Arc<Path>
pub fn to_logger(&self) -> Logger
Sourcepub fn daemon_state_path(&self) -> Arc<Path>
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!
Sourcepub fn is_running(&self) -> Result<bool, Error>
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.
Sourcepub fn send_signal(&self, signal: Option<Signal>) -> Result<bool>
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.
pub fn status_string(&self, additional_info: bool) -> Result<Cow<'static, str>>
pub fn print_status(&self, additional_info: bool) -> Result<()>
Sourcepub fn execute(
self,
mode: DaemonMode,
default_is_hard: bool,
) -> Result<ExecutionResult, DaemonError>
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!