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
impl Handle
Sourcepub fn detach(&mut self)
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
Sourcepub fn detach_with_msg<T: AsRef<[u8]>>(&mut self, msg: T)
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> 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