bachelor-thesis/chapters/thesis/appendix04_calling_script.sh

173 lines
4.8 KiB
Bash
Raw Normal View History

2024-08-16 22:13:36 +02:00
#!/bin/bash
payara_path="/opt/docker/payara"
postgres_path="/var/lib/postgres"
postgres_path="/opt/docker"
postgres_data_path="$postgres_path/data"
postgres_log_path=$postgres_data_path/log
payara_config="$payara_path/config/domain.xml"
domain_log="$payara_path/logs/server.log"
script_path="/opt/docker/timing.sh"
pgbadger_out="/opt/docker/pgreport"
report_postfix=""
2024-08-19 21:00:19 +02:00
report_postno=""
2024-08-16 22:13:36 +02:00
docker_name=dcpgbatch
COMPOSE_FILE=/opt/docker/docker-compose.yaml
gflog() {
echo "follow the log: $domain_log"
tail -f $domain_log
}
gfconf() {
nvim "$payara_config"
}
gfscript() {
outPath=$pgbadger_out$report_postfix/bash.out
touch "$outPath"
echo "============================================================" >>"$outPath"
bash $script_path | tee -a "$outPath"
}
pginit() {
sudo chmod g+x $postgres_path
sudo chmod g+x $postgres_data_path
sudo chmod g+rx $postgres_log_path
}
pglogls() {
echo "show postgresql logfiles"
ls $postgres_log_path/ -lhtc
}
pglogrm() {
cnt=${1:-10}
cntTail=$(($cnt + 1))
echo "remove old postgresql logfiles from $(ls $postgres_log_path/ -tc | wc -l) until $cnt (~${cnt}00 MB) $cntTail"
ls $postgres_log_path/ -tc | tail -n +$cntTail | xargs -r -I{} sudo rm "$postgres_log_path/{}"
}
pglog() {
pg_log=$(ls $postgres_log_path/ -tc --ignore '*log' | head -n 1)
echo "follow the log: $postgres_log_path/$pg_log"
tail -n 3 -f $postgres_log_path/$pg_log
}
pgconf() {
sudo nvim "${postgres_path}/postgresql.conf"
}
pgrp() {
mkdir -p $pgbadger_out$report_postfix
2024-08-19 21:00:19 +02:00
mkdir -p $pgbadger_out$report_postfix$report_postno
2024-08-16 22:13:36 +02:00
outPath=$pgbadger_out$report_postfix/bash.out
touch "$outPath"
echo "" >>"$outPath"
2024-08-19 21:00:19 +02:00
pgbadger -X -I -f jsonlog -j 10 -O $pgbadger_out$report_postfix$report_postno $postgres_log_path/postgresql-*.json 2>&1 | tee -a "$outPath"
2024-08-16 22:13:36 +02:00
}
pgrpres() {
2024-08-21 00:30:20 +02:00
if [[ "$report_postfix" == "" ]]; then
2024-08-19 21:00:19 +02:00
rm -R $pgbadger_out
else
rm -R $pgbadger_out$report_postfix*
fi
2024-08-16 22:13:36 +02:00
}
dccreate() {
sudo docker compose -f $COMPOSE_FILE create --force-recreate
}
dcstart() {
sudo docker compose -f $COMPOSE_FILE start
sleep 2
pginit
}
dcstop() {
sudo docker compose -f $COMPOSE_FILE stop
}
2024-08-21 23:44:10 +02:00
dcres() {
sudo docker compose -f $COMPOSE_FILE down
}
2024-08-16 22:13:36 +02:00
dcstats() {
sudo docker stats
}
for name in "$@"; do
case $name in
2024-08-19 21:00:19 +02:00
-rppf=*) report_postfix="${name#*=}" ;;
-rppn=*) report_postno="${name#*=}" ;;
2024-08-16 22:13:36 +02:00
gflog) gflog ;;
gfconf) gfconf ;;
gfscript) gfscript ;;
2024-08-19 21:00:19 +02:00
gfrestart) pgrpinit ;;
2024-08-16 22:13:36 +02:00
pginit) pginit ;;
pglogls) pglogls ;;
pglogrm) pglogrm ;;
pglog) pglog ;;
pgconf) pgconf ;;
pgrestart) pgrestart ;;
pgrp) pgrp ;;
pgrpres) pgrpres ;;
dcinit) dccreate ;;
dcstart) dcstart ;;
dcstop) dcstop ;;
2024-08-21 23:44:10 +02:00
dcres) dcres ;;
2024-08-16 22:13:36 +02:00
dcstats) dcstats ;;
measinit)
2024-08-19 21:00:19 +02:00
pginit
2024-08-16 22:13:36 +02:00
pgrpres
pglogrm 0
dccreate
dcstart
;;
measres)
dcstop
pgrpres
pglogrm 0
dcstart
pgrp
pglogrm
;;
meascall)
gfscript
pgrp
pglogrm
;;
help)
echo "CALLING: $0 <function> [ <function>]"
echo "The overview of the functions of this script."
echo "It is allowed to enter multiple functions in one execute,"
echo "that would be called serialized."
echo "ATTENTION: parameter must be defined in front of the commands!"
echo ""
echo "*** parameter ***"
2024-08-19 21:00:19 +02:00
echo " -rppf=<val> Postfix name for the report-folder (used by gfscript, pgrp, pgrpres, measres, meascall)"
echo " -rppn=<val> Postfix number for the report-folder (used by pgrp, measres, meascall)"
2024-08-16 22:13:36 +02:00
echo ""
echo "*** glassfish ***"
echo " gflog Show and follow the log of the glassfish server with $domain_name"
echo " gfconf Open the configuration file from glassfish server"
echo " gfscript Calls the testscript for the website"
echo ""
echo "*** postgresql ***"
echo " pginit Initialize the folder for postgresql log-folder"
echo " pglogls Show the current content of the log-folder from postgresql"
echo " pglogrm Clean the log-folder from postgresql, the newest 20 files are sill available"
echo " pglog Show and follow the last log from postgresql"
echo " pgconf Open the configuration file from postgresql"
echo " pgrestart Restart the postgresql"
echo " pgrp Generate the pgbadger report from postgresql log files"
echo " pgrpres Resetet the output of pgbadger"
echo ""
echo "*** docker ***"
echo " dcinit Docker erstellen"
2024-08-21 23:44:10 +02:00
echo " dcstart Docker Container starten"
echo " dcstop Docker Container stoppen"
echo " dcres Docker Container stoppen und loeschen"
2024-08-16 22:13:36 +02:00
echo " dcstats Docker live Statistik anzeigen"
echo ""
echo "*** combine cmds ***"
echo " measinit Initialize everthing after start"
echo " measres reset data for new measuring"
echo " meascall execute one measure"
;;
*)
echo >&2 "Invalid option $name"
exit 1
;;
esac
done