This follows the POSIX standard way of creating a daemon process. This does not use the systemd or other init system specifics.
38 lines
535 B
Rust
38 lines
535 B
Rust
#[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);
|
|
}
|
|
}
|
|
}
|