-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
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
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");
ConfigItem::Ptr item = builder->Compile();
item->Register();
- bool result = ConfigItem::ActivateItems(validateOnly);
+ bool result = ConfigItem::ActivateItems(validate);
int warnings = 0, errors = 0;
("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)")
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;
}
m_Validated = true;
}
-bool ConfigItem::ActivateItems(bool validateOnly)
+bool ConfigItem::ActivateItems(ValidationType validate)
{
if (ConfigCompilerContext::GetInstance()->HasErrors())
return false;
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");
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 */
namespace icinga
{
+enum ValidationType
+{
+ ValidateNone,
+ ValidateOnly,
+ ValidateStart
+};
+
/**
* A configuration item. Non-abstract configuration items can be used to
* create configuration objects at runtime.
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:
DebugInfo m_DebugInfo; /**< Debug information. */
ExpressionList::Ptr m_LinkedExpressionList;
-
+
DynamicObject::Ptr m_Object;
static boost::mutex m_Mutex;