Skip to content

Commit 34ed62c

Browse files
author
James McNeil
committed
touch config file to verify it is read-only
1 parent ed7c222 commit 34ed62c

File tree

7 files changed

+63
-42
lines changed

7 files changed

+63
-42
lines changed

3.7-rc/alpine/docker-entrypoint.sh

+9-6
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,15 @@ oldConfigFile="$configBase.config"
202202
newConfigFile="$configBase.conf"
203203

204204
shouldWriteConfig="$haveConfig"
205-
if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then
206-
# config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount)
207-
tmp="/tmp/rabbitmq.conf"
208-
cat "$newConfigFile" > "${tmp}"
209-
newConfigFile="${tmp}"
210-
export RABBITMQ_CONFIG_FILE="${tmp}"
205+
if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then
206+
# config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap)
207+
export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf'
208+
cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE"
209+
echo >&2
210+
echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it"
211+
echo >&2 " We have copied it to '$RABBITMQ_CONFIG_FILE' so it can be amended to work around the problem, but it is recommended that the read-only source file should be modified and the environment variables removed instead."
212+
echo >&2
213+
newConfigFile="$RABBITMQ_CONFIG_FILE"
211214
fi
212215
if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then
213216
{

3.7-rc/ubuntu/docker-entrypoint.sh

+9-6
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,15 @@ oldConfigFile="$configBase.config"
202202
newConfigFile="$configBase.conf"
203203

204204
shouldWriteConfig="$haveConfig"
205-
if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then
206-
# config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount)
207-
tmp="/tmp/rabbitmq.conf"
208-
cat "$newConfigFile" > "${tmp}"
209-
newConfigFile="${tmp}"
210-
export RABBITMQ_CONFIG_FILE="${tmp}"
205+
if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then
206+
# config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap)
207+
export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf'
208+
cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE"
209+
echo >&2
210+
echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it"
211+
echo >&2 " We have copied it to '$RABBITMQ_CONFIG_FILE' so it can be amended to work around the problem, but it is recommended that the read-only source file should be modified and the environment variables removed instead."
212+
echo >&2
213+
newConfigFile="$RABBITMQ_CONFIG_FILE"
211214
fi
212215
if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then
213216
{

3.7/alpine/docker-entrypoint.sh

+9-6
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,15 @@ oldConfigFile="$configBase.config"
202202
newConfigFile="$configBase.conf"
203203

204204
shouldWriteConfig="$haveConfig"
205-
if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then
206-
# config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount)
207-
tmp="/tmp/rabbitmq.conf"
208-
cat "$newConfigFile" > "${tmp}"
209-
newConfigFile="${tmp}"
210-
export RABBITMQ_CONFIG_FILE="${tmp}"
205+
if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then
206+
# config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap)
207+
export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf'
208+
cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE"
209+
echo >&2
210+
echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it"
211+
echo >&2 " We have copied it to '$RABBITMQ_CONFIG_FILE' so it can be amended to work around the problem, but it is recommended that the read-only source file should be modified and the environment variables removed instead."
212+
echo >&2
213+
newConfigFile="$RABBITMQ_CONFIG_FILE"
211214
fi
212215
if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then
213216
{

3.7/ubuntu/docker-entrypoint.sh

+9-6
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,15 @@ oldConfigFile="$configBase.config"
202202
newConfigFile="$configBase.conf"
203203

204204
shouldWriteConfig="$haveConfig"
205-
if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then
206-
# config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount)
207-
tmp="/tmp/rabbitmq.conf"
208-
cat "$newConfigFile" > "${tmp}"
209-
newConfigFile="${tmp}"
210-
export RABBITMQ_CONFIG_FILE="${tmp}"
205+
if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then
206+
# config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap)
207+
export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf'
208+
cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE"
209+
echo >&2
210+
echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it"
211+
echo >&2 " We have copied it to '$RABBITMQ_CONFIG_FILE' so it can be amended to work around the problem, but it is recommended that the read-only source file should be modified and the environment variables removed instead."
212+
echo >&2
213+
newConfigFile="$RABBITMQ_CONFIG_FILE"
211214
fi
212215
if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then
213216
{

3.8-rc/alpine/docker-entrypoint.sh

+9-6
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,15 @@ oldConfigFile="$configBase.config"
202202
newConfigFile="$configBase.conf"
203203

204204
shouldWriteConfig="$haveConfig"
205-
if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then
206-
# config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount)
207-
tmp="/tmp/rabbitmq.conf"
208-
cat "$newConfigFile" > "${tmp}"
209-
newConfigFile="${tmp}"
210-
export RABBITMQ_CONFIG_FILE="${tmp}"
205+
if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then
206+
# config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap)
207+
export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf'
208+
cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE"
209+
echo >&2
210+
echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it"
211+
echo >&2 " We have copied it to '$RABBITMQ_CONFIG_FILE' so it can be amended to work around the problem, but it is recommended that the read-only source file should be modified and the environment variables removed instead."
212+
echo >&2
213+
newConfigFile="$RABBITMQ_CONFIG_FILE"
211214
fi
212215
if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then
213216
{

3.8-rc/ubuntu/docker-entrypoint.sh

+9-6
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,15 @@ oldConfigFile="$configBase.config"
202202
newConfigFile="$configBase.conf"
203203

204204
shouldWriteConfig="$haveConfig"
205-
if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then
206-
# config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount)
207-
tmp="/tmp/rabbitmq.conf"
208-
cat "$newConfigFile" > "${tmp}"
209-
newConfigFile="${tmp}"
210-
export RABBITMQ_CONFIG_FILE="${tmp}"
205+
if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then
206+
# config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap)
207+
export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf'
208+
cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE"
209+
echo >&2
210+
echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it"
211+
echo >&2 " We have copied it to '$RABBITMQ_CONFIG_FILE' so it can be amended to work around the problem, but it is recommended that the read-only source file should be modified and the environment variables removed instead."
212+
echo >&2
213+
newConfigFile="$RABBITMQ_CONFIG_FILE"
211214
fi
212215
if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then
213216
{

docker-entrypoint.sh

+9-6
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,15 @@ oldConfigFile="$configBase.config"
202202
newConfigFile="$configBase.conf"
203203

204204
shouldWriteConfig="$haveConfig"
205-
if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then
206-
# config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount)
207-
tmp="/tmp/rabbitmq.conf"
208-
cat "$newConfigFile" > "${tmp}"
209-
newConfigFile="${tmp}"
210-
export RABBITMQ_CONFIG_FILE="${tmp}"
205+
if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then
206+
# config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap)
207+
export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf'
208+
cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE"
209+
echo >&2
210+
echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it"
211+
echo >&2 " We have copied it to '$RABBITMQ_CONFIG_FILE' so it can be amended to work around the problem, but it is recommended that the read-only source file should be modified and the environment variables removed instead."
212+
echo >&2
213+
newConfigFile="$RABBITMQ_CONFIG_FILE"
211214
fi
212215
if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then
213216
{

0 commit comments

Comments
 (0)