Last active
August 29, 2015 14:02
-
-
Save akutz/d2ad5cde0e1a9cf62b34 to your computer and use it in GitHub Desktop.
Bash profile functions for managing local instances of Atlassian servers such as JIRA and Stash
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
# Stash | |
export STASH_HOME="$HOME/.stash" | |
export STASH_VERSION="3.0.4" | |
export STASH_CATALINA_HOME="$HOME/Servers/stash/$STASH_VERSION" | |
# Jira | |
export JIRA_HOME="$HOME/.jira" | |
export JIRA_VERSION="6.2.7" | |
export JIRA_CATALINA_HOME="$HOME/Servers/jira/$JIRA_VERSION" | |
function pid_for_atlas_server() { | |
PATT=$(echo $1 | ssed -R 's/\./\\./g') | |
ps alx | grep -E "java.*?-Dcatalina.home=$PATT" | awk '{print $2}' | |
} | |
function wait_for_atlas_server_to_stop() { | |
while [ "$(pid_for_atlas_server $1)" != "" ]; do | |
printf " ..." | |
sleep 1 | |
done | |
} | |
function atlas_server_controller() { | |
app_name=$1 | |
app_version=$2 | |
app_home=$3 | |
app_catalina_home=$4 | |
app_action=$5 | |
lcase_app_name=$(echo $app_name | ssed -R 's/([A-Z])/\1/g') | |
pid=$(pid_for_atlas_server $app_catalina_home) | |
case "$app_action" in | |
start) | |
if [ "$pid" != "" ]; then | |
echo "$app_name already running ($pid)" | |
return | |
fi | |
rm -fr $app_home/log/* | |
rm -fr $app_home/tmp/* | |
printf "Starting $app_name $app_version..." | |
$app_catalina_home/bin/start-$lcase_app_name.sh &> /dev/null | |
printf "completed!\n" | |
;; | |
stop) | |
if [ "$pid" == "" ]; then | |
echo "$app_name not running" | |
return | |
fi | |
printf "Stopping $app_name $app_version..." | |
if [ "$pid" != "" ]; then | |
$app_catalina_home/bin/stop-$lcase_app_name.sh &> /dev/null | |
wait_for_atlas_server_to_stop $app_catalina_home | |
fi | |
printf "completed!\n" | |
;; | |
status) | |
if [ "$pid" == "" ]; then | |
echo "$app_name not running" | |
else | |
echo "$app_name is running ($pid)" | |
fi | |
;; | |
restart) | |
atlas_server_controller "$app_name" \ | |
"$app_version" \ | |
"$app_home" \ | |
"$app_catalina_home" \ | |
stop | |
atlas_server_controller "$app_name" \ | |
"$app_version" \ | |
"$app_home" \ | |
"$app_catalina_home" \ | |
start | |
;; | |
esac | |
} | |
function stash() { | |
atlas_server_controller Stash \ | |
$STASH_VERSION \ | |
$STASH_HOME \ | |
$STASH_CATALINA_HOME \ | |
$1 | |
} | |
function jira() { | |
atlas_server_controller Jira \ | |
$JIRA_VERSION \ | |
$JIRA_HOME \ | |
$JIRA_CATALINA_HOME \ | |
$1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment