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)]
|
#[cfg(unix)]
|
||||||
use unix_daemonize::{daemonize_redirect, ChdirMode};
|
use unix_daemonize::{daemonize_redirect, ChdirMode};
|
||||||
|
#[cfg(unix)]
|
||||||
|
use std::fs::File;
|
||||||
|
#[cfg(unix)]
|
||||||
|
use std::io::prelude::*;
|
||||||
|
|
||||||
use core::ops::Deref;
|
use core::ops::Deref;
|
||||||
use errors::*;
|
use errors::*;
|
||||||
|
@ -100,10 +104,15 @@ fn daemonize(options: &getopts::Matches) -> Result<()> {
|
||||||
}
|
}
|
||||||
let mut log_file = utils::get_data_root()?;
|
let mut log_file = utils::get_data_root()?;
|
||||||
log_file.push("polaris.log");
|
log_file.push("polaris.log");
|
||||||
match daemonize_redirect(Some(&log_file), Some(&log_file), ChdirMode::NoChdir) {
|
let pid = match daemonize_redirect(Some(&log_file), Some(&log_file), ChdirMode::NoChdir) {
|
||||||
Ok(_) => Ok(()),
|
Ok(p) => p,
|
||||||
Err(_) => bail!(ErrorKind::DaemonError),
|
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<()> {
|
fn run() -> Result<()> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue