FrankChen021 opened a new pull request, #20272:
URL: https://github.com/apache/druid/pull/20272

   ### Description
   
   The Docker startup scripts use `echo -e` when writing runtime properties. The
   behavior of `echo -e` is not portable across `/bin/sh` implementations.
   
   On Ubuntu-based Docker images, `/bin/sh` commonly resolves to `dash`, which 
does
   not recognize `-e` as an option. As a result, the generated runtime 
properties
   can contain a spurious `-e` property with an empty value. This property is 
then
   visible through `sys.server_properties`.
   
   #### Shell behavior
   
   For:
   
   ```sh
   key=foo
   value=bar
   echo -e "\n$key=$value"
   ```
   
   The output differs by shell:
   
   | `/bin/sh` implementation | Output |
   | --- | --- |
   | Bash | A leading newline, followed by `foo=bar` |
   | BusyBox `ash` | A leading newline, followed by `foo=bar` |
   | Ubuntu `dash` | `-e`, followed by a newline and `foo=bar` |
   
   The `dash` output is effectively:
   
   ```text
   -e 
   foo=bar
   ```
   
   Java's properties parser interprets the first line as a property named `-e`
   with an empty value.
   
   Because the scripts use `#!/bin/sh`, behavior is determined by the image's
   `/bin/sh` implementation. This was reproduced with the Ubuntu-based Docker
   images used by the `spdi-27` and `spdi-37` branches. The current master image
   uses BusyBox, which masks the issue because its `echo` supports `-e`.
   
   #### Observed symptom
   
   The following screenshot shows the unexpected `-e` row returned by
   `sys.server_properties`:
   
   <!-- SCREENSHOT_ATTACHMENT -->
   
   #### Changes
   
   Replace the non-portable `echo -e` calls in both `druid.sh` and `peon.sh` 
with
   POSIX-compatible `printf`:
   
   ```sh
   printf '\n%s=%s\n' "$key" "$value"
   ```
   
   The existing property destination and key/value behavior are unchanged.
   `sys.server_properties` does not require any code changes.
   
   #### Verification
   
   - Built the Docker image before and after the change.
   - Reproduced the issue under `dash`: `/status/properties` contained
     `"-e": ""`, and `sys.server_properties` returned the corresponding row.
   - Verified after the change that `-e` was absent while normal properties were
     still present.
   - Ran `sh -n distribution/docker/druid.sh`.
   - Ran `sh -n distribution/docker/peon.sh`.
   - Ran `git diff --check`.
   
   ##### Key changed files
   
   - `distribution/docker/druid.sh`
   - `distribution/docker/peon.sh`
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to