当前位置: 首页 > 工具软件 > pwd.sh > 使用案例 >

linux环境下,java应用启停脚本参考(start.sh/stop.sh)

宰父劲
2023-12-01

start.sh

MAIN_CLASS=


CLASSPATH='.';

JVM_PARMS=""


export APP_HOME=$(dirname $(pwd))

export APP_APPS=$APP_HOME/apps

export APP_RESOURCES=$APP_HOME/conf

export APP_LIB=$APP_HOME/lib

export APP_LOG=$APP_HOME/logs;

export APP_NAME=$(basename $APP_HOME)


function make_logs_dir {

        if [ ! -e "/data/logs/$APP_NAME" ]; then mkdir -p "/data/logs/$APP_NAME"; fi

        if [ ! -d "$APP_LOG" ]; then ln -sf "/data/logs/$APP_NAME" "$APP_LOG"; fi

}

make_logs_dir



for i in $APP_APPS/*;

  do CLASSPATH="$CLASSPATH":$i;

done


CLASSPATH="$CLASSPATH":$APP_RESOURCES;


for i in $APP_LIB/*;

  do CLASSPATH="$CLASSPATH":$i;

done


#echo -e $CLASSPATH


nohup java -cp $CLASSPATH  $JVM_PARMS  $MAIN_CLASS >> $APP_LOG/${APP_NAME}.out 2>&1 &

stop.sh

export APP_HOME=$(dirname $(pwd))

export APP_APPS=$APP_HOME/apps

export APP_RESOURCES=$APP_HOME/conf

export APP_LIB=$APP_HOME/lib

export APP_LOG=$APP_HOME/logs;

export APP_NAME=$(basename $APP_HOME)



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


if [ $pid ]; then


  kill $pid


  stop_timeout=30

  for no in $(seq 1 $stop_timeout); do

    if ps -p "$pid" 2>&1 > /dev/null; then

      if [ $no -lt $stop_timeout ]; then

        echo "[$no] shutdown server ..."

        sleep 1

        continue

      fi


      echo "shutdown server timeout, kill process: $pid"

      echo "`date +'%Y-%m-%-d %H:%M:%S'` , pid : [$pid] , error message : abnormal shutdown which can not be closed within 30s" > $APP_LOG/shutdown.error

      kill -9 $pid; sleep 1; break;

    else

      echo "shutdown server ok!"; break;

    fi

  done

fi

 类似资料: