学习啦 > 学习电脑 > 操作系统 > Linux教程 > linux下启动java程序的通用脚本介绍

linux下启动java程序的通用脚本介绍

时间: 恒辉636 分享

学习啦在线学习网linux下启动java程序的通用脚本介绍

学习啦在线学习网   一、start.sh

  #!/bin/bash

  cd `dirname

学习啦 > 学习电脑 > 操作系统 > Linux教程 > linux下启动java程序的通用脚本介绍

linux下启动java程序的通用脚本介绍

时间: 恒辉636 分享

学习啦在线学习网linux下启动java程序的通用脚本介绍

学习啦在线学习网   一、start.sh

  #!/bin/bash

  cd `dirname

`

学习啦在线学习网   BIN_DIR=`pwd`

  cd ..

  DEPLOY_DIR=`pwd`

  CONF_DIR=$DEPLOY_DIR/conf

  SERVER_NAME=`sed '/server.name/!d;s/.*=//' conf/server.properties | tr -d '\r'`

  SERVER_PORT=`sed '/server.netty.port/!d;s/.*=//' conf/server.properties | tr -d '\r'`

学习啦在线学习网   if [ -z "$SERVER_NAME" ]; then

  SERVER_NAME=`hostname`

  fi

  PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print

linux下启动java程序的通用脚本介绍

  一、start.sh

  #!/bin/bash

  cd `dirname $0`

学习啦在线学习网   BIN_DIR=`pwd`

  cd ..

学习啦在线学习网   DEPLOY_DIR=`pwd`

  CONF_DIR=$DEPLOY_DIR/conf

学习啦在线学习网   SERVER_NAME=`sed '/server.name/!d;s/.*=//' conf/server.properties | tr -d '\r'`

  SERVER_PORT=`sed '/server.netty.port/!d;s/.*=//' conf/server.properties | tr -d '\r'`

  if [ -z "$SERVER_NAME" ]; then

  SERVER_NAME=`hostname`

  fi

学习啦在线学习网   PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`

  if [ -n "$PIDS" ]; then

学习啦在线学习网   echo "ERROR: The $SERVER_NAME already started!"

学习啦在线学习网   echo "PID: $PIDS"

  exit 1

  fi

学习啦在线学习网   if [ -n "$SERVER_PORT" ]; then

  SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l`

  if [ $SERVER_PORT_COUNT -gt 0 ]; then

  echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!"

  exit 1

  fi

  fi

  LOGS_DIR=""

  LOGS_DIR=$DEPLOY_DIR/logs

  #if [ ! -d $LOGS_DIR ]; then

  # mkdir $LOGS_DIR

  #fi

  STDOUT_FILE=$LOGS_DIR/stdout.log

  LIB_DIR=$DEPLOY_DIR/lib

  LIB_JARS=`find $LIB_DIR|grep .jar|awk '{print $0}'|tr "\n" ":"`

  JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "

  JAVA_DEBUG_OPTS=""

  if [ "$1" = "debug" ]; then

学习啦在线学习网   JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n "

  fi

  JAVA_JMX_OPTS=""

学习啦在线学习网   if [ "$1" = "jmx" ]; then

  JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false "

  fi

学习啦在线学习网   JAVA_MEM_OPTS=""

学习啦在线学习网   BITS=`file $JAVA_HOME/bin/java | grep 64-bit`

学习啦在线学习网   if [ -n "$BITS" ]; then

  let memTotal=`cat /proc/meminfo |grep MemTotal|awk '{printf "%d", $2/1024 }'`

  if [ $memTotal -gt 2500 ];then

  JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -Xmn400m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "

  else

学习啦在线学习网   JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -Xmn400m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "

  fi

  else

  JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC "

  fi

学习啦在线学习网   echo -e "Starting the $SERVER_NAME ...\c"

学习啦在线学习网   nohup java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS -classpath $CONF_DIR:$LIB_JARS com.hzins.framework.server.ServerMain > $STDOUT_FILE 2>&1 &

  COUNT=0

  while [ $COUNT -lt 1 ]; do

  echo -e ".\c"

  sleep 1

  # if [ -n "$SERVER_PORT" ]; then

  # COUNT=`echo status | nc 127.0.0.1 $SERVER_PORT -i 1 | grep -c OK`

  # else

学习啦在线学习网   COUNT=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l`

  # fi

  if [ $COUNT -gt 0 ]; then

  break

  fi

  done

学习啦在线学习网   echo "OK!"

学习啦在线学习网   PIDS=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}'`

  echo "PID: $PIDS"

  #echo "STDOUT: $STDOUT_FILE"

学习啦在线学习网   二、stop.sh

  #!/bin/bash

学习啦在线学习网   cd `dirname $0`

学习啦在线学习网   BIN_DIR=`pwd`

  cd ..

学习啦在线学习网   DEPLOY_DIR=`pwd`

学习啦在线学习网   CONF_DIR=$DEPLOY_DIR/conf

  SERVER_NAME=`sed '/server.name/!d;s/.*=//' conf/server.properties | tr -d '\r'`

  if [ -z "$SERVER_NAME" ]; then

学习啦在线学习网   SERVER_NAME=`hostname`

  fi

  PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`

学习啦在线学习网   if [ -z "$PIDS" ]; then

  echo "ERROR: The $SERVER_NAME does not started!"

  exit 1

  fi

  if [ "$1" != "skip" ]; then

学习啦在线学习网   $BIN_DIR/dump.sh

  fi

  echo -e "Stopping the $SERVER_NAME ...\c"

  for PID in $PIDS ; do

  kill $PID > /dev/null 2>&1

  done

  COUNT=0

  while [ $COUNT -lt 1 ]; do

  echo -e ".\c"

  sleep 1

  COUNT=1

学习啦在线学习网   for PID in $PIDS ; do

  PID_EXIST=`ps --no-heading -p $PID`

  if [ -n "$PID_EXIST" ]; then

  COUNT=0

  break

  fi

  done

  done

  echo "OK!"

  echo "PID: $PIDS"

  三、restart.sh

  #!/bin/bash

  cd `dirname $0`

  ./stop.sh

学习啦在线学习网   ./start.sh

}'`

  if [ -n "$PIDS" ]; then

  echo "ERROR: The $SERVER_NAME already started!"

学习啦在线学习网   echo "PID: $PIDS"

  exit 1

  fi

  if [ -n "$SERVER_PORT" ]; then

学习啦在线学习网   SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l`

  if [ $SERVER_PORT_COUNT -gt 0 ]; then

  echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!"

  exit 1

  fi

  fi

学习啦在线学习网   LOGS_DIR=""

  LOGS_DIR=$DEPLOY_DIR/logs

  #if [ ! -d $LOGS_DIR ]; then

学习啦在线学习网   # mkdir $LOGS_DIR

  #fi

  STDOUT_FILE=$LOGS_DIR/stdout.log

  LIB_DIR=$DEPLOY_DIR/lib

  LIB_JARS=`find $LIB_DIR|grep .jar|awk '{print

学习啦 > 学习电脑 > 操作系统 > Linux教程 > linux下启动java程序的通用脚本介绍

linux下启动java程序的通用脚本介绍

时间: 恒辉636 分享

linux下启动java程序的通用脚本介绍

  一、start.sh

学习啦在线学习网   #!/bin/bash

  cd `dirname

学习啦在线学习网}'|tr "\n" ":"`

  JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "

  JAVA_DEBUG_OPTS=""

  if [ " class="main">

学习啦 > 学习电脑 > 操作系统 > Linux教程 > linux下启动java程序的通用脚本介绍

linux下启动java程序的通用脚本介绍

时间: 恒辉636 分享

  JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n "

  fi

  JAVA_JMX_OPTS=""

  if [ " class="main">

学习啦 > 学习电脑 > 操作系统 > Linux教程 > linux下启动java程序的通用脚本介绍

linux下启动java程序的通用脚本介绍

时间: 恒辉636 分享

  JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false "

  fi

  JAVA_MEM_OPTS=""

  BITS=`file $JAVA_HOME/bin/java | grep 64-bit`

学习啦在线学习网   if [ -n "$BITS" ]; then

  let memTotal=`cat /proc/meminfo |grep MemTotal|awk '{printf "%d",

linux下启动java程序的通用脚本介绍

学习啦在线学习网   一、start.sh

学习啦在线学习网   #!/bin/bash

学习啦在线学习网   cd `dirname $0`

  BIN_DIR=`pwd`

  cd ..

  DEPLOY_DIR=`pwd`

学习啦在线学习网   CONF_DIR=$DEPLOY_DIR/conf

  SERVER_NAME=`sed '/server.name/!d;s/.*=//' conf/server.properties | tr -d '\r'`

  SERVER_PORT=`sed '/server.netty.port/!d;s/.*=//' conf/server.properties | tr -d '\r'`

  if [ -z "$SERVER_NAME" ]; then

  SERVER_NAME=`hostname`

  fi

  PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`

  if [ -n "$PIDS" ]; then

学习啦在线学习网   echo "ERROR: The $SERVER_NAME already started!"

  echo "PID: $PIDS"

  exit 1

  fi

  if [ -n "$SERVER_PORT" ]; then

  SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l`

  if [ $SERVER_PORT_COUNT -gt 0 ]; then

  echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!"

  exit 1

  fi

  fi

学习啦在线学习网   LOGS_DIR=""

  LOGS_DIR=$DEPLOY_DIR/logs

  #if [ ! -d $LOGS_DIR ]; then

  # mkdir $LOGS_DIR

  #fi

  STDOUT_FILE=$LOGS_DIR/stdout.log

学习啦在线学习网   LIB_DIR=$DEPLOY_DIR/lib

  LIB_JARS=`find $LIB_DIR|grep .jar|awk '{print $0}'|tr "\n" ":"`

  JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "

学习啦在线学习网   JAVA_DEBUG_OPTS=""

  if [ "$1" = "debug" ]; then

  JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n "

  fi

  JAVA_JMX_OPTS=""

学习啦在线学习网   if [ "$1" = "jmx" ]; then

  JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false "

  fi

学习啦在线学习网   JAVA_MEM_OPTS=""

学习啦在线学习网   BITS=`file $JAVA_HOME/bin/java | grep 64-bit`

学习啦在线学习网   if [ -n "$BITS" ]; then

  let memTotal=`cat /proc/meminfo |grep MemTotal|awk '{printf "%d", $2/1024 }'`

  if [ $memTotal -gt 2500 ];then

  JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -Xmn400m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "

  else

  JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -Xmn400m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "

  fi

  else

学习啦在线学习网   JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC "

  fi

学习啦在线学习网   echo -e "Starting the $SERVER_NAME ...\c"

学习啦在线学习网   nohup java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS -classpath $CONF_DIR:$LIB_JARS com.hzins.framework.server.ServerMain > $STDOUT_FILE 2>&1 &

  COUNT=0

  while [ $COUNT -lt 1 ]; do

学习啦在线学习网   echo -e ".\c"

  sleep 1

  # if [ -n "$SERVER_PORT" ]; then

  # COUNT=`echo status | nc 127.0.0.1 $SERVER_PORT -i 1 | grep -c OK`

  # else

  COUNT=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l`

  # fi

  if [ $COUNT -gt 0 ]; then

  break

  fi

  done

学习啦在线学习网   echo "OK!"

  PIDS=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}'`

学习啦在线学习网   echo "PID: $PIDS"

  #echo "STDOUT: $STDOUT_FILE"

  二、stop.sh

学习啦在线学习网   #!/bin/bash

  cd `dirname $0`

学习啦在线学习网   BIN_DIR=`pwd`

  cd ..

  DEPLOY_DIR=`pwd`

学习啦在线学习网   CONF_DIR=$DEPLOY_DIR/conf

  SERVER_NAME=`sed '/server.name/!d;s/.*=//' conf/server.properties | tr -d '\r'`

学习啦在线学习网   if [ -z "$SERVER_NAME" ]; then

  SERVER_NAME=`hostname`

  fi

  PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`

学习啦在线学习网   if [ -z "$PIDS" ]; then

  echo "ERROR: The $SERVER_NAME does not started!"

  exit 1

  fi

  if [ "$1" != "skip" ]; then

  $BIN_DIR/dump.sh

  fi

  echo -e "Stopping the $SERVER_NAME ...\c"

  for PID in $PIDS ; do

  kill $PID > /dev/null 2>&1

  done

  COUNT=0

  while [ $COUNT -lt 1 ]; do

  echo -e ".\c"

  sleep 1

  COUNT=1

  for PID in $PIDS ; do

  PID_EXIST=`ps --no-heading -p $PID`

学习啦在线学习网   if [ -n "$PID_EXIST" ]; then

  COUNT=0

  break

  fi

  done

  done

学习啦在线学习网   echo "OK!"

学习啦在线学习网   echo "PID: $PIDS"

学习啦在线学习网   三、restart.sh

学习啦在线学习网   #!/bin/bash

  cd `dirname $0`

  ./stop.sh

学习啦在线学习网   ./start.sh

/1024 }'`

学习啦在线学习网   if [ $memTotal -gt 2500 ];then

  JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -Xmn400m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "

  else

学习啦在线学习网   JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -Xmn400m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "

  fi

  else

学习啦在线学习网   JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC "

  fi

  echo -e "Starting the $SERVER_NAME ...\c"

  nohup java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS -classpath $CONF_DIR:$LIB_JARS com.hzins.framework.server.ServerMain > $STDOUT_FILE 2>&1 &

  COUNT=0

  while [ $COUNT -lt 1 ]; do

  echo -e ".\c"

  sleep 1

  # if [ -n "$SERVER_PORT" ]; then

  # COUNT=`echo status | nc 127.0.0.1 $SERVER_PORT -i 1 | grep -c OK`

  # else

  COUNT=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print

linux下启动java程序的通用脚本介绍

学习啦在线学习网   一、start.sh

  #!/bin/bash

  cd `dirname $0`

  BIN_DIR=`pwd`

  cd ..

  DEPLOY_DIR=`pwd`

  CONF_DIR=$DEPLOY_DIR/conf

  SERVER_NAME=`sed '/server.name/!d;s/.*=//' conf/server.properties | tr -d '\r'`

  SERVER_PORT=`sed '/server.netty.port/!d;s/.*=//' conf/server.properties | tr -d '\r'`

  if [ -z "$SERVER_NAME" ]; then

学习啦在线学习网   SERVER_NAME=`hostname`

  fi

  PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`

  if [ -n "$PIDS" ]; then

学习啦在线学习网   echo "ERROR: The $SERVER_NAME already started!"

  echo "PID: $PIDS"

  exit 1

  fi

  if [ -n "$SERVER_PORT" ]; then

  SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l`

学习啦在线学习网   if [ $SERVER_PORT_COUNT -gt 0 ]; then

  echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!"

  exit 1

  fi

  fi

学习啦在线学习网   LOGS_DIR=""

  LOGS_DIR=$DEPLOY_DIR/logs

学习啦在线学习网   #if [ ! -d $LOGS_DIR ]; then

  # mkdir $LOGS_DIR

  #fi

学习啦在线学习网   STDOUT_FILE=$LOGS_DIR/stdout.log

  LIB_DIR=$DEPLOY_DIR/lib

  LIB_JARS=`find $LIB_DIR|grep .jar|awk '{print $0}'|tr "\n" ":"`

  JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "

  JAVA_DEBUG_OPTS=""

  if [ "$1" = "debug" ]; then

学习啦在线学习网   JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n "

  fi

学习啦在线学习网   JAVA_JMX_OPTS=""

  if [ "$1" = "jmx" ]; then

学习啦在线学习网   JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false "

  fi

  JAVA_MEM_OPTS=""

  BITS=`file $JAVA_HOME/bin/java | grep 64-bit`

学习啦在线学习网   if [ -n "$BITS" ]; then

  let memTotal=`cat /proc/meminfo |grep MemTotal|awk '{printf "%d", $2/1024 }'`

学习啦在线学习网   if [ $memTotal -gt 2500 ];then

学习啦在线学习网   JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -Xmn400m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "

  else

学习啦在线学习网   JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -Xmn400m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "

  fi

  else

  JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC "

  fi

  echo -e "Starting the $SERVER_NAME ...\c"

  nohup java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS -classpath $CONF_DIR:$LIB_JARS com.hzins.framework.server.ServerMain > $STDOUT_FILE 2>&1 &

  COUNT=0

  while [ $COUNT -lt 1 ]; do

  echo -e ".\c"

  sleep 1

学习啦在线学习网   # if [ -n "$SERVER_PORT" ]; then

学习啦在线学习网   # COUNT=`echo status | nc 127.0.0.1 $SERVER_PORT -i 1 | grep -c OK`

  # else

  COUNT=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l`

  # fi

学习啦在线学习网   if [ $COUNT -gt 0 ]; then

  break

  fi

  done

学习啦在线学习网   echo "OK!"

学习啦在线学习网   PIDS=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}'`

学习啦在线学习网   echo "PID: $PIDS"

  #echo "STDOUT: $STDOUT_FILE"

  二、stop.sh

  #!/bin/bash

  cd `dirname $0`

  BIN_DIR=`pwd`

  cd ..

学习啦在线学习网   DEPLOY_DIR=`pwd`

学习啦在线学习网   CONF_DIR=$DEPLOY_DIR/conf

  SERVER_NAME=`sed '/server.name/!d;s/.*=//' conf/server.properties | tr -d '\r'`

  if [ -z "$SERVER_NAME" ]; then

  SERVER_NAME=`hostname`

  fi

学习啦在线学习网   PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`

  if [ -z "$PIDS" ]; then

  echo "ERROR: The $SERVER_NAME does not started!"

  exit 1

  fi

  if [ "$1" != "skip" ]; then

  $BIN_DIR/dump.sh

  fi

  echo -e "Stopping the $SERVER_NAME ...\c"

  for PID in $PIDS ; do

  kill $PID > /dev/null 2>&1

  done

  COUNT=0

  while [ $COUNT -lt 1 ]; do

  echo -e ".\c"

  sleep 1

  COUNT=1

学习啦在线学习网   for PID in $PIDS ; do

  PID_EXIST=`ps --no-heading -p $PID`

  if [ -n "$PID_EXIST" ]; then

  COUNT=0

  break

  fi

  done

  done

  echo "OK!"

学习啦在线学习网   echo "PID: $PIDS"

  三、restart.sh

  #!/bin/bash

学习啦在线学习网   cd `dirname $0`

  ./stop.sh

学习啦在线学习网   ./start.sh

}' | wc -l`

  # fi

  if [ $COUNT -gt 0 ]; then

  break

  fi

  done

  echo "OK!"

  PIDS=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print

学习啦在线学习网linux下启动java程序的通用脚本介绍

  一、start.sh

学习啦在线学习网   #!/bin/bash

  cd `dirname $0`

  BIN_DIR=`pwd`

  cd ..

  DEPLOY_DIR=`pwd`

学习啦在线学习网   CONF_DIR=$DEPLOY_DIR/conf

  SERVER_NAME=`sed '/server.name/!d;s/.*=//' conf/server.properties | tr -d '\r'`

  SERVER_PORT=`sed '/server.netty.port/!d;s/.*=//' conf/server.properties | tr -d '\r'`

学习啦在线学习网   if [ -z "$SERVER_NAME" ]; then

  SERVER_NAME=`hostname`

  fi

  PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`

学习啦在线学习网   if [ -n "$PIDS" ]; then

  echo "ERROR: The $SERVER_NAME already started!"

学习啦在线学习网   echo "PID: $PIDS"

  exit 1

  fi

学习啦在线学习网   if [ -n "$SERVER_PORT" ]; then

学习啦在线学习网   SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l`

  if [ $SERVER_PORT_COUNT -gt 0 ]; then

  echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!"

  exit 1

  fi

  fi

学习啦在线学习网   LOGS_DIR=""

学习啦在线学习网   LOGS_DIR=$DEPLOY_DIR/logs

学习啦在线学习网   #if [ ! -d $LOGS_DIR ]; then

  # mkdir $LOGS_DIR

  #fi

  STDOUT_FILE=$LOGS_DIR/stdout.log

学习啦在线学习网   LIB_DIR=$DEPLOY_DIR/lib

  LIB_JARS=`find $LIB_DIR|grep .jar|awk '{print $0}'|tr "\n" ":"`

  JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "

  JAVA_DEBUG_OPTS=""

学习啦在线学习网   if [ "$1" = "debug" ]; then

学习啦在线学习网   JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n "

  fi

学习啦在线学习网   JAVA_JMX_OPTS=""

学习啦在线学习网   if [ "$1" = "jmx" ]; then

  JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false "

  fi

学习啦在线学习网   JAVA_MEM_OPTS=""

  BITS=`file $JAVA_HOME/bin/java | grep 64-bit`

学习啦在线学习网   if [ -n "$BITS" ]; then

学习啦在线学习网   let memTotal=`cat /proc/meminfo |grep MemTotal|awk '{printf "%d", $2/1024 }'`

  if [ $memTotal -gt 2500 ];then

  JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -Xmn400m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "

  else

学习啦在线学习网   JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -Xmn400m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "

  fi

  else

  JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC "

  fi

  echo -e "Starting the $SERVER_NAME ...\c"

  nohup java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS -classpath $CONF_DIR:$LIB_JARS com.hzins.framework.server.ServerMain > $STDOUT_FILE 2>&1 &

  COUNT=0

学习啦在线学习网   while [ $COUNT -lt 1 ]; do

  echo -e ".\c"

  sleep 1

  # if [ -n "$SERVER_PORT" ]; then

学习啦在线学习网   # COUNT=`echo status | nc 127.0.0.1 $SERVER_PORT -i 1 | grep -c OK`

  # else

  COUNT=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l`

  # fi

学习啦在线学习网   if [ $COUNT -gt 0 ]; then

  break

  fi

  done

学习啦在线学习网   echo "OK!"

  PIDS=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}'`

  echo "PID: $PIDS"

  #echo "STDOUT: $STDOUT_FILE"

学习啦在线学习网   二、stop.sh

学习啦在线学习网   #!/bin/bash

学习啦在线学习网   cd `dirname $0`

  BIN_DIR=`pwd`

  cd ..

  DEPLOY_DIR=`pwd`

学习啦在线学习网   CONF_DIR=$DEPLOY_DIR/conf

  SERVER_NAME=`sed '/server.name/!d;s/.*=//' conf/server.properties | tr -d '\r'`

学习啦在线学习网   if [ -z "$SERVER_NAME" ]; then

学习啦在线学习网   SERVER_NAME=`hostname`

  fi

学习啦在线学习网   PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`

  if [ -z "$PIDS" ]; then

  echo "ERROR: The $SERVER_NAME does not started!"

  exit 1

  fi

学习啦在线学习网   if [ "$1" != "skip" ]; then

  $BIN_DIR/dump.sh

  fi

  echo -e "Stopping the $SERVER_NAME ...\c"

学习啦在线学习网   for PID in $PIDS ; do

学习啦在线学习网   kill $PID > /dev/null 2>&1

  done

  COUNT=0

  while [ $COUNT -lt 1 ]; do

  echo -e ".\c"

  sleep 1

  COUNT=1

  for PID in $PIDS ; do

  PID_EXIST=`ps --no-heading -p $PID`

学习啦在线学习网   if [ -n "$PID_EXIST" ]; then

  COUNT=0

  break

  fi

  done

  done

  echo "OK!"

  echo "PID: $PIDS"

学习啦在线学习网   三、restart.sh

  #!/bin/bash

  cd `dirname $0`

  ./stop.sh

  ./start.sh

}'`

学习啦在线学习网   echo "PID: $PIDS"

学习啦在线学习网   #echo "STDOUT: $STDOUT_FILE"

学习啦在线学习网   二、stop.sh

  #!/bin/bash

  cd `dirname

学习啦 > 学习电脑 > 操作系统 > Linux教程 > linux下启动java程序的通用脚本介绍

linux下启动java程序的通用脚本介绍

时间: 恒辉636 分享

linux下启动java程序的通用脚本介绍

  一、start.sh

  #!/bin/bash

  cd `dirname

`

  BIN_DIR=`pwd`

  cd ..

  DEPLOY_DIR=`pwd`

学习啦在线学习网   CONF_DIR=$DEPLOY_DIR/conf

  SERVER_NAME=`sed '/server.name/!d;s/.*=//' conf/server.properties | tr -d '\r'`

  if [ -z "$SERVER_NAME" ]; then

  SERVER_NAME=`hostname`

  fi

  PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print

linux下启动java程序的通用脚本介绍

  一、start.sh

学习啦在线学习网   #!/bin/bash

学习啦在线学习网   cd `dirname $0`

  BIN_DIR=`pwd`

  cd ..

  DEPLOY_DIR=`pwd`

  CONF_DIR=$DEPLOY_DIR/conf

  SERVER_NAME=`sed '/server.name/!d;s/.*=//' conf/server.properties | tr -d '\r'`

  SERVER_PORT=`sed '/server.netty.port/!d;s/.*=//' conf/server.properties | tr -d '\r'`

  if [ -z "$SERVER_NAME" ]; then

  SERVER_NAME=`hostname`

  fi

学习啦在线学习网   PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`

学习啦在线学习网   if [ -n "$PIDS" ]; then

  echo "ERROR: The $SERVER_NAME already started!"

学习啦在线学习网   echo "PID: $PIDS"

  exit 1

  fi

  if [ -n "$SERVER_PORT" ]; then

学习啦在线学习网   SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l`

  if [ $SERVER_PORT_COUNT -gt 0 ]; then

  echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!"

  exit 1

  fi

  fi

学习啦在线学习网   LOGS_DIR=""

  LOGS_DIR=$DEPLOY_DIR/logs

学习啦在线学习网   #if [ ! -d $LOGS_DIR ]; then

  # mkdir $LOGS_DIR

  #fi

学习啦在线学习网   STDOUT_FILE=$LOGS_DIR/stdout.log

学习啦在线学习网   LIB_DIR=$DEPLOY_DIR/lib

  LIB_JARS=`find $LIB_DIR|grep .jar|awk '{print $0}'|tr "\n" ":"`

学习啦在线学习网   JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "

  JAVA_DEBUG_OPTS=""

  if [ "$1" = "debug" ]; then

  JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n "

  fi

学习啦在线学习网   JAVA_JMX_OPTS=""

学习啦在线学习网   if [ "$1" = "jmx" ]; then

  JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false "

  fi

  JAVA_MEM_OPTS=""

  BITS=`file $JAVA_HOME/bin/java | grep 64-bit`

  if [ -n "$BITS" ]; then

  let memTotal=`cat /proc/meminfo |grep MemTotal|awk '{printf "%d", $2/1024 }'`

  if [ $memTotal -gt 2500 ];then

学习啦在线学习网   JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -Xmn400m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "

  else

学习啦在线学习网   JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -Xmn400m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "

  fi

  else

  JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC "

  fi

学习啦在线学习网   echo -e "Starting the $SERVER_NAME ...\c"

学习啦在线学习网   nohup java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS -classpath $CONF_DIR:$LIB_JARS com.hzins.framework.server.ServerMain > $STDOUT_FILE 2>&1 &

  COUNT=0

  while [ $COUNT -lt 1 ]; do

  echo -e ".\c"

  sleep 1

  # if [ -n "$SERVER_PORT" ]; then

  # COUNT=`echo status | nc 127.0.0.1 $SERVER_PORT -i 1 | grep -c OK`

  # else

  COUNT=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l`

  # fi

  if [ $COUNT -gt 0 ]; then

  break

  fi

  done

  echo "OK!"

学习啦在线学习网   PIDS=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}'`

  echo "PID: $PIDS"

  #echo "STDOUT: $STDOUT_FILE"

学习啦在线学习网   二、stop.sh

学习啦在线学习网   #!/bin/bash

学习啦在线学习网   cd `dirname $0`

学习啦在线学习网   BIN_DIR=`pwd`

  cd ..

  DEPLOY_DIR=`pwd`

  CONF_DIR=$DEPLOY_DIR/conf

学习啦在线学习网   SERVER_NAME=`sed '/server.name/!d;s/.*=//' conf/server.properties | tr -d '\r'`

学习啦在线学习网   if [ -z "$SERVER_NAME" ]; then

学习啦在线学习网   SERVER_NAME=`hostname`

  fi

  PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`

  if [ -z "$PIDS" ]; then

  echo "ERROR: The $SERVER_NAME does not started!"

  exit 1

  fi

  if [ "$1" != "skip" ]; then

学习啦在线学习网   $BIN_DIR/dump.sh

  fi

  echo -e "Stopping the $SERVER_NAME ...\c"

学习啦在线学习网   for PID in $PIDS ; do

学习啦在线学习网   kill $PID > /dev/null 2>&1

  done

  COUNT=0

学习啦在线学习网   while [ $COUNT -lt 1 ]; do

  echo -e ".\c"

  sleep 1

  COUNT=1

  for PID in $PIDS ; do

  PID_EXIST=`ps --no-heading -p $PID`

  if [ -n "$PID_EXIST" ]; then

  COUNT=0

  break

  fi

  done

  done

学习啦在线学习网   echo "OK!"

  echo "PID: $PIDS"

学习啦在线学习网   三、restart.sh

  #!/bin/bash

学习啦在线学习网   cd `dirname $0`

  ./stop.sh

学习啦在线学习网   ./start.sh

}'`

  if [ -z "$PIDS" ]; then

  echo "ERROR: The $SERVER_NAME does not started!"

  exit 1

  fi

  if [ " class="main">

学习啦 > 学习电脑 > 操作系统 > Linux教程 > linux下启动java程序的通用脚本介绍

linux下启动java程序的通用脚本介绍

时间: 恒辉636 分享

学习啦在线学习网   $BIN_DIR/dump.sh

  fi

  echo -e "Stopping the $SERVER_NAME ...\c"

  for PID in $PIDS ; do

  kill $PID > /dev/null 2>&1

  done

  COUNT=0

  while [ $COUNT -lt 1 ]; do

学习啦在线学习网   echo -e ".\c"

  sleep 1

  COUNT=1

  for PID in $PIDS ; do

  PID_EXIST=`ps --no-heading -p $PID`

学习啦在线学习网   if [ -n "$PID_EXIST" ]; then

  COUNT=0

  break

  fi

  done

  done

  echo "OK!"

  echo "PID: $PIDS"

学习啦在线学习网   三、restart.sh

  #!/bin/bash

  cd `dirname

学习啦 > 学习电脑 > 操作系统 > Linux教程 > linux下启动java程序的通用脚本介绍
168436