2

I start my java with these arguments

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/log/${SERVICE}_`date +%Y-%m-%d:%H:%M:%S`.hprof"

When heap dump occurs, the .hprof file has -rw------- (600) permission, which can't be read by other users.

How do I make these files generated with 644 permission?

Attempt: I tried passing this -XX:+HeapDumpOnOutOfMemoryError="chmod 644 *.hprof" but got the error:

Improperly specified VM option 'HeapDumpOnOutOfMemoryError=chmod'

What should be the correct syntax? Thank you

hydradon
  • 1,316
  • 1
  • 21
  • 52
  • Did your check your umask settings? Typically applications use that umask settings that the environment drops on them? – GhostCat Oct 10 '18 at 02:58
  • 1
    @GhostCat other generated logs have correct `644` though. E.g: gc.log, nohup.log – hydradon Oct 10 '18 at 02:59
  • https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html says that *HeapDumpOnOutOfMemoryError* is an **option**. What makes you think that you can pass a **shell command** to that in the first place?! – GhostCat Oct 10 '18 at 03:03
  • @GhostCat I followed this post https://stackoverflow.com/questions/12484559/can-you-override-the-file-permissions-for-the-heap-dump-produced-by-xxheapdump . However, if that's not the way, any suggestion for the original question? – hydradon Oct 10 '18 at 03:11
  • Did you try the second answer, pointing to a shell script? ( beyond that, that is the thing with these -XX options: they are subject to change at any point. it is possible that this worked with earlier versions of java, but doesnt work with the specific jvm implementation you are using ) – GhostCat Oct 10 '18 at 03:13

1 Answers1

4

Found the issue, the correct args list should be

-XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError='chmod 644 *.hprof' -XX:HeapDumpPath=/log/${SERVICE}_`date +%Y-%m-%d:%H:%M:%S`.hprof"

Since I put everything inside double quote and then put in JAVA_OPTIONS, the inner quotes should be single

hydradon
  • 1,316
  • 1
  • 21
  • 52