JAva起動と停止sh
4653 ワード
一、説明
Windows下:echo"%JAVA_HOME%"Liunx Crontabタイミングのロジック:/etc/crontab JAVA_HOME/bin/:java-help java:Javaインタプリタ、直接クラスファイルからJavaアプリケーションコードを実行 jps:現在のシステム内のすべてのプロセスではなく、現在のユーザーのJavaプロセスのみを検索します. native 2 ascii:文字またはファイルを変換するための符号化フォーマット
二、起動スクリプト
三、停止スクリプト
Windows下:echo"%JAVA_HOME%"Liunx Crontabタイミングのロジック:/etc/crontab JAVA_HOME/bin/:java-help java:Javaインタプリタ、直接クラスファイルからJavaアプリケーションコードを実行 jps:現在のシステム内のすべてのプロセスではなく、現在のユーザーのJavaプロセスのみを検索します. native 2 ascii:文字またはファイルを変換するための符号化フォーマット
二、起動スクリプト
#!/bin/sh
#set JAVA_HOME
#JAVA_HOME=/usr/local/java
#check JAVA_HOME & java
noJavaHome=false
# -z
if [ -z "$JAVA_HOME" ] ; then
noJavaHome=true
fi
# -e
if [ ! -e "$JAVA_HOME/bin/java" ] ; then
noJavaHome=true
fi
if $noJavaHome ; then
echo
echo "Error: JAVA_HOME environment variable is not set."
echo
exit 1
fi
#==============================================================================
#set JAVA_OPTS
JAVA_OPTS="-server -Xms2048m -Xmx2048m -Xmn512m -Xss512k"
#performance Options
JAVA_OPTS="$JAVA_OPTS -XX:+AggressiveOpts"
JAVA_OPTS="$JAVA_OPTS -XX:+UseBiasedLocking"
JAVA_OPTS="$JAVA_OPTS -XX:+UseFastAccessorMethods"
JAVA_OPTS="$JAVA_OPTS -XX:+DisableExplicitGC"
JAVA_OPTS="$JAVA_OPTS -XX:+UseParNewGC"
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC"
JAVA_OPTS="$JAVA_OPTS -XX:+CMSParallelRemarkEnabled"
JAVA_OPTS="$JAVA_OPTS -XX:+UseCMSCompactAtFullCollection"
JAVA_OPTS="$JAVA_OPTS -XX:+UseCMSInitiatingOccupancyOnly"
JAVA_OPTS="$JAVA_OPTS -XX:CMSInitiatingOccupancyFraction=75"
#GC Log Options
#JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCApplicationStoppedTime"
#JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCTimeStamps"
#JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails"
#debug Options
#JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8065,server=y,suspend=n"
#==============================================================================
#set HOME
PTFENCE_DIR=`pwd`
# , , ( )。
cd `dirname "$0"`/..
PTFENCE_HOME=`pwd`
cd $PTFENCE_DIR
if [ -z "$PTFENCE_HOME" ] ; then
echo
echo "Error: COBAR_HOME environment variable is not defined correctly."
echo
exit 1
fi
#==============================================================================
#set CLASSPATH
PTFENCE_CLASSPATH="$PTFENCE_HOME/conf:$PTFENCE_HOME/lib/classes"
for i in "$PTFENCE_HOME"/lib/*.jar
do
PTFENCE_CLASSPATH="$PTFENCE_CLASSPATH:$i"
done
#==============================================================================
if [ -d "$PTFENCE_HOME/logs" ] ; then
echo "logs dir exits"
else
mkdir $PTFENCE_HOME/logs
fi
#startup Server
#get java
RUN_CMD="\"$JAVA_HOME/bin/java\""
#-D<name>=<value> set a system property
RUN_CMD="$RUN_CMD -Dptfence.home=\"$PTFENCE_HOME\""
#-classpath:class search path of directories and zip/jar files
RUN_CMD="$RUN_CMD -classpath \"$PTFENCE_CLASSPATH\""
#
RUN_CMD="$RUN_CMD $JAVA_OPTS"
#$@
RUN_CMD="$RUN_CMD com.test.inf.ptfence.FenceCore \"$PTFENCE_HOME/conf/config.properties\" $@"
#>>
RUN_CMD="$RUN_CMD >> \"$PTFENCE_HOME/logs/console.log\" 2>&1 "
echo $RUN_CMD
#eval , , ,
eval $RUN_CMD
echo "====exec ptfence complete===="
# ,
echo $?
#==============================================================================
三、停止スクリプト
#!/bin/sh
#set JAVA_HOME
#JAVA_HOME=/usr/local/java
#check JAVA_HOME & java
echo "start shutdown ptfence....."
noJavaHome=false
if [ -z "$JAVA_HOME" ] ; then
noJavaHome=true
fi
if [ ! -e "$JAVA_HOME/bin/java" ] ; then
noJavaHome=true
fi
if $noJavaHome ; then
echo
echo "Error: JAVA_HOME environment variable is not set."
echo
exit 1
fi
#==============================================================================
#set JAVA_OPTS
JAVA_OPTS="-Xss256k"
#==============================================================================
#stop Server
#jps Java ,
$JAVA_HOME/bin/jps |grep FenceCore|awk -F ' ' '{print $1}'|while read line
do
eval "kill -9 $line"
done
rm -rf /tmp/ptfence-*
#==============================================================================
echo "shutdown ptfence success."
jps
17930 Bootstrap
32502 SocketServer
23932 Jps
13193 Bootstrap
23219 Bootstrap
10282 Bootstrap
23907 FenceCore
26118 QuorumPeerMain
#awk -F ' ' '{print $1}' , 12345
#while read line grep 。