Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dns: wait for aardvark server just after spawning aardvark-dns. #300

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/dns/aardvark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::net::IpAddr;
use std::net::Ipv4Addr;
use std::path::Path;
use std::process::{Command, Stdio};
use std::{thread, time};

const SYSTEMD_CHECK_PATH: &str = "/run/systemd/system";
const SYSTEMD_RUN: &str = "systemd-run";
Expand Down Expand Up @@ -76,9 +77,8 @@ impl Aardvark {
false
}

pub fn start_aardvark_server(&self) -> Result<()> {
pub fn start_aardvark_server(&mut self) -> Result<()> {
log::debug!("Spawning aardvark server");

let mut aardvark_args = vec![];
// only use systemd when it is booted, see sd_booted(3)
if Path::new(SYSTEMD_CHECK_PATH).exists() && Aardvark::is_executable_in_path(SYSTEMD_RUN) {
Expand Down Expand Up @@ -115,6 +115,24 @@ impl Aardvark {
.env("RUST_LOG", log::max_level().as_str())
.spawn()?;

// Starting aardvark server is the last task for netavark so in some env
// setup netavark will end up exiting way sooner then aardvark process
// is actually ready to serve so after starting aardvark we have to wait
// till aardvark process is ready. If it does not shows up atleast retry
// 10 times with a delay of 500ms and then return.
let mut retry_count = 10;
while retry_count > 0 {
let aardvark_pid = self.get_aardvark_pid();
if aardvark_pid != -1
&& signal::kill(Pid::from_raw(aardvark_pid), Signal::SIGHUP).is_ok()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid SIGHUP, send signal 0 if possible - it takes no action on the target process, just returns if the process is alive.

{
break;
}
let duration_millis = time::Duration::from_millis(500);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

500ms is a little coarse. Recommend adjusting down to 250ms and doubling retries.

thread::sleep(duration_millis);
retry_count -= 1;
}

Ok(())
}

Expand Down