#!/bin/sh
SERVICE_NAME=서비스명
echo "Killing SERVICE_NAME: $SERVICE_NAME"
echo "Killing SERVICE ID: `ps -ef|grep -w D$SERVICE_NAME|grep -v grep|awk '{print $2}'`"
kill -9 `ps -ef|grep -w D$SERVICE_NAME|grep -v grep|awk '{print $2}'`
export JAVA_HOME=/svc/java/jdk1.8
export CATALINA_HOME=/svc/tomcat/tomcat8
export CLASSPATH=$CATALINA_HOME/lib/servlet-api.jar
export CATALINA_BASE=$CATALINA_HOME/$SERVICE_NAME
LOG_DIR="$CATALINA_HOME/$SERVICE_NAME/logs"
prefix=`date +%Y%m%d%H%M`
mv $CATALINA_OUT $LOG_DIR/backup/$SERVICE_NAME.out_$prefix
GC_LOG_OUT="$LOG_DIR/gclogs/gc.log"
mv $GC_LOG_OUT $LOG_DIR/gclogs/backup/gc.log_$prefix
touch $CATALINA_OUT
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib
export LD_LIBRARY_PATH
exec $JAVA_HOME/bin/java \
-server \
-Xms256m -Xmx256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m \
-D$SERVICE_NAME \
-Djava.awt.headless=true \
-Djava.endorsed.dirs=$CATALINA_HOME/common/endorsed \
-classpath $CLASSPATH:$CATALINA_HOME/bin/bootstrap.jar:$CATALINA_HOME/bin/commons-logging-api.jar:$CATALINA_HOME/bin/tomcat-juli.jar \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-verbose:gc \
-Xloggc:$LOG_DIR/gclogs/gc.log \
-XX:+PrintGCDetails \
-XX:+PrintGCTimeStamps \
org.apache.catalina.startup.Bootstrap "$@" start \
>> $CATALINA_OUT 2>&1 &
# 2>&1 & | /apache설치위치/bin/rotatelogs "$CATALINA_OUT"-%Y-%m-%d.log 86400 540 &
echo "Using SERVICE_NAME: $SERVICE_NAME"
echo "Using JAVA_HOME: $JAVA_HOME"
echo "Using CLASSPATH: $CLASSPATH"
echo "Using CATALINA_HOME: $CATALINA_HOME"
echo "Using CATALINA_BASE: $CATALINA_BASE"
echo "Using CATALINA_OUT: $CATALINA_OUT"