A Daemon can now be created using the Daemon::spawn function.
This follows the POSIX standard way of creating a daemon process. This does not use the systemd or other init system specifics.
This commit is contained in:
37
examples/daemon.rs
Normal file
37
examples/daemon.rs
Normal file
@ -0,0 +1,37 @@
|
||||
#[macro_use]
|
||||
extern crate scribe;
|
||||
|
||||
extern crate weave;
|
||||
extern crate daemon;
|
||||
|
||||
|
||||
|
||||
use weave::{ExitCode, Terminate};
|
||||
use daemon::Daemon;
|
||||
|
||||
|
||||
|
||||
fn child_entry(pid: i64) -> Box<Terminate>
|
||||
{
|
||||
println!("Child ending. ID: {}", pid);
|
||||
|
||||
Box::new(ExitCode::GeneralFailure)
|
||||
}
|
||||
|
||||
|
||||
fn main()
|
||||
{
|
||||
println!("Starting Daemon example.");
|
||||
match Daemon::spawn(&child_entry)
|
||||
{
|
||||
Ok(exit_code) =>
|
||||
{
|
||||
println!("Exiting with: {}", exit_code.get_code());
|
||||
}
|
||||
|
||||
Err(error) =>
|
||||
{
|
||||
error!("{}", error);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user