一个通用的java应用程序启动shell脚本:
#!/bin/bash
cd `dirname $0`
CUR_SHELL_DIR=`pwd`
CUR_SHELL_NAME=`basename ${BASH_SOURCE}`
#修改这儿jar包名就可以
JAR_NAME=\"console.jar\"
JAR_PATH=$CUR_SHELL_DIR/$JAR_NAME
#JAVA_MEM_OPTS=\" -server -Xms1024m -Xmx1024m -XX:PermSize=128m\"
JAVA_MEM_OPTS=\"\"
#SPRING_PROFILES_ACTIV=\"-Dspring.profiles.active=prod\"
SPRING_PROFILES_ACTIV=\"\"
JAR_LIB=\"-Dloader.path=libs/\"
echo_help()
{
echo -e \"syntax: sh $CUR_SHELL_NAME start|stop\"
}
if [ -z $1 ];then
echo_help
exit 1
fi
if [ \"$1\" == \"start\" ];then
# check server
PIDS=`ps --no-heading -C java -f --width 1000 | grep $JAR_NAME | awk \'{print $2}\'`
if [ -n \"$PIDS\" ]; then
echo -e \"ERROR: The $JAR_NAME already started and the PID is ${PIDS}.\"
exit 1
fi
echo \"Starting the $JAR_NAME...\"
# start
nohup java $JAR_LIB $JAVA_MEM_OPTS -jar $SPRING_PROFILES_ACTIV $JAR_PATH >> /dev/null 2>&1 &
COUNT=0
while [ $COUNT -lt 1 ]; do
sleep 1
COUNT=`ps --no-heading -C java -f --width 1000 | grep \"$JAR_NAME\" | awk \'{print $2}\' | wc -l`
if [ $COUNT -gt 0 ]; then
break
fi
done
PIDS=`ps --no-heading -C java -f --width 1000 | grep \"$JAR_NAME\" | awk \'{print $2}\'`
echo \"${JAR_NAME} Started and the PID is ${PIDS}.\"
elif [ \"$1\" == \"stop\" ];then
PIDS=`ps --no-heading -C java -f --width 1000 | grep $JAR_NAME | awk \'{print $2}\'`
if [ -z \"$PIDS\" ]; then
echo \"ERROR:The $JAR_NAME does not started!\"
exit 1
fi
echo -e \"Stopping the $JAR_NAME...\"
for PID in $PIDS; do
kill $PID > /dev/null 2>&1
done
COUNT=0
while [ $COUNT -lt 1 ]; do
sleep 1
COUNT=1
for PID in $PIDS ; do
PID_EXIST=`ps --no-heading -p $PID`
if [ -n \"$PID_EXIST\" ]; then
COUNT=0
break
fi
done
done
echo -e \"${JAR_NAME} Stopped and the PID is ${PIDS}.\"
else
echo_help
exit 1
假如您喜爱文中,就请运动您的发家致富手为文中关注点赞评价分享,让我们一起学习培训大量运维管理有关专业知识,最终请还记得关注我。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。