linux上简单的run.sh脚本,用来执行java -jar,包含启动停止重启

#:/bin/sh
. /etc/profile
CURRENT_DIR=$(cd $(dirname $0); pwd)

start(){
    nohup java -jar ${CURRENT_DIR}/*.jar &
    echo $! > ./pid
    echo "启动完成!PID:$(cat ./pid)"
}
stop(){
    processId=$(cat ./pid)
    echo $processId
    kill -9 $processId
    rm -f  ./pid
    echo "关闭完成!"
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    stop
    sleep 3
    start
    ;;
  *)
    echo "Usage: run.sh  {start|stop|restart}"
     ;;
esac

你可能感兴趣的:(java,jar,linux)