67 lines
1.5 KiB
Bash
Executable File
67 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
##################################################
|
|
# Mount dir #
|
|
# - /opt/tomcat/webapps #
|
|
# - /opt/tomcat/logs #
|
|
# ENV #
|
|
# - JAVA_OPTS #
|
|
# - CATALINA_OUT #
|
|
##################################################
|
|
|
|
set -euo pipefail
|
|
export LANG=en_US.UTF-8
|
|
trap Quit EXIT
|
|
|
|
PIDS=
|
|
GOT_SIGTERM=
|
|
CATALINA_OUT=${CATALINA_OUT:-/dev/null}
|
|
export JAVA_OPTS="-server -Djava.security.egd=file:/dev/./urandom -Duser.timezone=GMT+08 ${JAVA_OPTS:-}"
|
|
|
|
function Print {
|
|
local file=/dev/null
|
|
[ '-f' = "$1" ] && file=$2 && shift && shift
|
|
date +"[%F %T] $*" | tee -a $file
|
|
}
|
|
|
|
function Quit {
|
|
Print killing java ...
|
|
while :; do
|
|
pkill -f java && Print killing java ... || break
|
|
sleep 1
|
|
done
|
|
Print Container stopped.
|
|
test -n "$GOT_SIGTERM"
|
|
}
|
|
|
|
function RestoreConf {
|
|
if [ -z "$(ls conf/)" ]; then
|
|
Print Restore default config files and quit ...
|
|
tar zxf conf.tgz
|
|
exit
|
|
fi
|
|
}
|
|
|
|
function StartProc {
|
|
Print Start tomcat ...
|
|
./bin/catalina.sh run &>> $CATALINA_OUT &
|
|
PIDS="$PIDS $!"
|
|
}
|
|
|
|
function Main {
|
|
local pid=
|
|
cd /opt/tomcat
|
|
RestoreConf
|
|
StartProc
|
|
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
|
|
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
|
|
for pid in $PIDS; do
|
|
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
|
|
done
|
|
done
|
|
}
|
|
|
|
# Start here
|
|
Main
|
|
|