pub struct PidGuard(/* private fields */);Expand description
Exclusive, flock(2)-backed guard on the daemon’s pid file.
Replaces the previous check-then-act sequence (read pid file, check liveness, remove if
stale, then write) with a single atomic lock acquisition: only one process can ever hold the
advisory lock on the pid file, so a second concurrent --daemon invocation fails immediately
with DaemonError::AlreadyRunning instead of racing the first to write the file. Dropping
the guard unlinks the pid file and releases the lock.
§Examples
use zeph_core::daemon::PidGuard;
let guard = PidGuard::acquire("/tmp/zeph-daemon.pid").expect("no other instance running");
// ... run the daemon ...
drop(guard); // releases the lock and removes the pid fileImplementations§
Source§impl PidGuard
impl PidGuard
Sourcepub fn acquire(path: &str) -> Result<Self, DaemonError>
pub fn acquire(path: &str) -> Result<Self, DaemonError>
Acquire an exclusive lock on the pid file at path, creating it if necessary, and write
the current process id into it.
§Errors
Returns DaemonError::AlreadyRunning if another process already holds the lock, or
DaemonError::PidFile for filesystem failures.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PidGuard
impl RefUnwindSafe for PidGuard
impl Send for PidGuard
impl Sync for PidGuard
impl Unpin for PidGuard
impl UnsafeUnpin for PidGuard
impl UnwindSafe for PidGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request