systemd managed java can not be attached

Bug #1981523 reported by virusdefender
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
tomcat9 (Ubuntu)
New
Undecided
Unassigned

Bug Description

The default `/lib/systemd/system/tomcat9.service` contains `PrivateTmp` `AmbientCapabilities` `ProtectSystem` it will cause the java process can not be attached, many tools like 'jstack' must use this mechanism to communicate with jvm.

```
➜ tomcat9 ps -ef | grep java
tomcat 86960 1 99 13:50 ? 00:00:02 /usr/lib/jvm/java-11-openjdk-amd64/bin/java -Djava.util.logging.config.file=/var/lib/tomcat9/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headless=true -XX:+UseG1GC -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/share/tomcat9/bin/bootstrap.jar:/usr/share/tomcat9/bin/tomcat-juli.jar -Dcatalina.base=/var/lib/tomcat9 -Dcatalina.home=/usr/share/tomcat9 -Djava.io.tmpdir=/tmp org.apache.catalina.startup.Bootstrap start
ubuntu 86992 72538 0 13:50 pts/0 00:00:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn java

➜ tomcat9 sudo su -l tomcat -s /bin/bash

tomcat@ubuntu:/$ jstack 86960
86960: Unable to open socket file /proc/86960/root/tmp/.java_pid86960: target process 86960 doesn't respond within 10500ms or HotSpot VM not loaded
```

If related options are removed, jstack can work

```
➜ tomcat9 sudo vim /lib/systemd/system/tomcat9.service

➜ tomcat9 sudo systemctl daemon-reload && sudo systemctl restart tomcat9

➜ tomcat9 ps -ef | grep java
tomcat 87095 1 81 13:50 ? 00:00:03 /usr/lib/jvm/java-11-openjdk-amd64/bin/java -Djava.util.logging.config.file=/var/lib/tomcat9/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headless=true -XX:+UseG1GC -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/share/tomcat9/bin/bootstrap.jar:/usr/share/tomcat9/bin/tomcat-juli.jar -Dcatalina.base=/var/lib/tomcat9 -Dcatalina.home=/usr/share/tomcat9 -Djava.io.tmpdir=/tmp org.apache.catalina.startup.Bootstrap start
ubuntu 87129 72538 0 13:51 pts/0 00:00:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn java

➜ tomcat9 sudo su -l tomcat -s /bin/bash

tomcat@ubuntu:/$ jstack 87095
2022-07-13 13:51:09
Full thread dump OpenJDK 64-Bit Server VM (11.0.15+10-Ubuntu-0ubuntu0.18.04.1 mixed mode, sharing):

Threads class SMR info:

........
```

description: updated
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.