JAR package deployment script

Deploy a jar package named xxx and output it to out.log, just prepare the following script start.sh

#!/bin/< span style="color: #0000ff;">sh

echo " =====Close Java application======"
PROCESS
=`ps -ef |grep java | grep -v grep|grep xxx.jar|awk '{print $2}'`
for i in $PROCESS
do
echo " Kill the $1 process [$i ]"
kill -9 $i
done
echo " =====Start Java application======"
nohup java
-jar xxx.jar> out.log 2>& 1 &
echo $! > savePid.txt
cat savePid.txt
rm savePid.txt

1. Navigate to the deployment directory, such as /root /home/admin

cd /root/home/admin

2. Upload xxx.jar and start.sh to the current directory

3. Edit this script under windows, the format is DOS, it cannot be executed successfully, you need to change the format first

3.1 Enter vim editing and execute

vim start.sh

3.2 Press the shift key and the: key on the keyboard, and enter< /p>

set ff=unix

3.3 Press shiff+z+z, save and exit vim

4. Execute Script

sh start.sh

The output is as follows, and the deployment is successful.

 =====Close the Java application ======< span style="color: #000000;">

Kill the process [29491]
=====Start Java application======
29608

Of course, you can execute the start.sh script like this

./start.sh

If an error is reported Without permission, you also need to execute the following commands

chmod u+x *.sh

#!/bin/sh

span>

echo =====Close Java application======

PROCESS
=`ps -ef |grep java | grep -v grep|grep xxx.jar|awk {print $2}`

for i in $PROCESS

do

echo Kill the $1 process [$i ]

kill9 $i

done

echo =====Start Java application======

nohup java
-jar xxx.jar> out.log 2>& 1 &

echo $! > savePid.txt

cat savePid.txt

rm savePid.txt

cd /root/home/admin< /pre>

vim start.sh

set ff= unix

sh start.sh

 =====Close Java application======

Kill the process [
29491]
=====Start Java application======
29608

./start.sh

chmod u+x *.sh

Leave a Comment

Your email address will not be published.