[ 
https://issues.apache.org/jira/browse/MESOS-4812?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15728864#comment-15728864
 ] 

haosdent commented on MESOS-4812:
---------------------------------

Thanks [~lloesche]'s help. I could reproduce by this application definition
{code}
{
  "id": "/test",
  "cmd": null,
  "cpus": 1,
  "mem": 128,
  "disk": 0,
  "instances": 1,
  "executor": null,
  "fetch": null,
  "constraints": null,
  "acceptedResourceRoles": null,
  "user": null,
  "container": {
    "docker": {
      "image": "nginx",
      "forcePullImage": false,
      "privileged": false,
      "portMappings": [
        {
          "containerPort": 80,
          "protocol": "tcp"
        }
      ],
      "network": "BRIDGE"
    }
  },
  "labels": null,
  "healthChecks": [
    {
      "protocol": "COMMAND",
      "command": {
        "value": "bash -c \"</dev/tcp/$HOST/$PORT0\""
      }
    }
  ],
  "env": null
}
{code}


It is because we warp the health check command with {{docker exec}} blindly. 
{code}
      // Wrap the original health check command in `docker exec`.
      const CommandInfo& command = healthCheck.command();

      vector<string> commandArguments;
      commandArguments.push_back(docker->getPath());
      commandArguments.push_back("exec");
      commandArguments.push_back(containerName);

      if (command.shell()) {
        commandArguments.push_back("sh");
        commandArguments.push_back("-c");
        commandArguments.push_back("\"");
        commandArguments.push_back(command.value());
        commandArguments.push_back("\"");
      } else {
        commandArguments.push_back(command.value());

        foreach (const string& argument, command.arguments()) {
          commandArguments.push_back(argument);
        }
      }

      healthCheck.mutable_command()->set_shell(true); <-- Cause problem.
      healthCheck.mutable_command()->clear_arguments();
      healthCheck.mutable_command()->set_value(
          strings::join(" ", commandArguments)); <-- Cause problem.
{code}

Then it would generate the health check command 
{code}
sh -c 'docker exec 
mesos-ce13aa71-ebba-4361-b6dd-8d4ce57ea4ab-S9.566f6c77-a6c9-46e0-bc40-5fe95a1aa9ae
 sh -c " bash -c "</dev/tcp/$HOST/$PORT" "'
{code}

This leads to the error
{code}
sh: 1: cannot open /dev/tcp/127.0.0.1/80 : No such file
{code}

> Mesos fails to escape command health checks
> -------------------------------------------
>
>                 Key: MESOS-4812
>                 URL: https://issues.apache.org/jira/browse/MESOS-4812
>             Project: Mesos
>          Issue Type: Bug
>    Affects Versions: 0.25.0
>            Reporter: Lukas Loesche
>            Assignee: haosdent
>              Labels: health-check
>         Attachments: health_task.gif
>
>
> As described in https://github.com/mesosphere/marathon/issues/3333
> I would like to run a command health check
> {noformat}
> /bin/bash -c "</dev/tcp/$HOST/$PORT0"
> {noformat}
> The health check fails because Mesos, while running the command inside double 
> quotes of a sh -c "" doesn't escape the double quotes in the command.
> If I escape the double quotes myself the command health check succeeds. But 
> this would mean that the user needs intimate knowledge of how Mesos executes 
> his commands which can't be right.
> I was told this is not a Marathon but a Mesos issue so am opening this JIRA. 
> I don't know if this only affects the command health check.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to