Skip to content

Commit

Permalink
Try our best to find etcd binary and raising warnings properly when f…
Browse files Browse the repository at this point in the history
…ailed (v6d-io#1724)

Prevent vineyardd crashing with some unexpected exceptions.

Fixes v6d-io#1716

Signed-off-by: Tao He <linzhu.ht@alibaba-inc.com>
  • Loading branch information
sighingnow authored Jan 22, 2024
1 parent 8fd14a4 commit 1079d7f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/server/util/etcd_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,31 @@ Status EtcdLauncher::LaunchEtcdServer(
LOG(INFO) << "Starting the etcd server";

// resolve etcd binary
std::string etcd_cmd = etcd_spec_["etcd_cmd"].get_ref<std::string const&>();
std::string etcd_cmd = etcd_spec_.value("etcd_cmd", "");
if (etcd_cmd.empty()) {
setenv("LC_ALL", "C", 1); // makes boost's path works as expected.
etcd_cmd = boost::process::search_path("etcd").string();
}
if (etcd_cmd.empty()) {
// try en_US.UTF-8 and search again.
setenv("LC_ALL", "en_US.UTF-8", 1);
etcd_cmd = boost::process::search_path("etcd").string();
}
if (etcd_cmd.empty()) {
std::string error_message =
"Failed to find etcd binary, please specify its path using the "
"`--etcd_cmd` argument and try again.";
LOG(WARNING) << error_message;
return Status::EtcdError("Failed to find etcd binary");
}
if (!ghc::filesystem::exists(ghc::filesystem::path(etcd_cmd))) {
std::string error_message =
"The etcd binary '" + etcd_cmd +
"' does not exist, please specify the correct path using "
"the `--etcd_cmd` argument and try again.";
LOG(WARNING) << error_message;
return Status::EtcdError("The etcd binary does not exist");
}
LOG(INFO) << "Found etcd at: " << etcd_cmd;

std::string host_to_advertise;
Expand Down

0 comments on commit 1079d7f

Please sign in to comment.