-
-
Save pfallasro/587322b79fe244c9164a315f49d7d277 to your computer and use it in GitHub Desktop.
plumbr_service
This file contains 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 | |
# File references | |
JbossStandAloneFile=/usr/local/jboss/bin/standalone.sh | |
PlumbrPropertiesFile=/opt/securelink/java/plumbr/plumbr.properties | |
# JBoss file setting o be added in /usr/local/jboss/bin/standalone.sh | |
JbossSetting='JAVA_OPTS=\"$JAVA_OPTS -javaagent:\/opt\/securelink\/java\/plumbr\/plumbr.jar\"' | |
# Plumbr settings to be added in /opt/securelink/java/tools/plumbr/plumbr.properties | |
ClusterID=$(echo "${HOSTNAME}" | cut -d'.' -f3) | |
PlumbrClusterID="clusterId=${ClusterID}" | |
PlumbrJVMID="jvmId=$HOSTNAME" | |
# Shared Functions | |
function restart_jboss () { | |
echo "Restarting JBoss" | |
/etc/init.d/jboss restart > /dev/null | |
echo "JBoss restarted" | |
} | |
# Menu Functions | |
function enable_plumbr () { | |
# Adding Plumbr properties | |
if [ -f "$PlumbrPropertiesFile" ]; then | |
echo "Adding clusterId and jvmId plumbr.properties" | |
sed -i "s/^clusterId=.*/$PlumbrClusterID/g" "$PlumbrPropertiesFile" | |
sed -i "s/^jvmId=.*/$PlumbrJVMID/g" "$PlumbrPropertiesFile" | |
else | |
echo "plumbr.properties file not found!" | |
exit 1 | |
fi | |
# Setting up Jboss standalone.sh with Plumbr | |
if [ -f "$JbossStandAloneFile" ]; then | |
if grep -q "$JbossSetting" "$JbossStandAloneFile"; then | |
echo "Plumbr setting already exist in standalone.sh" | |
exit 1 | |
else | |
echo "Adding Plumbr settings to standalone.sh after Shebang" | |
sed -i "/^#!\/bin\/sh/a $JbossSetting" "$JbossStandAloneFile" | |
restart_jboss | |
exit 0 | |
fi | |
else | |
echo "Jboss standalone.sh file not found!" | |
exit 1 | |
fi | |
} | |
function disable_plumbr () { | |
# Setting up Jboss standalone.sh without Plumbr | |
if [ -f "$JbossStandAloneFile" ]; then | |
if grep -q "$JbossSetting" "$JbossStandAloneFile"; then | |
echo "Removing JbossSetting from JbossStandAloneFile" | |
sed -i "/$JbossSetting/d" "$JbossStandAloneFile" | |
restart_jboss | |
exit 0 | |
else | |
echo "Plumbr setting no longer exists in standalone.sh" | |
exit 1 | |
fi | |
else | |
echo "Jboss standalone.sh file not found!" | |
exit 1 | |
fi | |
} | |
function help_menu () { | |
cat << EOF | |
Usage: ${0} (-h | -E | -D ) | |
OPTIONS: | |
-h|--help Show this message | |
-D|--disable Disable Plumbr agent from this machine | |
-E|--enable Enable Plumbr agent on this machine | |
EXAMPLES: | |
Disable Plumbr agent: | |
$ plumbr_service -D | |
Enable Plumbr agent: | |
$ plumbr_service -E | |
EOF | |
} | |
while [[ $# -gt 0 ]] | |
do | |
case "${1}" in | |
-h|--help) | |
help_menu | |
shift | |
;; | |
-D|--disable) | |
disable_plumbr | |
shift | |
;; | |
-E|--enable) | |
enable_plumbr | |
shift | |
;; | |
*) | |
echo "${1} is not a valid flag, try running: ${0} --help" | |
;; | |
esac | |
shift | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment