Score:0

jcmd works in console but fails in script

in flag

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!

Michael Hampton avatar
cz flag
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`.
in flag
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.
Score:1
fr flag

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

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.