| 116 | } |
| 117 | |
| 118 | int FeatureUtility::DisableFeatures(const std::vector<std::string>& features) |
| 119 | { |
| 120 | String features_enabled_dir = GetFeaturesEnabledPath(); |
| 121 | |
| 122 | if (!Utility::PathExists(features_enabled_dir) ) { |
| 123 | Log(LogCritical, "cli") |
| 124 | << "Cannot disable features. Path '" << features_enabled_dir << "' does not exist."; |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | std::vector<std::string> errors; |
| 129 | |
| 130 | for (auto& feature : features) { |
| 131 | String target = features_enabled_dir + "/" + feature + ".conf"; |
| 132 | |
| 133 | if (!Utility::PathExists(target) ) { |
| 134 | Log(LogWarning, "cli") |
| 135 | << "Feature '" << feature << "' already disabled."; |
| 136 | continue; |
| 137 | } |
| 138 | |
| 139 | if (unlink(target.CStr()) < 0) { |
| 140 | Log(LogCritical, "cli") |
| 141 | << "Cannot disable feature '" << feature << "'. Unlinking target file '" << target |
| 142 | << "' failed with error code " << errno << ", \"" + Utility::FormatErrorNumber(errno) << "\"."; |
| 143 | errors.push_back(feature); |
| 144 | continue; |
| 145 | } |
| 146 | |
| 147 | std::cout << "Disabling feature " << ConsoleColorTag(Console_ForegroundMagenta | Console_Bold) << feature |
| 148 | << ConsoleColorTag(Console_Normal) << ". Make sure to restart Icinga 2 for these changes to take effect.\n"; |
| 149 | } |
| 150 | |
| 151 | if (!errors.empty()) { |
| 152 | Log(LogCritical, "cli") |
| 153 | << "Cannot disable feature(s): " << boost::algorithm::join(errors, " "); |
| 154 | errors.clear(); |
| 155 | return 1; |
| 156 | } |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | int FeatureUtility::ListFeatures(std::ostream& os) |
| 162 | { |
nothing calls this directly
no test coverage detected