aboutsummaryrefslogtreecommitdiffstats
path: root/configd/src
diff options
context:
space:
mode:
authorArne Juul <arnej@yahooinc.com>2022-12-07 13:49:39 +0000
committerArne Juul <arnej@yahooinc.com>2022-12-08 12:08:11 +0000
commitb63e8fcf5afcc0cc00ee07f2155c62d318849258 (patch)
tree9d2ce1dc6a8eb59eb1fa4242c53b0cfec5672228 /configd/src
parent99b1c7795757d0f337d319bfa8f559382692665d (diff)
add logctl override
Diffstat (limited to 'configd/src')
-rw-r--r--configd/src/apps/sentinel/CMakeLists.txt1
-rw-r--r--configd/src/apps/sentinel/logctl.cpp48
-rw-r--r--configd/src/apps/sentinel/logctl.h8
-rw-r--r--configd/src/apps/sentinel/service.cpp6
4 files changed, 63 insertions, 0 deletions
diff --git a/configd/src/apps/sentinel/CMakeLists.txt b/configd/src/apps/sentinel/CMakeLists.txt
index 79d4af7b3a4..fde3b6c8e67 100644
--- a/configd/src/apps/sentinel/CMakeLists.txt
+++ b/configd/src/apps/sentinel/CMakeLists.txt
@@ -7,6 +7,7 @@ vespa_add_executable(configd_config-sentinel_app
connectivity.cpp
env.cpp
line-splitter.cpp
+ logctl.cpp
manager.cpp
metrics.cpp
model-owner.cpp
diff --git a/configd/src/apps/sentinel/logctl.cpp b/configd/src/apps/sentinel/logctl.cpp
new file mode 100644
index 00000000000..b63bdf52272
--- /dev/null
+++ b/configd/src/apps/sentinel/logctl.cpp
@@ -0,0 +1,48 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "logctl.h"
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#include <vespa/log/log.h>
+LOG_SETUP(".sentinel.logctl");
+
+namespace config::sentinel {
+
+void justRunLogctl(const char *cspec, const char *lspec)
+{
+ const char *progName = "vespa-logctl";
+ pid_t pid = fork();
+ if (pid == 0) {
+ LOG(debug, "running '%s' '%s' '%s'\n", progName, cspec, lspec);
+ int rv = execlp(progName, progName, "-c", cspec, lspec, nullptr);
+ if (rv != 0) {
+ LOG(warning, "execlp of '%s' failed: %s", progName, strerror(errno));
+ }
+ } else if (pid > 0) {
+ int wstatus = 0;
+ pid_t got = waitpid(pid, &wstatus, 0);
+ if (got == pid) {
+ if (WIFEXITED(wstatus)) {
+ int exitCode = WEXITSTATUS(wstatus);
+ if (exitCode != 0) {
+ LOG(warning, "running '%s' failed (exit code %d)", progName, exitCode);
+ }
+ } else if (WIFSIGNALED(wstatus)) {
+ int termSig = WTERMSIG(wstatus);
+ LOG(warning, "running '%s' failed (got signal %d)", progName, termSig);
+ } else {
+ LOG(warning, "'%s' failure (wait status was %d)", progName, wstatus);
+ }
+ } else {
+ LOG(error, "waitpid() failed: %s", strerror(errno));
+ }
+ } else {
+ LOG(error, "fork() failed: %s", strerror(errno));
+ }
+}
+
+}
diff --git a/configd/src/apps/sentinel/logctl.h b/configd/src/apps/sentinel/logctl.h
new file mode 100644
index 00000000000..7eb88bcd19c
--- /dev/null
+++ b/configd/src/apps/sentinel/logctl.h
@@ -0,0 +1,8 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#pragma once
+
+namespace config::sentinel {
+
+void justRunLogctl(const char *cspec, const char *lspec);
+
+}
diff --git a/configd/src/apps/sentinel/service.cpp b/configd/src/apps/sentinel/service.cpp
index e9225325e27..a18bc4da3e5 100644
--- a/configd/src/apps/sentinel/service.cpp
+++ b/configd/src/apps/sentinel/service.cpp
@@ -2,6 +2,7 @@
#include "service.h"
#include "output-connection.h"
+#include "logctl.h"
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/util/signalhandler.h>
@@ -329,6 +330,11 @@ Service::runChild()
for (const auto &envvar : _config->environ) {
setenv(envvar.varname.c_str(), envvar.varvalue.c_str(), 1);
}
+ for (const auto &logctl : _config->logctl) {
+ const auto cspec = _config->name + ":" + logctl.componentSpec;
+ const auto lspec = logctl.levelsModSpec;
+ justRunLogctl(cspec.c_str(), lspec.c_str());
+ }
// Set up environment
setenv("VESPA_SERVICE_NAME", _config->name.c_str(), 1);