mirror of https://github.com/Icinga/icinga2.git
Split ConfigItem::ActivateItems() into ConfigItem::ValidateItems() and ConfigItem::ActivateItems().
Also removes the -Z commandline parameter: won't be needed when this feature is done. Refs #5788
This commit is contained in:
parent
17d277ff16
commit
19afcd894a
|
@ -62,7 +62,7 @@ start() {
|
|||
chmod 2755 $ICINGA2_STATE_DIR/run/icinga2/cmd
|
||||
|
||||
echo "Starting Icinga 2: "
|
||||
$DAEMON -c $ICINGA2_CONFIG_FILE -Z -d -e $ICINGA2_ERROR_LOG -u $ICINGA2_USER -g $ICINGA2_GROUP
|
||||
$DAEMON -c $ICINGA2_CONFIG_FILE -d -e $ICINGA2_ERROR_LOG -u $ICINGA2_USER -g $ICINGA2_GROUP
|
||||
|
||||
echo "Done"
|
||||
echo
|
||||
|
|
|
@ -67,7 +67,7 @@ static String LoadAppType(const String& typeSpec)
|
|||
return typeSpec.SubStr(index + 1);
|
||||
}
|
||||
|
||||
static bool LoadConfigFiles(const String& appType, ValidationType validate)
|
||||
static bool LoadConfigFiles(const String& appType)
|
||||
{
|
||||
ConfigCompilerContext::GetInstance()->Reset();
|
||||
|
||||
|
@ -88,7 +88,7 @@ static bool LoadConfigFiles(const String& appType, ValidationType validate)
|
|||
ConfigItem::Ptr item = builder->Compile();
|
||||
item->Register();
|
||||
|
||||
bool result = ConfigItem::ActivateItems(validate);
|
||||
bool result = ConfigItem::ValidateItems();
|
||||
|
||||
int warnings = 0, errors = 0;
|
||||
|
||||
|
@ -250,7 +250,6 @@ int Main(void)
|
|||
("config,c", po::value<std::vector<std::string> >(), "parse a configuration file")
|
||||
("no-config,z", "start without a configuration file")
|
||||
("validate,C", "exit after validating the configuration")
|
||||
("no-validate,Z", "skip validating the configuration")
|
||||
("debug,x", "enable debugging")
|
||||
("errorlog,e", po::value<std::string>(), "log fatal errors to the specified log file (only works in combination with --daemonize)")
|
||||
#ifndef _WIN32
|
||||
|
@ -406,6 +405,14 @@ int Main(void)
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!LoadConfigFiles(appType))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (g_AppParams.count("validate")) {
|
||||
Log(LogInformation, "icinga-app", "Finished validating the configuration file(s).");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if (g_AppParams.count("daemonize")) {
|
||||
String errorLog;
|
||||
|
||||
|
@ -416,20 +423,10 @@ int Main(void)
|
|||
Logger::DisableConsoleLog();
|
||||
}
|
||||
|
||||
ValidationType validate = ValidateStart;
|
||||
|
||||
if (g_AppParams.count("validate"))
|
||||
validate = ValidateOnly;
|
||||
|
||||
if (g_AppParams.count("no-validate"))
|
||||
validate = ValidateNone;
|
||||
|
||||
if (!LoadConfigFiles(appType, validate))
|
||||
// activate config only after daemonization: it starts threads and that is not compatible with fork()
|
||||
if (!ConfigItem::ActivateItems()) {
|
||||
Log(LogCritical, "icinga-app", "Error activating configuration.");
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (validate == ValidateOnly) {
|
||||
Log(LogInformation, "icinga-app", "Finished validating the configuration file(s).");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
|
|
|
@ -274,29 +274,23 @@ void ConfigItem::ValidateItem(void)
|
|||
m_Validated = true;
|
||||
}
|
||||
|
||||
bool ConfigItem::ActivateItems(ValidationType validate)
|
||||
bool ConfigItem::ValidateItems(void)
|
||||
{
|
||||
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
||||
return false;
|
||||
|
||||
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
||||
return false;
|
||||
|
||||
ParallelWorkQueue upq;
|
||||
|
||||
if (validate != ValidateNone) {
|
||||
Log(LogInformation, "config", "Validating config items (step 1)...");
|
||||
Log(LogInformation, "config", "Validating config items (step 1)...");
|
||||
|
||||
BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) {
|
||||
upq.Enqueue(boost::bind(&ConfigItem::ValidateItem, kv.second));
|
||||
}
|
||||
BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) {
|
||||
upq.Enqueue(boost::bind(&ConfigItem::ValidateItem, kv.second));
|
||||
}
|
||||
|
||||
upq.Join();
|
||||
upq.Join();
|
||||
|
||||
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
||||
return false;
|
||||
} else
|
||||
Log(LogInformation, "config", "Skipping validating config items (step 1)...");
|
||||
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
||||
return false;
|
||||
|
||||
Log(LogInformation, "config", "Committing config items");
|
||||
|
||||
|
@ -328,35 +322,32 @@ bool ConfigItem::ActivateItems(ValidationType validate)
|
|||
Log(LogInformation, "config", "Evaluating 'object' rules...");
|
||||
ObjectRule::EvaluateRules();
|
||||
|
||||
if (validate != ValidateNone) {
|
||||
Log(LogInformation, "config", "Validating config items (step 2)...");
|
||||
Log(LogInformation, "config", "Validating config items (step 2)...");
|
||||
|
||||
BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) {
|
||||
upq.Enqueue(boost::bind(&ConfigItem::ValidateItem, kv.second));
|
||||
}
|
||||
BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) {
|
||||
upq.Enqueue(boost::bind(&ConfigItem::ValidateItem, kv.second));
|
||||
}
|
||||
|
||||
upq.Join();
|
||||
} else
|
||||
Log(LogInformation, "config", "Skipping validating config items (step 2)...");
|
||||
upq.Join();
|
||||
|
||||
ConfigItem::DiscardItems();
|
||||
ConfigType::DiscardTypes();
|
||||
|
||||
if (validate != ValidateNone) {
|
||||
/* log stats for external parsers */
|
||||
BOOST_FOREACH(const DynamicType::Ptr& type, DynamicType::GetTypes()) {
|
||||
int count = std::distance(type->GetObjects().first, type->GetObjects().second);
|
||||
if (count > 0)
|
||||
Log(LogInformation, "config", "Checked " + Convert::ToString(count) + " " + type->GetName() + "(s).");
|
||||
}
|
||||
/* log stats for external parsers */
|
||||
BOOST_FOREACH(const DynamicType::Ptr& type, DynamicType::GetTypes()) {
|
||||
int count = std::distance(type->GetObjects().first, type->GetObjects().second);
|
||||
if (count > 0)
|
||||
Log(LogInformation, "config", "Checked " + Convert::ToString(count) + " " + type->GetName() + "(s).");
|
||||
}
|
||||
|
||||
return !ConfigCompilerContext::GetInstance()->HasErrors();
|
||||
}
|
||||
|
||||
bool ConfigItem::ActivateItems(void)
|
||||
{
|
||||
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
||||
return false;
|
||||
|
||||
if (validate == ValidateOnly)
|
||||
return true;
|
||||
|
||||
/* restore the previous program state */
|
||||
try {
|
||||
DynamicObject::RestoreObjects(Application::GetStatePath());
|
||||
|
@ -366,6 +357,8 @@ bool ConfigItem::ActivateItems(ValidationType validate)
|
|||
|
||||
Log(LogInformation, "config", "Triggering Start signal for config items");
|
||||
|
||||
ParallelWorkQueue upq;
|
||||
|
||||
BOOST_FOREACH(const DynamicType::Ptr& type, DynamicType::GetTypes()) {
|
||||
BOOST_FOREACH(const DynamicObject::Ptr& object, type->GetObjects()) {
|
||||
if (object->IsActive())
|
||||
|
|
|
@ -27,13 +27,6 @@
|
|||
namespace icinga
|
||||
{
|
||||
|
||||
enum ValidationType
|
||||
{
|
||||
ValidateNone,
|
||||
ValidateOnly,
|
||||
ValidateStart
|
||||
};
|
||||
|
||||
/**
|
||||
* A configuration item. Non-abstract configuration items can be used to
|
||||
* create configuration objects at runtime.
|
||||
|
@ -70,7 +63,8 @@ public:
|
|||
|
||||
void ValidateItem(void);
|
||||
|
||||
static bool ActivateItems(ValidationType validate);
|
||||
static bool ValidateItems(void);
|
||||
static bool ActivateItems(void);
|
||||
static void DiscardItems(void);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue