From ff226c580390ac68bcf12e1186ae26a349e1e85d Mon Sep 17 00:00:00 2001 From: Martin Westergaard Lassen Date: Mon, 1 Feb 2016 10:50:55 +0000 Subject: [PATCH] Copy all environment variables to logstash --- .../mesos/logstash/executor/LogstashService.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/logstash-executor/src/main/java/org/apache/mesos/logstash/executor/LogstashService.java b/logstash-executor/src/main/java/org/apache/mesos/logstash/executor/LogstashService.java index 76dd1ac..f3823c9 100644 --- a/logstash-executor/src/main/java/org/apache/mesos/logstash/executor/LogstashService.java +++ b/logstash-executor/src/main/java/org/apache/mesos/logstash/executor/LogstashService.java @@ -14,11 +14,13 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Optional; import java.util.function.Consumer; import java.util.function.Predicate; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Encapsulates a logstash instance. Keeps track of the current container id for logstash. @@ -110,10 +112,12 @@ public void run(LogstashProtos.LogstashConfiguration logstashConfiguration) { "--log", "/var/log/logstash.log", "-e", serialize(logstashConfiguration) }; - String[] env = { - "LS_HEAP_SIZE=" + System.getProperty("mesos.logstash.logstash.heap.size"), - "HOME=/root" - }; + + final HashMap envs = new HashMap<>(System.getenv()); + envs.put("LS_HEAP_SIZE", System.getProperty("mesos.logstash.logstash.heap.size")); + envs.put("HOME", "/root"); + + String[] env = envs.entrySet().stream().map(kv -> kv.getKey() + "=" + kv.getValue()).toArray(String[]::new); LOGGER.info("Starting subprocess: " + String.join(" ", env) + " " + String.join(" ", command)); process = Runtime.getRuntime().exec(command, env); } catch (IOException e) {