DUBBO-479 修复start.sh在mac下的错误

This commit is contained in:
liangfei0201 2012-08-03 13:27:44 +08:00
parent 96c3193f1c
commit 5fbd2bd9bd
3 changed files with 39 additions and 35 deletions

View File

@ -12,7 +12,7 @@ if [ -z "$SERVER_NAME" ]; then
SERVER_NAME=`hostname` SERVER_NAME=`hostname`
fi fi
PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'` PIDS=`ps -f | grep java | grep "$CONF_DIR" |awk '{print $2}'`
if [ -z "$PIDS" ]; then if [ -z "$PIDS" ]; then
echo "ERROR: The $SERVER_NAME does not started!" echo "ERROR: The $SERVER_NAME does not started!"
exit 1 exit 1
@ -58,6 +58,7 @@ for PID in $PIDS ; do
echo -e ".\c" echo -e ".\c"
fi fi
done done
if [ -r /bin/netstat ]; then if [ -r /bin/netstat ]; then
/bin/netstat -an > $DATE_DIR/netstat.dump 2>&1 /bin/netstat -an > $DATE_DIR/netstat.dump 2>&1
echo -e ".\c" echo -e ".\c"
@ -86,5 +87,6 @@ if [ -r /usr/bin/uptime ]; then
/usr/bin/uptime > $DATE_DIR/uptime.dump 2>&1 /usr/bin/uptime > $DATE_DIR/uptime.dump 2>&1
echo -e ".\c" echo -e ".\c"
fi fi
echo "OK!" echo "OK!"
echo "DUMP: $DATE_DIR" echo "DUMP: $DATE_DIR"

View File

@ -6,14 +6,15 @@ DEPLOY_DIR=`pwd`
CONF_DIR=$DEPLOY_DIR/conf CONF_DIR=$DEPLOY_DIR/conf
SERVER_NAME=`sed '/dubbo.application.name/!d;s/.*=//' conf/dubbo.properties | tr -d '\r'` SERVER_NAME=`sed '/dubbo.application.name/!d;s/.*=//' conf/dubbo.properties | tr -d '\r'`
SERVER_PROTOCOL=`sed '/dubbo.protocol.name/!d;s/.*=//' conf/dubbo.properties | tr -d '\r'`
SERVER_PORT=`sed '/dubbo.protocol.port/!d;s/.*=//' conf/dubbo.properties | tr -d '\r'` SERVER_PORT=`sed '/dubbo.protocol.port/!d;s/.*=//' conf/dubbo.properties | tr -d '\r'`
LOGS_FILE=`sed '/dubbo.log4j.file/!d;s/.*=//' conf/dubbo.properties | tr -d '\r'` LOGS_FILE=`sed '/dubbo.log4j.file/!d;s/.*=//' conf/dubbo.properties | tr -d '\r'`
if [ -z "$SERVER_NAME" ]; then if [ -z "$SERVER_NAME" ]; then
SERVER_NAME=`hostname` SERVER_NAME=`hostname`
fi fi
PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'` PIDS=`ps -f | grep java | grep "$CONF_DIR" |awk '{print $2}'`
if [ -n "$PIDS" ]; then if [ -n "$PIDS" ]; then
echo "ERROR: The $SERVER_NAME already started!" echo "ERROR: The $SERVER_NAME already started!"
echo "PID: $PIDS" echo "PID: $PIDS"
@ -21,21 +22,21 @@ if [ -n "$PIDS" ]; then
fi fi
if [ -n "$SERVER_PORT" ]; then if [ -n "$SERVER_PORT" ]; then
SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l` SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l`
if [ $SERVER_PORT_COUNT -gt 0 ]; then if [ $SERVER_PORT_COUNT -gt 0 ]; then
echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!" echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!"
exit 1 exit 1
fi fi
fi fi
LOGS_DIR="" LOGS_DIR=""
if [ -n "$LOGS_FILE" ]; then if [ -n "$LOGS_FILE" ]; then
LOGS_DIR=`dirname $LOGS_FILE` LOGS_DIR=`dirname $LOGS_FILE`
else else
LOGS_DIR=$DEPLOY_DIR/logs LOGS_DIR=$DEPLOY_DIR/logs
fi fi
if [ ! -d $LOGS_DIR ]; then if [ ! -d $LOGS_DIR ]; then
mkdir $LOGS_DIR mkdir $LOGS_DIR
fi fi
STDOUT_FILE=$LOGS_DIR/stdout.log STDOUT_FILE=$LOGS_DIR/stdout.log
@ -52,16 +53,11 @@ 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 " JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false "
fi fi
JAVA_MEM_OPTS="" JAVA_MEM_OPTS=""
BITS=`file $JAVA_HOME/bin/java | grep 64-bit` BITS=`java -version 2>&1 | grep -i 64-bit`
if [ -n "$BITS" ]; then if [ -n "$BITS" ]; then
let memTotal=`cat /proc/meminfo |grep MemTotal|awk '{printf "%d", $2/1024 }'` JAVA_MEM_OPTS=" -server -Xmx2g -Xms2g -Xmn256m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "
if [ $memTotal -gt 2500 ];then
JAVA_MEM_OPTS=" -server -Xmx2g -Xms2g -Xmn256m -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 -Xmx1g -Xms1g -Xmn256m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "
fi
else else
JAVA_MEM_OPTS=" -server -Xms1024m -Xmx1024m -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC " JAVA_MEM_OPTS=" -server -Xms1g -Xmx1g -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC "
fi fi
echo -e "Starting the $SERVER_NAME ...\c" echo -e "Starting the $SERVER_NAME ...\c"
@ -72,15 +68,20 @@ while [ $COUNT -lt 1 ]; do
echo -e ".\c" echo -e ".\c"
sleep 1 sleep 1
if [ -n "$SERVER_PORT" ]; then if [ -n "$SERVER_PORT" ]; then
COUNT=`echo status | nc 127.0.0.1 $SERVER_PORT -i 1 | grep -c OK` if [ "$SERVER_PROTOCOL" == "dubbo" ]; then
COUNT=`echo status | nc -i 1 127.0.0.1 $SERVER_PORT | grep -c OK`
else
COUNT=`netstat -an | grep $SERVER_PORT | wc -l`
fi
else else
COUNT=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l` COUNT=`ps -f | grep java | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l`
fi
if [ $COUNT -gt 0 ]; then
break
fi fi
if [ $COUNT -gt 0 ]; then
break
fi
done done
echo "OK!" echo "OK!"
PIDS=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}'` PIDS=`ps -f | grep java | grep "$DEPLOY_DIR" | awk '{print $2}'`
echo "PID: $PIDS" echo "PID: $PIDS"
echo "STDOUT: $STDOUT_FILE" echo "STDOUT: $STDOUT_FILE"

View File

@ -8,22 +8,22 @@ CONF_DIR=$DEPLOY_DIR/conf
SERVER_NAME=`sed '/dubbo.application.name/!d;s/.*=//' conf/dubbo.properties | tr -d '\r'` SERVER_NAME=`sed '/dubbo.application.name/!d;s/.*=//' conf/dubbo.properties | tr -d '\r'`
if [ -z "$SERVER_NAME" ]; then if [ -z "$SERVER_NAME" ]; then
SERVER_NAME=`hostname` SERVER_NAME=`hostname`
fi fi
PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'` PIDS=`ps -f | grep java | grep "$CONF_DIR" |awk '{print $2}'`
if [ -z "$PIDS" ]; then if [ -z "$PIDS" ]; then
echo "ERROR: The $SERVER_NAME does not started!" echo "ERROR: The $SERVER_NAME does not started!"
exit 1 exit 1
fi fi
if [ "$1" != "skip" ]; then if [ "$1" != "skip" ]; then
$BIN_DIR/dump.sh $BIN_DIR/dump.sh
fi fi
echo -e "Stopping the $SERVER_NAME ...\c" echo -e "Stopping the $SERVER_NAME ...\c"
for PID in $PIDS ; do for PID in $PIDS ; do
kill $PID > /dev/null 2>&1 kill $PID > /dev/null 2>&1
done done
COUNT=0 COUNT=0
@ -32,12 +32,13 @@ while [ $COUNT -lt 1 ]; do
sleep 1 sleep 1
COUNT=1 COUNT=1
for PID in $PIDS ; do for PID in $PIDS ; do
PID_EXIST=`ps --no-heading -p $PID` PID_EXIST=`ps -f -p $PID | grep java`
if [ -n "$PID_EXIST" ]; then if [ -n "$PID_EXIST" ]; then
COUNT=0 COUNT=0
break break
fi fi
done done
done done
echo "OK!" echo "OK!"
echo "PID: $PIDS" echo "PID: $PIDS"