Created
September 22, 2016 21:55
-
-
Save johntbush/2980b8b09c52ad0cedaa522d791285ae to your computer and use it in GitHub Desktop.
thread_dump
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # manually create a heap dump file for tomcat using jmap | |
| . /etc/profile.d/common_shell_functions | |
| get_tomcat_pid() { | |
| PID=$(service tomcat status | awk {'print $3'} | sed 's/)//g') | |
| [[ -z $PID ]] && die "Unable to determine tocat pid; does not appear to be running" | |
| } | |
| # main | |
| get_tomcat_pid | |
| TOMCAT_DIR=<%= scope.function_hiera(["app_basedir"]) %>/tomcat | |
| HEAPDUMP_FILE="manual_pid${PID}_$(date +%Y%m%d%H%M%S).hprof" | |
| RUNAS='sudo -u rsmart' | |
| cd $TOMCAT_DIR || die "Unable to go to $TOMCAT_DIR" | |
| $RUNAS jmap -dump:format=b,file=${HEAPDUMP_FILE} $PID | |
| [[ $? -ne 0 ]] && die "Unable to create heap dump file $HEAPDUMP_FILE" | |
| $RUNAS chmod 644 $HEAPDUMP_FILE | |
| [[ $? -ne 0 ]] && die "Unable to chmod ${HEAPDUMP_FILE}" | |
| echo "Compressing the following heap dump file:" | |
| ls -lGh $HEAPDUMP_FILE | |
| $RUNAS pbzip2 -l $HEAPDUMP_FILE | |
| [[ $? -ne 0 ]] && die "Unable to pbzip -l ${HEAPDUMP_FILE}" | |
| echo "Created heap dump file ${TOMCAT_DIR}/${HEAPDUMP_FILE}.bz2 for tomcat PID $PID" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment