java项目启动_Java项目通过启动jar启动项目脚本

贴出一个项目启动脚本,内容如下:

#!/bin/bash

# Steps:

# Removing /app/sit/# unzip /app/sit/.candidates/.zip to /app/sit//app

# cd to /app/sit//app, and run java -jar ${JAVA_OPTS} xxx.jar

#

# logs are stored in /app/sit//logs

# If you want to overwrite config files in the jar, move it to /app/sit//conf

#

# /app/sit

#     |── .candidates

#     │   └──xxx.zip (Jenkins build with `deploy=true` will place zips here)

#     └── #         ├── app

#         │   ├── -.jar

#         │   └── lib

#         │       ├── activemq-all-5.11.3.jar

#         │       ├── ...

#         │       └── utility-cache-redis-0.0.1-SNAPSHOT.jar

#         ├── conf

#         │   └── env-xxx.properties (optional)

#         └── logs

#             └── biz.log

#######################################################################################

################  variable starts  ##############

JAVA_OPTS=${JAVA_OPTS:-"-Xms256m -Xmx256m"}

#JAVA_OPTS="-server -Xms8G -Xmx8G -XX:+UseG1GC -XX:MaxGCPauseMillis=200"

#JAVA_OPTS="-server -Xms512m -Xmx512m -XX:SurvivorRatio=2 -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSInitiatingOccupancyOnly -XX:+ScavengeBeforeFullGC -XX:+CMSScavengeBeforeRemark -XX:CMSInitiatingOccupancyFraction=65 -XX:+ParallelRefProcEnabled -verbose:gc -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+PrintTenuringDistribution -Xloggc:../logs/gc-`date +%F_%H-%M-%S`.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=50M -Dsun.net.inetaddr.ttl=30 -Djava.security.egd=file:/dev/./urandom -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../logs/dump-`date +%F_%H-%M-%S`.hprof"

################  variable stops  ###############

work_dir=${PWD}/app

pidfile=${PWD}/pid

app_name=`pwd`

############## functions ###############

start() {

>> app/nohup.out

cd ${work_dir}

echo "starting..."

nohup $JAVA_HOME/bin/java ${JAVA_OPTS} -jar *.jar  &

#  nohup java ${JAVA_OPTS} -jar *.jar >/dev/null 2>&1 &

echo $! > ${pidfile}

echo "started."

}

stop() {

if is_running; then

kill  ${pid}

echo "${app_name} stopped successfully."

else

echo "${app_name} is NOT running"

rm -f ${pidfile}

fi

}

status() {

if is_running; then

echo "${app_name} is running..."

else

echo "${app_name} is NOT running"

fi

}

is_running() {

pid=`cat ${pidfile}`

if [ -e "/proc/${pid}" ] && [ "java" == "`cat /proc/${pid}/comm`" ]; then

return 0

else

rm -f ${pidfile}

return 1

fi

}

############## functions calls ###############

case $1 in

start)

if is_running; then

echo "${app_name} is already running."

else

start

fi

;;

stop)

if [ -e "${pidfile}" ];then

stop

exit 1

else

echo "${app_name} is NOT running"

fi

;;

status)

status

;;

restart)

stop

sleep 1

start

;;

deploy)

stop

sleep 1

deploy_zip

sleep 1

start

;;

*)

echo "./bootstrap.sh (start|stop|restart|deploy|status)"

esac

之后通过./bootstrap.sh (start|stop|restart|deploy|status) 脚本启动服务了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值