记一个工作中常用的java部署脚本
首先进入linux,
1.使用下面代码段
vim run.sh
2.然后按 i 进入编辑模式
3.拷贝下面脚本代码
#!/bin/sh
#chkconfig: 2345 99 10
#description: Startup and shutdown script for server.jar
export JAVA_HOME=/usr/java/jdk1.8.0_65
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
#update this path
SERVER=/root/xx/xx.jar
ARGS="-Xms2g -Xmx2g -Xmn2g -Xss128k -XX:MaxPermSize=64m -XX:-UseParallelGC -XX:+UseParallelOldGC -XX:ParallelGCThreads=4 -XX:+UseConcMarkSweepGC -XX:MaxTenuringThreshold=30 -XX:SurvivorRatio=6 S"
start()
{
if test -e $SERVER
then
echo -e "Starting $SERVER"
if java -jar $SERVER $ARGS >/dev/null 2>&1 &
then
echo -e "server start OK"
else
echo -e "server start failed"
fi
else
echo -e "Couldn't find $SERVER"
fi
}
stop()
{
pid=`jps -l |grep $SERVER|awk '{print $1}'`
if [ -z "$pid" ]
then
echo "$SERVER is not runing"
exit 0;
fi
echo -e "Stopping server $pid ..."
if kill $pid
then
echo -e "server stop $pid OK"
else
echo -e "server stop $pid failed"
fi
}
restart()
{
echo -e "Restarting server..."
stop
start
}
status()
{
pid=`jps -l |grep $SERVER|awk '{print $1}'`
if [ -z "$pid" ]
then
echo "$SERVER is not running ..."
else
echo "$SERVER is running, pid $pid ..."
fi
}
keepalive()
{
pid=`jps -l |grep $SERVER|awk '{print $1}'`
if [ -z "$pid" ]
then
echo "$SERVER is not running ..."
start
else
echo "$SERVER is running, pid $pid ..."
fi
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
keepalive)
keepalive
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|status}" >&2
exit 1
;;
esac
exit 0
4.Shift+insert粘贴到run.sh的文件里面
5.按Esc退出编辑模式
6.按 :wq 进行保存
7.输入命令
chmod +x run.sh
8.最后使用命令启动程序
./run.sh start
停止程序命令:
./run.sh stop
重启程序命令:
./run.sh restart
都是亲测可用哦~