diff --git a/components/director/src/task.rs b/components/director/src/task.rs index 5230e145eb7..89026571a93 100644 --- a/components/director/src/task.rs +++ b/components/director/src/task.rs @@ -11,13 +11,18 @@ use std::io::prelude::*; use std::net::SocketAddrV4; use std::path::PathBuf; use std::process::{Command, Stdio, Child}; +use std::str::FromStr; use std::thread; use libc::{pid_t, c_int}; use time::{Duration, SteadyTime}; + + use error::Result; use hcore; +use hcore::package::PackageIdent; +use hsup::package::Package; use hsup::supervisor::{WEXITSTATUS, WIFEXITED, WIFSIGNALED, WTERMSIG, Pid}; use hsup::util::signals; use super::ServiceDef; @@ -49,9 +54,27 @@ impl ExecContext { } } + impl Default for ExecContext { + /// use the latest hab-sup and the default Hab service root + /// Fall back to HAB_SUP_PATH if we can't find it. + /// Run hab-director with `RUST_LOG=habitat_director=debug` + /// to see the start params including hab-sup path fn default() -> ExecContext { - ExecContext::new(PathBuf::from(HAB_SUP_PATH), hcore::fs::svc_root()) + if let Ok(ident) = PackageIdent::from_str("core/hab-sup") { + if let Ok(pkg) = Package::load(&ident, None) { + let mut hab_director = pkg.path().to_path_buf(); + hab_director.push("bin"); + hab_director.push("hab-sup"); + ExecContext::new(hab_director, hcore::fs::svc_root()) + } else { + println!("Can't find core/hab-sup, falling back to {}", &HAB_SUP_PATH); + ExecContext::new(PathBuf::from(HAB_SUP_PATH), hcore::fs::svc_root()) + } + } else { + println!("Can't find core/hab-sup, falling back to {}", &HAB_SUP_PATH); + ExecContext::new(PathBuf::from(HAB_SUP_PATH), hcore::fs::svc_root()) + } } }