mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +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
|
||||
-c [ --config ] arg parse a configuration file
|
||||
-C [ --validate ] exit after validating the configuration
|
||||
-Z [ --no-validate ] skip validating the configuration
|
||||
-x [ --debug ] enable debugging
|
||||
-d [ --daemonize ] detach from the controlling terminal
|
||||
-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
|
||||
|
||||
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
|
||||
|
@ -62,7 +62,7 @@ static String LoadAppType(const String& typeSpec)
|
||||
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");
|
||||
|
||||
@ -85,7 +85,7 @@ static bool LoadConfigFiles(const String& appType, bool validateOnly)
|
||||
ConfigItem::Ptr item = builder->Compile();
|
||||
item->Register();
|
||||
|
||||
bool result = ConfigItem::ActivateItems(validateOnly);
|
||||
bool result = ConfigItem::ActivateItems(validate);
|
||||
|
||||
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")
|
||||
("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")
|
||||
("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)")
|
||||
@ -372,12 +373,18 @@ int main(int argc, char **argv)
|
||||
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;
|
||||
|
||||
if (validateOnly) {
|
||||
if (validate == ValidateOnly) {
|
||||
Log(LogInformation, "icinga-app", "Finished validating the configuration file(s).");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ void ConfigItem::ValidateItem(void)
|
||||
m_Validated = true;
|
||||
}
|
||||
|
||||
bool ConfigItem::ActivateItems(bool validateOnly)
|
||||
bool ConfigItem::ActivateItems(ValidationType validate)
|
||||
{
|
||||
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
||||
return false;
|
||||
@ -267,18 +267,21 @@ bool ConfigItem::ActivateItems(bool validateOnly)
|
||||
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
||||
return false;
|
||||
|
||||
Log(LogInformation, "config", "Validating config items (step 1)...");
|
||||
|
||||
ParallelWorkQueue upq;
|
||||
|
||||
BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) {
|
||||
upq.Enqueue(boost::bind(&ConfigItem::ValidateItem, kv.second));
|
||||
}
|
||||
if (validate != ValidateNone) {
|
||||
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())
|
||||
return false;
|
||||
upq.Join();
|
||||
|
||||
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
||||
return false;
|
||||
} else
|
||||
Log(LogInformation, "config", "Skipping validating config items (step 1)...");
|
||||
|
||||
Log(LogInformation, "config", "Committing config items");
|
||||
|
||||
@ -307,27 +310,32 @@ bool ConfigItem::ActivateItems(bool validateOnly)
|
||||
Log(LogInformation, "config", "Evaluating 'apply' rules...");
|
||||
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) {
|
||||
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();
|
||||
} else
|
||||
Log(LogInformation, "config", "Skipping validating config items (step 2)...");
|
||||
|
||||
ConfigItem::DiscardItems();
|
||||
ConfigType::DiscardTypes();
|
||||
|
||||
/* log stats for external parsers */
|
||||
BOOST_FOREACH(const DynamicType::Ptr& type, DynamicType::GetTypes()) {
|
||||
if (type->GetObjects().size() > 0)
|
||||
Log(LogInformation, "config", "Checked " + Convert::ToString(type->GetObjects().size()) + " " + type->GetName() + "(s).");
|
||||
if (validate != ValidateNone) {
|
||||
/* log stats for external parsers */
|
||||
BOOST_FOREACH(const DynamicType::Ptr& type, DynamicType::GetTypes()) {
|
||||
if (type->GetObjects().size() > 0)
|
||||
Log(LogInformation, "config", "Checked " + Convert::ToString(type->GetObjects().size()) + " " + type->GetName() + "(s).");
|
||||
}
|
||||
}
|
||||
|
||||
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
||||
return false;
|
||||
|
||||
if (validateOnly)
|
||||
if (validate == ValidateOnly)
|
||||
return true;
|
||||
|
||||
/* restore the previous program state */
|
||||
|
@ -27,6 +27,13 @@
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
enum ValidationType
|
||||
{
|
||||
ValidateNone,
|
||||
ValidateOnly,
|
||||
ValidateStart
|
||||
};
|
||||
|
||||
/**
|
||||
* A configuration item. Non-abstract configuration items can be used to
|
||||
* create configuration objects at runtime.
|
||||
@ -60,8 +67,8 @@ public:
|
||||
static bool HasObject(const String& type, const String& name);
|
||||
|
||||
void ValidateItem(void);
|
||||
|
||||
static bool ActivateItems(bool validateOnly);
|
||||
|
||||
static bool ActivateItems(ValidationType validate);
|
||||
static void DiscardItems(void);
|
||||
|
||||
private:
|
||||
@ -78,7 +85,7 @@ private:
|
||||
DebugInfo m_DebugInfo; /**< Debug information. */
|
||||
|
||||
ExpressionList::Ptr m_LinkedExpressionList;
|
||||
|
||||
|
||||
DynamicObject::Ptr m_Object;
|
||||
|
||||
static boost::mutex m_Mutex;
|
||||
|
Loading…
x
Reference in New Issue
Block a user