summaryrefslogtreecommitdiffstats
path: root/logforwarder
diff options
context:
space:
mode:
authorArne Juul <arnej@yahoo-inc.com>2017-10-03 09:32:30 +0000
committerArne Juul <arnej@yahoo-inc.com>2017-10-05 06:25:33 +0000
commit4dcb4d900d6ac8143e95cf7189b40fbc464182e6 (patch)
treef7fe469c584d71908369dc332992877dbfb67a0a /logforwarder
parentdeb22c99216e4545610e08928490eba617b7b8b7 (diff)
write config file
Diffstat (limited to 'logforwarder')
-rw-r--r--logforwarder/src/apps/vespa-logforwarder-start/cf-handler.cpp37
1 files changed, 32 insertions, 5 deletions
diff --git a/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.cpp b/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.cpp
index 573a23a373e..13370c08b59 100644
--- a/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.cpp
+++ b/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.cpp
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "cf-handler.h"
+#include <vespa/defaults.h>
#include <vespa/config/common/configsystem.h>
#include <vespa/config/common/exceptions.h>
@@ -19,15 +20,41 @@ CfHandler::subscribe(const std::string & configId, uint64_t timeoutMS)
_handle = _subscriber.subscribe<LogforwarderConfig>(configId, timeoutMS);
}
+namespace {
+std::string
+cfFilePath() {
+ std::string path = vespa::Defaults::underVespaHome("var/db/vespa/splunk");
+ DIR *dp = opendir(path.c_str());
+ if (dp == NULL) {
+ if (errno != ENOTDIR || mkdir(path.c_str() != 0)) {
+ perror(path.c_str());
+ }
+ }
+ if (dp != NULL) closedir(dp);
+ path += "/deploymentclient.conf;
+ return path;
+}
+}
+
void
CfHandler::doConfigure()
{
std::unique_ptr<LogforwarderConfig> cfg(_handle->getConfig());
const LogforwarderConfig& config(*cfg);
- printf("logforwarder:\n");
- printf(" deployment server: %s\n", config.deploymentServer.c_str());
- printf(" client name: %s\n", config.clientName.c_str());
+ std::string path = cfFilePath();
+ std::string tmpPath = path + ".new";
+ FILE *fp = fopen(tmpPath.c_str(), "w");
+ if (fp == NULL) return;
+
+ fprintf(fp, "[deployment-client]\n");
+ fprintf(fp, "clientName = %s\n", config.clientName.c_str());
+ fprintf(fp, "\n");
+ fprintf(fp, "[target-broker:deploymentServer]\n");
+ fprintf(fp, "targetUri = %s\n", config.deploymentServer.c_str());
+
+ fclose(fp);
+ rename(tmpPath.c_str(), path.c_str());
}
void
@@ -43,9 +70,10 @@ constexpr uint64_t CONFIG_TIMEOUT_MS = 30 * 1000;
void
CfHandler::start(const char *configId)
{
- LOG(debug, "Reading configuration configid '%s'", configId);
+ LOG(debug, "Reading configuration with id '%s'", configId);
try {
subscribe(configId, CONFIG_TIMEOUT_MS);
+ doConfigure();
} catch (config::ConfigTimeoutException & ex) {
LOG(warning, "Timout getting config, please check your setup. Will exit and restart: %s", ex.getMessage().c_str());
exit(EXIT_FAILURE);
@@ -56,5 +84,4 @@ CfHandler::start(const char *configId)
LOG(error, "Fatal: Could not get config, please check your setup: %s", ex.getMessage().c_str());
exit(EXIT_FAILURE);
}
- doConfigure();
}