Commit b0c49a2e authored by baixj's avatar baixj

Merge branch 'master' of gitlab.ibreader.com:script/deploy-script

parents 91ec3af8 0b6aa6ad
# deploy-script
#!/bin/bash
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
DEPLOY_DIR=`pwd`
CONF_DIR=$DEPLOY_DIR/conf
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'`
LOGS_FILE=`sed '/dubbo.log4j.file/!d;s/.*=//' conf/dubbo.properties | tr -d '\r'`
if [ -z "$SERVER_NAME" ]; then
SERVER_NAME=`hostname`
fi
PIDS=`ps -f | grep java | 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="/data/dubbo/"
if [ -n "$LOGS_FILE" ]; then
LOGS_DIR=`dirname $LOGS_FILE`
else
LOGS_DIR=$DEPLOY_DIR/logs
fi
if [ ! -d $LOGS_DIR ]; then
mkdir $LOGS_DIR
fi
STDOUT_FILE=$LOGS_DIR/stdout.log
LIB_DIR=$DEPLOY_DIR/lib
LIB_JARS=`ls $LIB_DIR|grep .jar|awk '{print "'$LIB_DIR'/"$0}'|tr "\n" ":"`
JAVA_OPTS="-Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "
#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=`java -version 2>&1 | grep -i 64-bit`
if [ -n "$BITS" ]; then
#JAVA_MEM_OPTS="-Ddubbo.registry.file=dubbo-registry-Order-0.cache -server -Xms3550m -Xmx3550m -Xmn2048m -XX:PermSize=128m -Xss2000k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "
JAVA_MEM_OPTS="-Ddubbo.registry.file=dubbo-registry-Order-0.cache -server -Xms4096m -Xmx4096m -Xmn2048m -XX:PermSize=384m -Xss2000k -XX:SurvivorRatio=4 -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 -XX:ParallelGCThreads=4 -XX:-UseAdaptiveSizePolicy -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${LOGS_DIR}/HeapDumpOnOutOfMemoryError.log"
else
JAVA_MEM_OPTS=" -server -Xms512m -Xmx512m -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.alibaba.dubbo.container.Main > $STDOUT_FILE 2>&1 &
COUNT=0
while [ $COUNT -lt 1 ]; do
echo -e ".\c"
sleep 1
if [ -n "$SERVER_PORT" ]; then
if [ "$SERVER_PROTOCOL" == "dubbo1" ]; then
COUNT=`echo status | nc -i 1 127.0.0.1 $SERVER_PORT | grep -c OK`
else
COUNT=`netstat -lnp | grep $SERVER_PORT | wc -l`
fi
else
COUNT=`ps -f | grep java | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l`
fi
if [ $COUNT -gt 0 ]; then
break
fi
done
echo "OK!"
PIDS=`ps -f | grep java | grep "$DEPLOY_DIR" | awk '{print $2}'`
echo "PID: $PIDS"
echo "STDOUT: $STDOUT_FILE"
#!/bin/bash
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
DEPLOY_DIR=`pwd`
CONF_DIR=$DEPLOY_DIR/conf
SERVER_NAME=`sed '/dubbo.application.name/!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
SERVER_NAME=`hostname`
fi
PIDS=`ps -f | grep "com.alibaba.dubbo.container.Main" |awk '{print $2}'`
if [ -z "$PIDS" ]; then
echo "ERROR: The $SERVER_NAME does not started!"
exit 1
fi
LOGS_DIR=""
if [ -n "$LOGS_FILE" ]; then
LOGS_DIR=`dirname $LOGS_FILE`
else
LOGS_DIR=$DEPLOY_DIR/logs
fi
if [ ! -d $LOGS_DIR ]; then
mkdir $LOGS_DIR
fi
DUMP_DIR=$LOGS_DIR/dump
if [ ! -d $DUMP_DIR ]; then
mkdir $DUMP_DIR
fi
DUMP_DATE=`date +%Y%m%d%H%M%S`
DATE_DIR=$DUMP_DIR/$DUMP_DATE
if [ ! -d $DATE_DIR ]; then
mkdir $DATE_DIR
fi
echo -e "Dumping the $SERVER_NAME ...\c"
for PID in $PIDS ; do
jstack $PID > $DATE_DIR/jstack-$PID.dump 2>&1
echo -e ".\c"
jinfo $PID > $DATE_DIR/jinfo-$PID.dump 2>&1
echo -e ".\c"
jstat -gcutil $PID > $DATE_DIR/jstat-gcutil-$PID.dump 2>&1
echo -e ".\c"
jstat -gccapacity $PID > $DATE_DIR/jstat-gccapacity-$PID.dump 2>&1
echo -e ".\c"
jmap $PID > $DATE_DIR/jmap-$PID.dump 2>&1
echo -e ".\c"
jmap -heap $PID > $DATE_DIR/jmap-heap-$PID.dump 2>&1
echo -e ".\c"
jmap -histo $PID > $DATE_DIR/jmap-histo-$PID.dump 2>&1
echo -e ".\c"
if [ -r /usr/sbin/lsof ]; then
/usr/sbin/lsof -p $PID > $DATE_DIR/lsof-$PID.dump
echo -e ".\c"
fi
done
if [ -r /bin/netstat ]; then
/bin/netstat -an > $DATE_DIR/netstat.dump 2>&1
echo -e ".\c"
fi
if [ -r /usr/bin/iostat ]; then
/usr/bin/iostat > $DATE_DIR/iostat.dump 2>&1
echo -e ".\c"
fi
if [ -r /usr/bin/mpstat ]; then
/usr/bin/mpstat > $DATE_DIR/mpstat.dump 2>&1
echo -e ".\c"
fi
if [ -r /usr/bin/vmstat ]; then
/usr/bin/vmstat > $DATE_DIR/vmstat.dump 2>&1
echo -e ".\c"
fi
if [ -r /usr/bin/free ]; then
/usr/bin/free -t > $DATE_DIR/free.dump 2>&1
echo -e ".\c"
fi
if [ -r /usr/bin/sar ]; then
/usr/bin/sar > $DATE_DIR/sar.dump 2>&1
echo -e ".\c"
fi
if [ -r /usr/bin/uptime ]; then
/usr/bin/uptime > $DATE_DIR/uptime.dump 2>&1
echo -e ".\c"
fi
echo "OK!"
echo "DUMP: $DATE_DIR"
#!/bin/bash
starttime=`date +'%Y-%m-%d %H:%M:%S'`
logdir=/data/api/logs
old_day=`date +%Y%m%d -d"-7 days"`
filename=$logdir/*-$old_day*
rm -f $filename
echo " 删除文件: $filename"
endtime=`date +'%Y-%m-%d %H:%M:%S'`
start_seconds=$(date --date="$starttime" +%s);
end_seconds=$(date --date="$endtime" +%s);
echo " 开始时间: $starttime "
echo " 结束时间: $endtime "
echo " 本次运行时间: "$((end_seconds-start_seconds))"s"
\ No newline at end of file
#!/bin/bash
cd `dirname $0`
BIN_DIR=`pwd`
DEPLOY_DIR=`pwd`
IP=$(echo $SSH_CONNECTION | awk '{print $3}')
echo $IP
#
# $1 方法名 deploy 发布项目
# $2 项目目录
# $3 检查的url
#
function deploy() {
cd $2
sh -x ./restart.sh
COUNT=0
TIMES=0
if [ -n "$3" ]; then
while [ $COUNT -lt 1 ]; do
echo -e ".\c"
sleep 1
COUNT=`curl -v "$3" | grep "success" | wc -l`
if [ $COUNT -gt 0 ]; then
break
fi
let TIMES=TIMES+1
if [ $TIMES -gt 200 ]; then
exit 1
fi
done
fi
}
#
# $1 方法名 检查项目环境
# $2 项目目录
#
function check() {
return;
}
# $1 方法名 设置权重
# $2 虚拟主机组
# $3 weight 权重
#
function weight() {
echo "http://172.17.255.136:8084/api/deploy/slb/controlSLB?ipStrList=$IP&vGroupId=$2&weight=$3"
curl "http://172.17.255.136:8084/api/deploy/slb/controlSLB?ipStrList=$IP&vGroupId=$2&weight=$3"
exit 1
}
if [ $1 -z ]; then
$1 = "deploy"
fi
echo call $1
case $1 in
deploy)
deploy $*
;;
check)
check $*
;;
weight)
weight $*
;;
error)
exit 1
;;
*)
deploy "deploy" $*
esac
#!/bin/bash
cd `dirname $0`
BIN_DIR=`pwd`
DEPLOY_DIR=`pwd`
IP=$(echo $SSH_CONNECTION | awk '{print $3}')
echo $IP
#
# $1 方法名 deploy 发布项目
# $2 项目目录
# $3 检查的url
#
function deploy() {
echo deploy
sh -x $2/restart.sh
COUNT=0
TIMES=0
while [ $COUNT -lt 1 ]; do
echo -e ".\c"
sleep 1
COUNT=`curl -v "$3" | grep "success" | wc -l`
if [ $COUNT -gt 0 ]; then
break
fi
let TIMES=TIMES+1
if [ $TIMES -gt 200 ]; then
exit 1
fi
done
}
#
# $1 方法名 restart 重启项目
# $2 项目目录
# $3 检查的url
#
function restart() {
echo restart
cd $2
sh -x $2/restart.sh
}
#
# $1 方法名 检查项目运行状态
# $2 url
# $3 keyword
#
function check() {
keyword=$3
COUNT=0
TIMES=0
if [ $keyword -z ]; then
keyword="success"
fi
while [ $COUNT -lt 1 ]; do
echo -e ".\c"
sleep 1
COUNT=`curl -v "$2" | grep $keyword | wc -l`
if [ $COUNT -gt 0 ]; then
break
fi
let TIMES=TIMES+1
if [ $TIMES -gt 200 ]; then
exit 1
fi
done
}
# $1 方法名 设置权重
# $2 虚拟主机组
# $3 weight 权重
#
function weight() {
echo "http://172.17.255.136:8084/api/deploy/slb/controlSLB?ipStrList=$IP&vGroupId=$2&weight=$3"
curl "http://172.17.255.136:8084/api/deploy/slb/controlSLB?ipStrList=$IP&vGroupId=$2&weight=$3"
}
# if [ "$1" -z ]; then
# $1 = "deploy"
# fi
echo call $1
case $1 in
deploy)
deploy $*
;;
check)
check $*
;;
weight)
weight $*
;;
restart)
restart $*
;;
error)
exit 1
;;
*)
deploy "deploy" $*
esac
#!/bin/bash
# redis ip
db_ip=127.0.0.1
# redis 端口
db_port=6379
# redis 密码
password=
# 第一次游标
cursor=0
# 每次迭代的数量
cnt=100
# 下一次游标
new_cursor=0
redis-cli -h $db_ip -p $db_port scan $cursor count $cnt > scan_tmp_result
new_cursor=`sed -n '1p' scan_tmp_result`
sed -n '2,$p' scan_tmp_result > scan_result
cat scan_result |while read line
do
ttl_result=`redis-cli -h $db_ip -p $db_port ttl $line` # 获取 key 过期时间
if [[ $ttl_result == -1 ]];then # 判断过期时间,-1 是不过期
echo $line >> no_ttl.log # 追加到指定文件
fi
done
while [[ $cursor != $new_cursor ]]
do
redis-cli -h $db_ip -p $db_port scan $new_cursor count $cnt > scan_tmp_result
new_cursor=`sed -n '1p' scan_tmp_result`
sed -n '2,$p' scan_tmp_result > scan_result
cat scan_result |while read line
do
ttl_result=`redis-cli -h $db_ip -p $db_port ttl $line`
if [[ $ttl_result == -1 ]];then
echo $line >> no_ttl.log
fi
done
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment