shell启动脚本,用于启动jar包
#! /bin/bash
##java env
export JAVA_HOME=$JAVA_HOME
export JRE_HOME=$JAVA_HOME/jre
##service name
APP_NAME=odps-plugin
VERSION='1.0'
SERVICE_DIR=/opt/muxin.sun/$APP_NAME
SERVICE_NAME=com-qxwz-ops-report-$APP_NAME
JAR_NAME=$SERVICE_NAME-$VERSION\.jar
PID=$SERVICE_NAME\.pid
##entry dir
cd $SERVICE_DIR
##mkdir logs
mkdir -p logs
case "$1" in
start)
P_ID=`ps -ef | grep -w "$SERVICE_NAME" | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
nohup $JRE_HOME/bin/java -Xms512m -Xmx1024m -jar $JAR_NAME > logs/odps.log 2>&1 &
echo $1 >$SERVICE_DIR/$PID
echo "===== start $SERVICE_NAME"
else
echo "======= $SERVER_NAME process exits"
fi
;;
stop)
rm -rf $SERVICE_DIR/$PID
echo "====== stop $SERVICE_NAME"
sleep 5
P_ID=`ps -ef | grep -w "$SERVICE_NAME" | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
echo "======= $SERVER_NAME process not exits or stop success"
else
echo "======= $SERVER_NAME process pid is:$P_ID"
echo "======= begin kill $SERVER_NAME process, pid is :$P_ID"
kill -9 $P_ID
fi
;;
restart)
$0 stop
sleep 2
$0 start
echo "======= restart $SERVER_NAME"
;;
*)
##restart
echo "====== Unrecognized Command"
esac
exit 0
## END