mirror of https://github.com/Icinga/icinga2.git
Config packages: Catch active stage exceptions in rare cases
Typically this already is detected on startup.
This commit is contained in:
parent
704aabcb63
commit
03324b2fb6
|
@ -16,6 +16,7 @@ using namespace icinga;
|
|||
|
||||
String ConfigObjectUtility::GetConfigDir()
|
||||
{
|
||||
/* This may throw an exception the caller above must handle. */
|
||||
return ConfigPackageUtility::GetPackageDir() + "/_api/" +
|
||||
ConfigPackageUtility::GetActiveStage("_api");
|
||||
}
|
||||
|
@ -25,7 +26,10 @@ String ConfigObjectUtility::GetObjectConfigPath(const Type::Ptr& type, const Str
|
|||
String typeDir = type->GetPluralName();
|
||||
boost::algorithm::to_lower(typeDir);
|
||||
|
||||
return GetConfigDir() + "/conf.d/" + typeDir +
|
||||
/* This may throw an exception the caller above must handle. */
|
||||
String prefix = GetConfigDir();
|
||||
|
||||
return prefix + "/conf.d/" + typeDir +
|
||||
"/" + EscapeName(fullName) + ".conf";
|
||||
}
|
||||
|
||||
|
@ -102,7 +106,15 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full
|
|||
return false;
|
||||
}
|
||||
|
||||
String path = GetObjectConfigPath(type, fullName);
|
||||
String path;
|
||||
|
||||
try {
|
||||
path = GetObjectConfigPath(type, fullName);
|
||||
} catch (const std::exception& ex) {
|
||||
errors->Add("Config package broken: " + DiagnosticInformation(ex, false));
|
||||
return false;
|
||||
}
|
||||
|
||||
Utility::MkDirP(Utility::DirName(path), 0700);
|
||||
|
||||
std::ofstream fp(path.CStr(), std::ofstream::out | std::ostream::trunc);
|
||||
|
@ -216,7 +228,14 @@ bool ConfigObjectUtility::DeleteObjectHelper(const ConfigObject::Ptr& object, bo
|
|||
return false;
|
||||
}
|
||||
|
||||
String path = GetObjectConfigPath(object->GetReflectionType(), name);
|
||||
String path;
|
||||
|
||||
try {
|
||||
path = GetObjectConfigPath(object->GetReflectionType(), name);
|
||||
} catch (const std::exception& ex) {
|
||||
errors->Add("Config package broken: " + DiagnosticInformation(ex, false));
|
||||
return false;
|
||||
}
|
||||
|
||||
Utility::Remove(path);
|
||||
|
||||
|
|
|
@ -66,10 +66,16 @@ void ConfigPackagesHandler::HandleGet(
|
|||
boost::mutex::scoped_lock lock(ConfigPackageUtility::GetStaticPackageMutex());
|
||||
|
||||
for (const String& package : packages) {
|
||||
String activeStage;
|
||||
|
||||
try {
|
||||
activeStage = ConfigPackageUtility::GetActiveStage(package);
|
||||
} catch (const std::exception&) { } /* Should never happen. */
|
||||
|
||||
results.emplace_back(new Dictionary({
|
||||
{ "name", package },
|
||||
{ "stages", Array::FromVector(ConfigPackageUtility::GetStages(package)) },
|
||||
{ "active-stage", ConfigPackageUtility::GetActiveStage(package) }
|
||||
{ "active-stage", activeStage }
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue