Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Passing java options with special characters has unexpected output #215

Closed
jshrack-ssi opened this issue Apr 7, 2018 · 6 comments
Closed

Comments

@jshrack-ssi
Copy link

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 jeffbyrnes added the bug label Apr 9, 2018
@jeffbyrnes
Copy link
Contributor

jeffbyrnes commented Apr 9, 2018

@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
Copy link
Author

@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
Copy link
Contributor

@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
Copy link
Contributor

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

@jshrack-ssi
Copy link
Author

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
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants