Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
94 lines (79 sloc) 2.73 KB
#!/bin/bash -e
echo "[uaa-ctl] UAA Control Setting Up Logging"
exec > >(tee -a >(logger -p user.info -t vcap.$(basename $0).stdout) | awk -W interactive '{ system("echo -n [$(date +\"%Y-%m-%d %H:%M:%S%z\")]"); print " " $0 }' >>/var/vcap/sys/log/uaa/uaa_ctl.log)
exec 2> >(tee -a >(logger -p user.error -t vcap.$(basename $0).stderr) | awk -W interactive '{ system("echo -n [$(date +\"%Y-%m-%d %H:%M:%S%z\")]"); print " " $0 }' >>/var/vcap/sys/log/uaa/uaa_ctl.err.log)
echo "[uaa-ctl] UAA Control script invoked"
RUN_DIR=/var/vcap/sys/run/uaa
LOG_DIR=/var/vcap/sys/log/uaa
JOB_DIR=/var/vcap/jobs/uaa
DATA_DIR=/var/vcap/data/uaa
STATUS=$DATA_DIR/uaa_status
PIDFILE=$RUN_DIR/uaa.pid
mkdir -p /var/vcap/sys/run/uaa
chown vcap:vcap /var/vcap/sys/run/uaa
pid_guard() {
local return_code=0
pidfile=$1
name=$2
if [ -f "$pidfile" ]; then
pid=$(head -1 "$pidfile")
echo "[uaa-pid-guard] PID File has value $pid"
if [ -n "$pid" ] && [ -e /proc/$pid ]; then
echo "[uaa-pid-guard] $name is already running, please stop it first"
return_code=1
else
echo "[uaa-pid-guard] Removing stale pidfile..."
rm $pidfile
fi
fi
return $return_code
}
ensure_no_more_tomcat() {
for java_pid in $(ps -ef |grep java| grep tomcat |grep -Po '\-DPID=\K[^ ]+'); do
echo "[uaa-kill-tomcat] Found leftover Java process - killing($java_pid) if running: `ps -fp $java_pid`"
kill -9 $java_pid
done
}
case $1 in
start)
ulimit -n 65536
export CLOUD_FOUNDRY_CONFIG_PATH=/var/vcap/jobs/uaa/config
export CATALINA_OPTS="<%= p('uaa.catalina_opts') %>"
echo "[uaa-start] UAA start invoked - checking for running process"
if pid_guard $PIDFILE "UAA"
then
echo "[uaa-start] UAA not running according to pid_guard - proceeding with startup"
else
echo "[uaa-start] UAA already running according to pid_guard - aborting start process"
exit 1
fi
echo "[uaa-start] Checking whether tomcat is no longer running..."
ensure_no_more_tomcat
echo "[uaa-start] About to start UAA"
echo $$ > $PIDFILE
chown vcap:vcap $PIDFILE
exec /var/vcap/jobs/uaa/bin/uaa
;;
stop)
echo "[uaa-stop] About to stop UAA"
# This tells the health_check to return false
# and the route will be deregistered
rm -f $STATUS
sleep 5
echo "[uaa-stop] Health check STATUS file removed"
if pid_guard $PIDFILE "UAA"
then
echo "[uaa-check] UAA not running"
else
echo "[uaa-stop] Found UAA Tomcat PID file $PIDFILE - Killing `cat $PIDFILE`"
kill `cat $PIDFILE`
rm -rf $PIDFILE
sleep 5
fi
echo "[uaa-stop] Clearing left over java processes"
ensure_no_more_tomcat
;;
*)
echo "Usage: uaa_ctl {start|stop}"
;;
esac
You can’t perform that action at this time.