1

I'm getting mad with what should be a simple task: a java process is running, runs out of memory and a script runs.

SELinux is disabled.

in setenv.sh :

-XX:OnOutOfMemoryError='/opt/alfresco/scripts/dumpNrestart.sh > /tmp/dumpNrestart.log 2>&1'

in /etc/sudoers.d/alfresco_sudoers :
%alfresco ALL= NOPASSWD: /opt/alfresco/java/bin/jcmd

in dumpNrestart.sh :
#!/bin/sh -x
PIDDE=$(cat /opt/alfresco/tomcat/temp/catalina.pid)
/bin/rm -f /tmp/"$PIDDE".hprof
/bin/sudo /bin/id
/bin/sudo /opt/alfresco/java/bin/jcmd "$PIDDE" GC.heap_dump /tmp/"$PIDDE".hprof
/opt/alfresco/tomcat/bin/shutdown.sh -force

Running dumpNrestart.sh from bash, with an unprivileged user works while it doesn't when called by the JVM (that runs with the same user):
++ cat /opt/alfresco/tomcat/temp/catalina.pid
+ PIDDE=11451
+ /bin/rm -f /tmp/11451.hprof
+ /opt/alfresco/java/bin/jcmd 11451 GC.heap_dump /tmp/11451.hprof
11451:
com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file /proc/11451/root/tmp/.java_pid11451: target process 11451 doesn't respond within 10500ms or HotSpot VM not loaded
        at jdk.attach/sun.tools.attach.VirtualMachineImpl.<init>(VirtualMachineImpl.java:100)
        at jdk.attach/sun.tools.attach.AttachProviderImpl.attachVirtualMachine(AttachProviderImpl.java:58)
        at jdk.attach/com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:207)
        at jdk.jcmd/sun.tools.jcmd.JCmd.executeCommandForPid(JCmd.java:114)
        at jdk.jcmd/sun.tools.jcmd.JCmd.main(JCmd.java:98)
+ /opt/alfresco/tomcat/bin/shutdown.sh -force

I guess it is a permission/privilege issue but with sudo I thought I was done... but I'm not as we see.

Any ideas, something I could try?

Thanks for your time reading this!

  • Why do you think there is a permission problem? The error message said: `target process 11451 doesn't respond within 10500ms or HotSpot VM not loaded`. – Michael Hampton Sep 28 '21 at 12:12
  • Hi Micheal, there's something (something I'm missing, maybe not permissions) about how jcmd gets called: running the script from bash always works but if called from the JVM it doesn't. I don't think it is a real timeout problem "10500ms" because from console the dump takes not even 5'' to be created and it is always created. – Francesco Papini Sep 28 '21 at 12:20

1 Answers1

2

Try using & .This will make the script to run in the background. And it will have access.

-XX:OnOutOfMemoryError='sh /opt/alfresco/scripts/dumpNrestart.sh &'