diff options
author | Jesse Luehrs <doy@tozt.net> | 2020-04-18 00:40:27 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2020-04-18 00:40:27 -0400 |
commit | 7445b3c5a15487e6fa5c97b17098cf5014e81a61 (patch) | |
tree | 5ad336a53b185e08376439dd86a67e2fff9f0755 /src | |
parent | 538276f22eb75331aee2c5d7effcbf2d8ccc8988 (diff) | |
download | rbw-7445b3c5a15487e6fa5c97b17098cf5014e81a61.tar.gz rbw-7445b3c5a15487e6fa5c97b17098cf5014e81a61.zip |
keep daemon log files
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/rbw-agent/daemon.rs | 14 | ||||
-rw-r--r-- | src/dirs.rs | 6 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/bin/rbw-agent/daemon.rs b/src/bin/rbw-agent/daemon.rs index 80c94ad..f87d0ec 100644 --- a/src/bin/rbw-agent/daemon.rs +++ b/src/bin/rbw-agent/daemon.rs @@ -24,9 +24,23 @@ pub fn daemonize() -> anyhow::Result<StartupAck> { std::fs::create_dir_all(&runtime_dir) .context("failed to create runtime directory")?; + let data_dir = rbw::dirs::data_dir(); + std::fs::create_dir_all(&data_dir) + .context("failed to create data directory")?; + let stdout = std::fs::OpenOptions::new() + .append(true) + .create(true) + .open(data_dir.join("agent.out"))?; + let stderr = std::fs::OpenOptions::new() + .append(true) + .create(true) + .open(data_dir.join("agent.err"))?; + let (r, w) = nix::unistd::pipe()?; let res = daemonize::Daemonize::new() .pid_file(runtime_dir.join("pidfile")) + .stdout(stdout) + .stderr(stderr) .exit_action(move || { // unwraps are necessary because not really a good way to handle // errors here otherwise diff --git a/src/dirs.rs b/src/dirs.rs index 3eb5804..fe610a7 100644 --- a/src/dirs.rs +++ b/src/dirs.rs @@ -11,6 +11,12 @@ pub fn cache_dir() -> std::path::PathBuf { } #[must_use] +pub fn data_dir() -> std::path::PathBuf { + let project_dirs = directories::ProjectDirs::from("", "", "rbw").unwrap(); + project_dirs.data_dir().to_path_buf() +} + +#[must_use] pub fn runtime_dir() -> std::path::PathBuf { let project_dirs = directories::ProjectDirs::from("", "", "rbw").unwrap(); project_dirs.runtime_dir().unwrap().to_path_buf() |