Skip to content

Commit

Permalink
Allow container restarts with file logging (#73101)
Browse files Browse the repository at this point in the history
Closes #72702. It wasn't possible to restart an Elasticsearch Docker
container when using `ES_LOG_STYLE=file`, and now it is.
  • Loading branch information
pugnascotia authored May 14, 2021
1 parent e394250 commit 5770107
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 3 additions & 2 deletions distribution/docker/src/docker/bin/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ if [[ -n "$ES_LOG_STYLE" ]]; then
# This is the default. Nothing to do.
;;
file)
# Overwrite the default config with the stack config
mv /usr/share/elasticsearch/config/log4j2.file.properties /usr/share/elasticsearch/config/log4j2.properties
# Overwrite the default config with the stack config. Do this as a
# copy, not a move, in case the container is restarted.
cp -f /usr/share/elasticsearch/config/log4j2.file.properties /usr/share/elasticsearch/config/log4j2.properties
;;
*)
echo "ERROR: ES_LOG_STYLE set to [$ES_LOG_STYLE]. Expected [console] or [file]" >&2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import static org.elasticsearch.packaging.util.Docker.getJson;
import static org.elasticsearch.packaging.util.Docker.mkDirWithPrivilegeEscalation;
import static org.elasticsearch.packaging.util.Docker.removeContainer;
import static org.elasticsearch.packaging.util.Docker.restartContainer;
import static org.elasticsearch.packaging.util.Docker.rmDirWithPrivilegeEscalation;
import static org.elasticsearch.packaging.util.Docker.runContainer;
import static org.elasticsearch.packaging.util.Docker.runContainerExpectingFailure;
Expand Down Expand Up @@ -676,6 +677,20 @@ public void test123CannotUseUnknownLoggingConfig() {
assertThat(result.stderr, containsString("ERROR: ES_LOG_STYLE set to [unknown]. Expected [console] or [file]"));
}

/**
* Check that it when configuring logging to write to disk, the container can be restarted.
*/
public void test124CanRestartContainerWithStackLoggingConfig() throws Exception {
runContainer(distribution(), builder().envVars(Map.of("ES_LOG_STYLE", "file")));

waitForElasticsearch(installation);

restartContainer();

// If something went wrong running Elasticsearch the second time, this will fail.
waitForElasticsearch(installation);
}

/**
* Check that the Java process running inside the container has the expected UID, GID and username.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,4 +612,11 @@ private static JsonNode getImageInspectionJson(Distribution distribution) throws
public static Shell.Result getContainerLogs() {
return sh.run("docker logs " + containerId);
}

/**
* Restarts the current docker container.
*/
public static void restartContainer() {
sh.run("docker restart " + containerId);
}
}

0 comments on commit 5770107

Please sign in to comment.