Create Confluence Debug target on running production environment

Is it possible to create a debug target (https://developer.atlassian.com/server/framework/atlassian-sdk/creating-a-remote-debug-target/) against a running production envionment of Confluence? (edit

Hi Dirk,

You can open the debug port on any JVM by passing it parameters at startup. It needs to restart (I don’t think there is anyway to open the debug port after it started). DO NOT DO IT IN PRODUCTION, because:

  • Anyone can then attach their own IDE to the debug port of Confluence and modify system properties,
  • System properties is what Confluence uses to know whether they are in dev mode (-Datlassian.dev.mode=true). When you are in dev mode, you can bypass a lot of security and some plugins even allow writing straight to the database.
  • Once you have been once in dev mode, there is no clear way to know what someone else could have installed in the JVM or modified in the database, and the production instance is tainted forever.

If you want to do it for a test environment which looks like a running production environment, go to /bin/setenv.sh, and locate this section at the bottom:

...
CATALINA_OPTS="-Xms1024m -Xmx1024m -XX:+UseG1GC ${CATALINA_OPTS}"
CATALINA_OPTS="-Dsynchrony.enable.xhr.fallback=true ${CATALINA_OPTS}"
CATALINA_OPTS="-Dorg.apache.tomcat.websocket.DEFAULT_BUFFER_SIZE=32768 ${CATALINA_OPTS}"
CATALINA_OPTS="-Djava.locale.providers=JRE,SPI,CLDR ${CATALINA_OPTS}"
CATALINA_OPTS="${START_CONFLUENCE_JAVA_OPTS} ${CATALINA_OPTS}"
CATALINA_OPTS="-Dconfluence.context.path=${CONFLUENCE_CONTEXT_PATH} ${CATALINA_OPTS}"
CATALINA_OPTS="-Djdk.tls.server.protocols=TLSv1.1,TLSv1.2 -Djdk.tls.client.protocols=TLSv1.1,TLSv1.2 ${CATALINA_OPTS}"
CATALINA_OPTS="-XX:ReservedCodeCacheSize=256m -XX:+UseCodeCacheFlushing ${CATALINA_OPTS}"

Add the following line (for Java 8):

CATALINA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 ${CATALINA_OPTS}"

The correct line is provided by Intellij IDEA when you configure the debug launch configuration (Debug “Remote JVM”), don’t forget to select the correct Java version:

Best regards,
Adrien Ragot

2 Likes

You can follow my answer here: How can we debug a code in intellij which is present on a remote server?

2 Likes