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

Lukas Loesche commented on MESOS-4812:
--------------------------------------

I think you're mixing up syntax. What you wrote was
{noformat}
command.set_value("bash -c \"</dev/tcp/$HOST/$PORT0\"");
{noformat}
which is a direct call to set_value().

Whereas what I wrote is
{noformat}
    {
      "protocol": "COMMAND",
      "command": { "value": "/bin/bash -c \"</dev/tcp/$HOST/$PORT0\"" }
    }
{noformat}
as part of a JSON file! Remember that the JSON data must also be escaped.
The escaped double quote \" will be replaced by the JSON parser.

So the command that's being send to Mesos ends up being:
{noformat}
/bin/bash -c "</dev/tcp/$HOST/$PORT0"
{noformat}
which is a perfectly valid shell command but will not execute successfully.

What you have to send to Mesos is
{noformat}
/bin/bash -c \"</dev/tcp/$HOST/$PORT0\"
{noformat}
because Mesos will take that string and put a /bin/sh -c "" around it.

To do that the JSON file that you're sending to Marathon has to look like this:
{noformat}
  {
    "protocol": "COMMAND",
    "command": { "value": "/bin/bash -c \\\"</dev/tcp/$HOST/$PORT0\\\"" }
  }
{noformat}

So here I'm escaping the backslash as well as the double quotes inside the JSON 
string so that I'm left with one backslash and double quotes after the JSON 
parser has processed the data. That can then be send to Mesos and successfully 
executed.

But as you can see from this conversation this gets confusing really quickly 
even for people working with it daily. So how can we expect our users to work 
with it.


> 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
>
> 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