mirror of
https://github.com/agersant/polaris
synced 2024-12-02 17:49:10 +00:00
Write PID file when forking (unix only)
This commit is contained in:
parent
d06263cff7
commit
8e97e7346d
1 changed files with 12 additions and 3 deletions
15
src/main.rs
15
src/main.rs
|
@ -52,6 +52,10 @@ extern crate unix_daemonize;
|
|||
|
||||
#[cfg(unix)]
|
||||
use unix_daemonize::{daemonize_redirect, ChdirMode};
|
||||
#[cfg(unix)]
|
||||
use std::fs::File;
|
||||
#[cfg(unix)]
|
||||
use std::io::prelude::*;
|
||||
|
||||
use core::ops::Deref;
|
||||
use errors::*;
|
||||
|
@ -100,10 +104,15 @@ fn daemonize(options: &getopts::Matches) -> Result<()> {
|
|||
}
|
||||
let mut log_file = utils::get_data_root()?;
|
||||
log_file.push("polaris.log");
|
||||
match daemonize_redirect(Some(&log_file), Some(&log_file), ChdirMode::NoChdir) {
|
||||
Ok(_) => Ok(()),
|
||||
let pid = match daemonize_redirect(Some(&log_file), Some(&log_file), ChdirMode::NoChdir) {
|
||||
Ok(p) => p,
|
||||
Err(_) => bail!(ErrorKind::DaemonError),
|
||||
}
|
||||
};
|
||||
let mut pid_path = utils::get_data_root()?;
|
||||
pid_path.push("polaris.pid");
|
||||
let mut file = File::create(pid_path)?;
|
||||
file.write_all(pid.to_string().as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run() -> Result<()> {
|
||||
|
|
Loading…
Reference in a new issue