脚本部署

startup.sh

#!/bin/bash

#如果没有tmp_dir目录则创建

dir="/clh-zq/image"

if [ ! -d "$dir" ];then

mkdir $dir

#项目名

PROJECTNAME=exam_clh_zq

pid=`ps -ef |grep $PROJECTNAME |grep -v "grep" |awk '{print $2}'`

if [ $pid ]; then

​  echo "$PROJECTNAME is running and pid=$pid"

else

  echo "Starting $PROJECTNAME ...."

  nohup java -jar $PROJECTNAME.jar &

fi



stop.sh

#!/bin/bash

PROJECTNAME=exam_clh_zq

pid=`ps -ef |grep $PROJECTNAME |grep -v "grep" |awk '{print $2}' `

if [ $pid ]; then

    echo "$PROJECTNAME is  running  and pid=$pid"

    kill -9 $pid

    if [[ $? -eq 0 ]];then

      echo "sucess to stop $PROJECTNAME "

    else

      echo "fail to stop $PROJECTNAME "

    fi

fi


问题


在从windows中copy到文件后可能出现转义问题等.

方法:

yum -y install dos2unix

dos2unix startup.sh


注意:

stop.sh搜索项目是按文件名搜索

当你有A项目叫做project,B项目叫projectB,当两个项目同时启动时,你在调用A的stop.sh时会关闭不掉项目,因为它搜索到的是一个数组,假设你没有启动项目A,调用A的stop.sh他会关掉B项目

你可能感兴趣的:(脚本部署)