Linux常用jar包启动停止脚本sh命令

启动

修改WORK_DIR和RUNTIME_JAR为自己的即可.
启动时会把进程号写出到pid.txt文件中.

start.sh

#!/bin/bash

set  -e

echo "starting ..."
WORK_DIR=/home/icepoint/icepoin-web-code
RUNTIME_JAR=icepoint-web-code-0.0.1-RELEASE.jar

sleep 1s

nohup /usr/local/jdk1.8.0_201/bin/java  -Dfile.encoding=UTF-8 -jar -Xmx512m  $WORK_DIR/$RUNTIME_JAR  >  $WORK_DIR/nohup_console.log 2>&1 &  

pid=$!
echo $pid > $WORK_DIR/pid.txt

停止

读取pid.txt文件进程号,并杀死进程

stop.sh

#!/bin/bash -x 
WORK_DIR=`dirname $0` 
 
 [ -f "$WORK_DIR/pid.txt" ] && pid=`cat $WORK_DIR/pid.txt` 

[ $pid ] && ps $pid || exit 0 
kill  $pid && echo OK
posted @ 2021-06-25 10:42  juyss  阅读(713)  评论(0编辑  收藏  举报