Last active
March 21, 2018 21:06
-
-
Save guizordan/2bab6703b2aaed0889faaa34ad265ce5 to your computer and use it in GitHub Desktop.
Glassfish script that starts a domain, stops every other running domain, deploys the latest .ear version and displays logging. Usage: 'bash deploy_glassfish domain-name'
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 | |
ear_path=~/projeto/FSJ/ambiente/maven_repo/br/com/fsj/retaguarda/fsj-retaguarda-ear/1.0-SNAPSHOT/fsj-retaguarda-ear-1.0-SNAPSHOT.ear | |
glassfish_path=~/glassfish-3.1.2.2/glassfish | |
domains_list=$(asadmin list-domains) | |
project_path=~/projeto/FSJ/branches/18.03.3.0 | |
memory_usage=$(free -m | awk 'NR==2{ printf " %.2f", $3*100/$2 }') | |
maximum_memory_usage=75.00 | |
function setDatabaseDialect { | |
if [ ! -z "${1}" ]; then | |
echo -e "Setting fsj-retaguarda-core-projeto/pom.xml to use ${1} dialect\n" | |
cd $project_path/fsj-retaguarda-core/fsj-retaguarda-core-projeto/ | |
if [ "$1" = "oracle" ]; then | |
sed -i -e 's/FirebirdDialect/Oracle10gDialect/g' pom.xml | |
elif [ "$1" = "firebird" ]; then | |
sed -i -e 's/Oracle10gDialect/FirebirdDialect/g' pom.xml | |
fi | |
fi | |
} | |
function mvn_install { | |
cd $project_path | |
mvn -T 1C install -offline | |
} | |
declare -a domains=() | |
for d in $glassfish_path/domains/*; do | |
domains+=("${d##*/}") | |
done | |
if [$memory_usage'>'$maximum_memory_usage | bc -l]; then | |
echo -e "\nMemory overload\nStopping all domains" | |
for i in "${domains[@]}"; do | |
asadmin stop-domain $i | |
done | |
fi | |
#check if passed domain exists inside glassfish's folder | |
if [[ " ${domains[@]} " == *" ${1} "* ]]; then | |
killall tail -q | |
echo -e "\nChecking for running domains...\n" | |
for domain in ${domains[@]}; do | |
# checks if is target domain | |
if [ $domain == ${1} ]; then | |
setDatabaseDialect $2 | |
# execute maven's fast build | |
mvn_install | |
if echo $domains_list | grep -q "${1} not running"; then | |
echo -e "\nStarting $domain\n" | |
asadmin start-domain $1 | |
else | |
echo -e "\n$domain already running" | |
fi | |
else | |
if echo $domains_list | grep -q "${domain} running"; then | |
echo -e "\nStopping $domain\n" | |
asadmin stop-domain $domain | |
else | |
echo -e "\n$domain is not running" | |
fi | |
fi | |
done | |
#deploys the application and checks its status | |
echo -e "\nDeploying ear...\n" | |
deploy_status=$(asadmin deploy --force=true $ear_path) | |
if echo $deploy_status | grep -q "Command deploy executed successfully."; then | |
echo -e "\nSuccessfully deployed!\n Displaying logs...\n" | |
tail -f -n 50 "$glassfish_path/domains/$1/logs/server.log" & disown | |
else | |
echo -e "\nDeploy failed...\nStopping the domain" | |
asadmin stop-domain $1 | |
fi | |
else | |
echo -e "Invalid domain.\nAvailable domains: ${domains[@]}" | |
exit | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment