mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 21:55:03 +02:00
Add --no-validate option and skip duplicate validation on (re)start.
Fixes #5800
This commit is contained in:
parent
008c2c2245
commit
1d32c5b2d3
@ -35,6 +35,7 @@ Icinga 2's init script is installed in `/etc/init.d/icinga2` by default:
|
|||||||
-D [ --define] args define a constant
|
-D [ --define] args define a constant
|
||||||
-c [ --config ] arg parse a configuration file
|
-c [ --config ] arg parse a configuration file
|
||||||
-C [ --validate ] exit after validating the configuration
|
-C [ --validate ] exit after validating the configuration
|
||||||
|
-Z [ --no-validate ] skip validating the configuration
|
||||||
-x [ --debug ] enable debugging
|
-x [ --debug ] enable debugging
|
||||||
-d [ --daemonize ] detach from the controlling terminal
|
-d [ --daemonize ] detach from the controlling terminal
|
||||||
-e [ --errorlog ] arg log fatal errors to the specified log file (only works
|
-e [ --errorlog ] arg log fatal errors to the specified log file (only works
|
||||||
|
@ -62,7 +62,7 @@ start() {
|
|||||||
chmod 2755 $ICINGA2_STATE_DIR/run/icinga2/cmd
|
chmod 2755 $ICINGA2_STATE_DIR/run/icinga2/cmd
|
||||||
|
|
||||||
echo "Starting Icinga 2: "
|
echo "Starting Icinga 2: "
|
||||||
$DAEMON -c $ICINGA2_CONFIG_FILE -d -e $ICINGA2_ERROR_LOG -u $ICINGA2_USER -g $ICINGA2_GROUP
|
$DAEMON -c $ICINGA2_CONFIG_FILE -Z -d -e $ICINGA2_ERROR_LOG -u $ICINGA2_USER -g $ICINGA2_GROUP
|
||||||
|
|
||||||
echo "Done"
|
echo "Done"
|
||||||
echo
|
echo
|
||||||
|
@ -62,7 +62,7 @@ static String LoadAppType(const String& typeSpec)
|
|||||||
return typeSpec.SubStr(index + 1);
|
return typeSpec.SubStr(index + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool LoadConfigFiles(const String& appType, bool validateOnly)
|
static bool LoadConfigFiles(const String& appType, ValidationType validate)
|
||||||
{
|
{
|
||||||
CONTEXT("Loading configuration files");
|
CONTEXT("Loading configuration files");
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ static bool LoadConfigFiles(const String& appType, bool validateOnly)
|
|||||||
ConfigItem::Ptr item = builder->Compile();
|
ConfigItem::Ptr item = builder->Compile();
|
||||||
item->Register();
|
item->Register();
|
||||||
|
|
||||||
bool result = ConfigItem::ActivateItems(validateOnly);
|
bool result = ConfigItem::ActivateItems(validate);
|
||||||
|
|
||||||
int warnings = 0, errors = 0;
|
int warnings = 0, errors = 0;
|
||||||
|
|
||||||
@ -213,6 +213,7 @@ int main(int argc, char **argv)
|
|||||||
("config,c", po::value<std::vector<String> >(), "parse a configuration file")
|
("config,c", po::value<std::vector<String> >(), "parse a configuration file")
|
||||||
("no-config,z", "start without a configuration file")
|
("no-config,z", "start without a configuration file")
|
||||||
("validate,C", "exit after validating the configuration")
|
("validate,C", "exit after validating the configuration")
|
||||||
|
("no-validate,Z", "skip validating the configuration")
|
||||||
("debug,x", "enable debugging")
|
("debug,x", "enable debugging")
|
||||||
("daemonize,d", "detach from the controlling terminal")
|
("daemonize,d", "detach from the controlling terminal")
|
||||||
("errorlog,e", po::value<String>(), "log fatal errors to the specified log file (only works in combination with --daemonize)")
|
("errorlog,e", po::value<String>(), "log fatal errors to the specified log file (only works in combination with --daemonize)")
|
||||||
@ -372,12 +373,18 @@ int main(int argc, char **argv)
|
|||||||
Logger::DisableConsoleLog();
|
Logger::DisableConsoleLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool validateOnly = g_AppParams.count("validate");
|
ValidationType validate = ValidateStart;
|
||||||
|
|
||||||
if (!LoadConfigFiles(appType, validateOnly))
|
if(g_AppParams.count("validate"))
|
||||||
|
validate = ValidateOnly;
|
||||||
|
|
||||||
|
if(g_AppParams.count("no-validate"))
|
||||||
|
validate = ValidateNone;
|
||||||
|
|
||||||
|
if (!LoadConfigFiles(appType, validate))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
if (validateOnly) {
|
if (validate == ValidateOnly) {
|
||||||
Log(LogInformation, "icinga-app", "Finished validating the configuration file(s).");
|
Log(LogInformation, "icinga-app", "Finished validating the configuration file(s).");
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -259,7 +259,7 @@ void ConfigItem::ValidateItem(void)
|
|||||||
m_Validated = true;
|
m_Validated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigItem::ActivateItems(bool validateOnly)
|
bool ConfigItem::ActivateItems(ValidationType validate)
|
||||||
{
|
{
|
||||||
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
||||||
return false;
|
return false;
|
||||||
@ -267,18 +267,21 @@ bool ConfigItem::ActivateItems(bool validateOnly)
|
|||||||
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Log(LogInformation, "config", "Validating config items (step 1)...");
|
|
||||||
|
|
||||||
ParallelWorkQueue upq;
|
ParallelWorkQueue upq;
|
||||||
|
|
||||||
BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) {
|
if (validate != ValidateNone) {
|
||||||
upq.Enqueue(boost::bind(&ConfigItem::ValidateItem, kv.second));
|
Log(LogInformation, "config", "Validating config items (step 1)...");
|
||||||
}
|
|
||||||
|
|
||||||
upq.Join();
|
BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) {
|
||||||
|
upq.Enqueue(boost::bind(&ConfigItem::ValidateItem, kv.second));
|
||||||
|
}
|
||||||
|
|
||||||
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
upq.Join();
|
||||||
return false;
|
|
||||||
|
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
||||||
|
return false;
|
||||||
|
} else
|
||||||
|
Log(LogInformation, "config", "Skipping validating config items (step 1)...");
|
||||||
|
|
||||||
Log(LogInformation, "config", "Committing config items");
|
Log(LogInformation, "config", "Committing config items");
|
||||||
|
|
||||||
@ -307,27 +310,32 @@ bool ConfigItem::ActivateItems(bool validateOnly)
|
|||||||
Log(LogInformation, "config", "Evaluating 'apply' rules...");
|
Log(LogInformation, "config", "Evaluating 'apply' rules...");
|
||||||
ApplyRule::EvaluateRules();
|
ApplyRule::EvaluateRules();
|
||||||
|
|
||||||
Log(LogInformation, "config", "Validating config items (step 2)...");
|
if (validate != ValidateNone) {
|
||||||
|
Log(LogInformation, "config", "Validating config items (step 2)...");
|
||||||
|
|
||||||
BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) {
|
BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) {
|
||||||
upq.Enqueue(boost::bind(&ConfigItem::ValidateItem, kv.second));
|
upq.Enqueue(boost::bind(&ConfigItem::ValidateItem, kv.second));
|
||||||
}
|
}
|
||||||
|
|
||||||
upq.Join();
|
upq.Join();
|
||||||
|
} else
|
||||||
|
Log(LogInformation, "config", "Skipping validating config items (step 2)...");
|
||||||
|
|
||||||
ConfigItem::DiscardItems();
|
ConfigItem::DiscardItems();
|
||||||
ConfigType::DiscardTypes();
|
ConfigType::DiscardTypes();
|
||||||
|
|
||||||
/* log stats for external parsers */
|
if (validate != ValidateNone) {
|
||||||
BOOST_FOREACH(const DynamicType::Ptr& type, DynamicType::GetTypes()) {
|
/* log stats for external parsers */
|
||||||
if (type->GetObjects().size() > 0)
|
BOOST_FOREACH(const DynamicType::Ptr& type, DynamicType::GetTypes()) {
|
||||||
Log(LogInformation, "config", "Checked " + Convert::ToString(type->GetObjects().size()) + " " + type->GetName() + "(s).");
|
if (type->GetObjects().size() > 0)
|
||||||
|
Log(LogInformation, "config", "Checked " + Convert::ToString(type->GetObjects().size()) + " " + type->GetName() + "(s).");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (validateOnly)
|
if (validate == ValidateOnly)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
/* restore the previous program state */
|
/* restore the previous program state */
|
||||||
|
@ -27,6 +27,13 @@
|
|||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
enum ValidationType
|
||||||
|
{
|
||||||
|
ValidateNone,
|
||||||
|
ValidateOnly,
|
||||||
|
ValidateStart
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A configuration item. Non-abstract configuration items can be used to
|
* A configuration item. Non-abstract configuration items can be used to
|
||||||
* create configuration objects at runtime.
|
* create configuration objects at runtime.
|
||||||
@ -61,7 +68,7 @@ public:
|
|||||||
|
|
||||||
void ValidateItem(void);
|
void ValidateItem(void);
|
||||||
|
|
||||||
static bool ActivateItems(bool validateOnly);
|
static bool ActivateItems(ValidationType validate);
|
||||||
static void DiscardItems(void);
|
static void DiscardItems(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user