shell script ps grep kill kill the process and publish jar package shell

Uses: Linux deletion process and start the java service shell script

Objective: To test environment quickly publish jar Service

Code: directly copied and saved to a linux executable startjar.sh (chmod + x startjar.sh set as executable)

#createby:lipp
#createtime:2020.03.12
#description:start a java service
#usages:
# your jar package in path:/tmp/
#./startjar.sh order-1.0.0.jar 
#

#1.please write your name of package
package=$1
copypath=$2
#如果没有输入路径,则设置默认复制jar包的路径为/tmp/
if [ -z $copypath ]; then
copypath=/tmp/
fi
echo '1.jar name '$1', need copy from :'$copypath

#2.kill pid
echo '2.kill process ...'
ps -ef|grep $1|awk  'NR==1{ print $2}'|xargs kill -9

#将jar包从路径复制到当前目录
if [ -n $iscopy ]; then
echo '3.delete old jar...'
rm -rf $1
echo '4. is copy form /tmp/'$1'...'
cp $copypath$1 .
fi

echo '5.start jar...'
nohup java -jar $1 &
#打印启动后的进程数据
ps -ef|grep $1
echo '-- over.'

usage:

1. First, copy your jar or bag to put / tmp /

2. In the old jar package you put in the path of execution: ./ startjar.sh order-1.0.0.jar / tmp / or ./startjar.sh order-1.0.0.jar 

The default path not written / tmp /. Jar which was order-1.0.0.jar package name, path behind

 

This record only simple common shell to write their own, easy to find.

Published 15 original articles · won praise 9 · views 10000 +

Guess you like

Origin blog.csdn.net/keep_running2/article/details/104825906