evertrue / zookeeper-cookbook

Chef cookbook for installing and managing Zookeeper.
https://supermarket.chef.io/cookbooks/zookeeper
Apache License 2.0
81 stars 119 forks source link

Passing java options with special characters has unexpected output #215

Closed jshrack-ssi closed 4 years ago

jshrack-ssi commented 6 years ago

When passing a java option for Prometheus jmx_exporter: '-javaagent:$JMX_DIR/jmx_prometheus_javaagent.jar=9099:$JMX_DIR/conf/config.yaml' the resultant output in the zookeeper-env.sh file becomes:

export JVMFLAGS=-Xmx3013m\ -javaagent:\$JMX_DIR/jmx_prometheus_javaagent.jar\=9099:\$JMX_DIR/conf/config.yaml

As you can see the resource takes the special characters , '$', and '=' and escapes them. Even if you try to escape them in the attributes it results in double escape characters ('\') instead of the expected clear result. I've tried numerous variations with no success. I'm not certain whether this is a problem with the hashed resource or Chef.

jeffbyrnes commented 6 years ago

@jshrack-ssi this is likely something with the exports_config() method, provided by the magic cookbook.

I just discovered that cookbook has been archived to a separate repo by its maintainer, @sczizzo, with the original repo deleted.

I dug up the archived version of the exports_config() method, and confirmed that is identical to the v1.5.0 published version of that method.

To save you a click:

def exports_config obj, header=nil
  obj.map do |k, v|
    if v.nil?
      k.to_s
    else
      "export #{k}=#{Shellwords.escape v.to_s}"
    end
  end.join("\n")
end

In this case, it’s that Shellwords.escape() that’s causing what you describe.

However, the string isn’t output with any quotations, so the escapes should make it work properly… Tricky business though.

jshrack-ssi commented 6 years ago

@jeffbyrnes Totally agree with your analysis. I actually wrapped my expression in a Shellwords.escape to see what would happen. Sure enough, it adds additional escape characters. The only real option I can think of is overwriting the entire config file to achieve the desired outcome. Thoughts?

jeffbyrnes commented 6 years ago

@jshrack-ssi, does it also quote your expression? If not, then the escaping might be a good thing.

Otherwise, if this is undesirable, we’ll want to abandon exports_config() in favor of our own version. Phooey. I dislike that sort of thing.

jeffbyrnes commented 6 years ago

A pull request is welcome, by the way; I’ve very little bandwidth right now.

jshrack-ssi commented 6 years ago

No, no quoting. I actually was attempting to insert quotes as it's required when using special characters in JVM options. Those too are escaped of course. Let me see what I can do with it as a workaround and I'll submit a PR if successful.

jeffbyrnes commented 4 years ago

I’m going to go ahead & close this out; @jshrack-ssi if you ever managed a workaround, I’d still love to see it & perhaps include it.