|
6 | 6 | import java.io.InputStreamReader; |
7 | 7 | import java.nio.charset.StandardCharsets; |
8 | 8 | import java.util.function.Predicate; |
| 9 | +import java.util.stream.Collectors; |
9 | 10 |
|
10 | 11 | import org.eclipse.microprofile.config.ConfigProvider; |
11 | 12 | import org.jboss.logging.Logger; |
@@ -80,31 +81,37 @@ private static String getVersionOutputFor(ContainerRuntime containerRuntime) { |
80 | 81 |
|
81 | 82 | private static boolean getRootlessStateFor(ContainerRuntime containerRuntime) { |
82 | 83 | Process rootlessProcess = null; |
| 84 | + ProcessBuilder pb = null; |
83 | 85 | try { |
84 | | - ProcessBuilder pb = new ProcessBuilder(containerRuntime.getExecutableName(), "info") |
85 | | - .redirectErrorStream(true); |
| 86 | + pb = new ProcessBuilder(containerRuntime.getExecutableName(), "info").redirectErrorStream(true); |
86 | 87 | rootlessProcess = pb.start(); |
87 | 88 | int exitCode = rootlessProcess.waitFor(); |
88 | 89 | if (exitCode != 0) { |
89 | 90 | log.warnf("Command \"%s\" exited with error code %d. " + |
90 | | - "Rootless container runtime detection might not be reliable.", |
91 | | - containerRuntime.getExecutableName(), exitCode); |
| 91 | + "Rootless container runtime detection might not be reliable or the container service is not running at all.", |
| 92 | + String.join(" ", pb.command()), exitCode); |
92 | 93 | } |
93 | 94 | try (InputStream inputStream = rootlessProcess.getInputStream(); |
94 | 95 | InputStreamReader inputStreamReader = new InputStreamReader(inputStream); |
95 | 96 | BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { |
96 | | - Predicate<String> stringPredicate; |
97 | | - // Docker includes just "rootless" under SecurityOptions, while podman includes "rootless: <boolean>" |
98 | | - if (containerRuntime == ContainerRuntime.DOCKER) { |
99 | | - stringPredicate = line -> line.trim().equals("rootless"); |
| 97 | + if (exitCode != 0) { |
| 98 | + log.debugf("Command \"%s\" output: %s", String.join(" ", pb.command()), |
| 99 | + bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()))); |
| 100 | + return false; |
100 | 101 | } else { |
101 | | - stringPredicate = line -> line.trim().equals("rootless: true"); |
| 102 | + Predicate<String> stringPredicate; |
| 103 | + // Docker includes just "rootless" under SecurityOptions, while podman includes "rootless: <boolean>" |
| 104 | + if (containerRuntime == ContainerRuntime.DOCKER) { |
| 105 | + stringPredicate = line -> line.trim().equals("rootless"); |
| 106 | + } else { |
| 107 | + stringPredicate = line -> line.trim().equals("rootless: true"); |
| 108 | + } |
| 109 | + return bufferedReader.lines().anyMatch(stringPredicate); |
102 | 110 | } |
103 | | - return bufferedReader.lines().anyMatch(stringPredicate); |
104 | 111 | } |
105 | 112 | } catch (IOException | InterruptedException e) { |
106 | 113 | // If an exception is thrown in the process, assume we are not running rootless (default docker installation) |
107 | | - log.debugf(e, "Failure to read info output from %s", containerRuntime.getExecutableName()); |
| 114 | + log.debugf(e, "Failure to read info output from %s", String.join(" ", pb.command())); |
108 | 115 | return false; |
109 | 116 | } finally { |
110 | 117 | if (rootlessProcess != null) { |
|
0 commit comments