Struct Handle

Source
pub struct Handle { /* private fields */ }
Expand description

handle returned from daemonize to the daemon process the daemon should use this handle to detach itself from the parent process, In cases where your program needs to run set up before starting this can be useful, as the daemon will pipe it’s stdout/stderr to the parent process to communicate if start up was successful

Implementations§

Source§

impl Handle

Source

pub fn detach(&mut self)

detach the daemon from the parent process this will write “Daemon started successfully” to stdout before detaching

§panics

if detach is called more than once

Source

pub fn detach_with_msg<T: AsRef<[u8]>>(&mut self, msg: T)

detach the daemon from the parent process with a custom message to be printed to stdout before detaching

§panics

if detach_with_msg is called more than once

Examples found in repository?
examples/simple.rs (line 14)
5fn main() {
6	match daemonize("pid_file") {
7		// we are now in the daemon, use this handle to detach from the parent process
8		Ok(mut handle) => {
9			let mut count = 0;
10			loop {
11				// the daemon's output is piped to the parent process' stdout
12				println!("Count: {}", count);
13				if count == 5 {
14					handle.detach_with_msg("count has reached 5, continuing in background");
15				}
16				thread::sleep(time::Duration::from_secs(1));
17				count += 1;
18			}
19		}
20		// the daemon or the parent process may receive this error,
21		// just print it and exit
22		Err(e) => {
23			// if this is the daemon, this is piped to the parent's stderr
24			eprintln!("{}", e);
25			// don't forget to flush
26			let _ = io::stderr().flush();
27			process::exit(1);
28		}
29	}
30}

Auto Trait Implementations§

§

impl Freeze for Handle

§

impl RefUnwindSafe for Handle

§

impl Send for Handle

§

impl Sync for Handle

§

impl Unpin for Handle

§

impl UnwindSafe for Handle

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.