| 144 | } |
| 145 | |
| 146 | bool NodeUtility::WriteNodeConfigObjects(const String& filename, const Array::Ptr& objects) |
| 147 | { |
| 148 | Log(LogInformation, "cli") |
| 149 | << "Dumping config items to file '" << filename << "'."; |
| 150 | |
| 151 | /* create a backup first */ |
| 152 | CreateBackupFile(filename); |
| 153 | |
| 154 | String path = Utility::DirName(filename); |
| 155 | |
| 156 | Utility::MkDirP(path, 0755); |
| 157 | |
| 158 | String user = Configuration::RunAsUser; |
| 159 | String group = Configuration::RunAsGroup; |
| 160 | |
| 161 | if (!Utility::SetFileOwnership(path, user, group)) { |
| 162 | Log(LogWarning, "cli") |
| 163 | << "Cannot set ownership for user '" << user << "' group '" << group << "' on path '" << path << "'. Verify it yourself!"; |
| 164 | } |
| 165 | |
| 166 | AtomicFile fp (filename, 0644); |
| 167 | |
| 168 | fp << "/*\n"; |
| 169 | fp << " * Generated by Icinga 2 node setup commands\n"; |
| 170 | fp << " * on " << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", Utility::GetTime()) << "\n"; |
| 171 | fp << " */\n\n"; |
| 172 | |
| 173 | ObjectLock olock(objects); |
| 174 | for (Dictionary::Ptr object : objects) { |
| 175 | SerializeObject(fp, object); |
| 176 | } |
| 177 | |
| 178 | fp << std::endl; |
| 179 | fp.Commit(); |
| 180 | |
| 181 | return true; |
| 182 | } |
| 183 | |
| 184 | |
| 185 | /* |
nothing calls this directly
no test coverage detected