From ccf0b8cc5a2ed39c92849f32950c26754bb7f124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Bo=CC=88ning?= Date: Tue, 23 Nov 2021 13:50:50 +0100 Subject: [PATCH] Fix issue with docker volume-mounted config file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using `sed -i` was causing an issue when a custom opensearch.yml file was mounted as a volume. ``` sed: cannot rename /usr/share/opensearch/config/sedqdMb0d: Device or resource busy ``` The reason for the issue was found by @unhipzippo https://github.com/opensearch-project/OpenSearch/issues/768#issuecomment-968140380 :heart: > The "sed -i" is an attempt to modify the opensearch.yml file "in place" -- But according to the GNU sed documentation (https://www.gnu.org/software/sed/manual/sed.html#Command_002dLine-Options), "in-place" actually "does this by creating a temporary file and sending output to this file rather than to the standard output. ... the temporary file is renamed to the output file’s original name". > > I believe this rename would require changing the inode of the original file -- something that Docker volume mounts don't permit. --- .../config/opensearch/opensearch-docker-entrypoint.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docker/release/config/opensearch/opensearch-docker-entrypoint.sh b/docker/release/config/opensearch/opensearch-docker-entrypoint.sh index d93c1828ab..3e9d1e460d 100755 --- a/docker/release/config/opensearch/opensearch-docker-entrypoint.sh +++ b/docker/release/config/opensearch/opensearch-docker-entrypoint.sh @@ -66,11 +66,10 @@ if [ -d "$OPENSEARCH_HOME/plugins/$SECURITY_PLUGIN" ]; then if [ "$DISABLE_SECURITY_PLUGIN" = "true" ]; then echo "Disabling OpenSearch Security Plugin" - sed -i '/plugins.security.disabled/d' $OPENSEARCH_HOME/config/opensearch.yml - echo "plugins.security.disabled: true" >> $OPENSEARCH_HOME/config/opensearch.yml + sed 's/plugins.security.disabled.*$/plugins.security.disabled: true' $OPENSEARCH_HOME/config/opensearch.yml | tee $OPENSEARCH_HOME/config/opensearch.yml else echo "Enabling OpenSearch Security Plugin" - sed -i '/plugins.security.disabled/d' $OPENSEARCH_HOME/config/opensearch.yml + sed '/plugins.security.disabled/d' $OPENSEARCH_HOME/config/opensearch.yml | tee $OPENSEARCH_HOME/config/opensearch.yml fi fi