#!/bin/bash
#开始时间"2016-03-17 20:00:00"
################################################################
# 帮助
if [ $# != 2 ] ; then
echo "脚本事例:./createdata.sh 活动起始时间 活动每一轮的时间长(s)"
echo "脚本事例:./createdata.sh "2016-03-17 20:00:00" 120"
exit 1;
fi
#################################################################
#起始时间, 轮次间隔
BEGIN=$1
jiange=$2
echo $1
################################################################
#时间处理
#将时间转换成数值
a=`date --date="$1" +%s`
echo $a
#识别是第几周
function IsPart
{
if (($1 < 49));then return 1; fi
if (($1 < 98));then return 2; fi
if (($1 < 147));then return 3;fi
if (($1 < 196));then return 4;fi
return 5;
}
#识别第几天
function IsExtra
{
if (($1 < 25));then return 1; fi
if (($1 < 49));then return 2; fi
if (($1 == 49));then return 0; fi
if (($1 < 74));then return 3; fi
if (($1 < 98));then return 4; fi
if (($1 == 98));then return 0; fi
if (($1 < 123));then return 5; fi
if (($1 < 147));then return 6; fi
if (($1 == 147));then return 0; fi
if (($1 < 172));then return 7; fi
if (($1 < 196));then return 8; fi
return 0;
}
#识别状态
function IsNotify
{
if (($1 < 49));then return 1; fi
if (($1 == 49));then return 3; fi
if (($1 < 98));then return 1; fi
if (($1 == 98));then return 3; fi
if (($1 < 147));then return 1; fi
if (($1 == 147));then return 3; fi
if (($1 < 196));then return 1; fi
return 2;
}
######################################################################
#生成数据库语句
#清理数据库时间
sudo rm -rf toutiaotime.sql
echo "delete from \`_ActivityRoundTimeConfig\`;" >> toutiaotime.sql
s1="INSERT INTO \`_ActivityRoundTimeConfig\` VALUES (20160319, "
sum_begin=$1
sum=a
timesql_begin=$1
#所有轮次
for((i=1;i<=196;++i))
do
#时间相加然后转换成标准时间格式
sum=$[$sum+$2]
sumtime=`date -d "@"$sum"" "+%Y-%m-%d %H:%M:%S"`
echo $sumtime
#函数调用
IsPart $i
part1=$?
IsExtra $i
extra1=$?
IsNotify $i
notify=$?
# sql语句拼接,例:INSERT INTO `_ActivityRoundTimeConfig` VALUES (20160319, 1, '2016-1-28 14:06:26', '2016-1-28 14:09:26', 1, 0, 0);
output=${s1}${i}", '"${sum_begin}"', '"${sumtime}"', "${part1}", "${extra1}", "${notify}");"
sum_begin=$sumtime
echo $output >> toutiaotime.sql
done
################################
#插入_ActivityTimeConfig表数据
echo "delete from \`_ActivityTimeConfig\`;" >> toutiaotime.sql
timesql="INSERT INTO \`_ActivityTimeConfig\` VALUES (20160319, 'auto_created', 20160319, 1, '"${timesql_begin}"', '"${sumtime}"', 0);"
echo $timesql >> toutiaotime.sql
################################################################################################
#将数据导入到数据库
sudo mysql -h******** -P**** -u***** -p***** activity < ./toutiaotime.sql
###################################################################################################
#清理重启voteserver
#调用进程创建voteserver配置文件
sudo ./genconfig "${timesql_begin}" "$2"
#关闭voteserver进程
CLOSE_VOTESERVER=`ps -ef | grep "VoteServer" | grep -Ev "grep|tail|less|update" | awk -F ' ' '{print $2}'`
sudo kill -9 $CLOSE_VOTESERVER
#删除历史文件
sudo rm -rf /data/voteserver/*
#删除配置文件
sudo rm -rf /data/services/voteserver/conf/vote.ini
#拷贝配置文件到指定位置
sudo cp ./vote.ini /data/services/voteserver/conf/
#rm -rf ./vote.ini
#运行voteserver
cd /data/services/voteserver/bin
sudo ./VoteServer &
echo "voteserver running..."
###############################################################################################
#重启进程
REAL_EXE="music_actNode_m"
#杀死旧的进程
echo "killing old process..."
OLDEXEPIDS=$( ps -ef | grep "music_actNode_m" | grep -Ev "grep|tail|less|update" | awk -F ' ' '{print $2}')
if ! [ "$OLDEXEPIDS" = "" ]
then
for p in $OLDEXEPIDS
do
if (($p != 14327))&&(($p != 26193));then
sudo kill $p
fi
done
fi
echo "check..."
sleep 2
maxsum=1
while (( $maxsum < 3 ))
do
NOTKILLPIDS=$( ps -ef | grep "music_actNode_m" | grep -Ev "grep|tail|less|update" | awk -F ' ' '{print $2}')
if [ "$NOTKILLPIDS" = "" ]
then
break;
fi
for p in $NOTKILLPIDS
do
if (($p != 14327))&&(($p != 26193));then
sudo kill -9 $p
fi
done
((maxsum++))
done
cd /data/services/music_actNode_m_shanghai-t378017.0308.r/bin
for(( i=1; i<=4; i++))
do
sudo ./music_actNode_m.t378017.0308.r &
done
#获取当前时间
#beginDATE=$(date +%Y-%m-%d%t%H:%M:%S)
#beginDateTow=$(date +%Y-%m-%d%t%H:%M:%S)
#echo $beginDATE
#开始时间"2016-03-17 20:00:00"
################################################################
# 帮助
if [ $# != 2 ] ; then
echo "脚本事例:./createdata.sh 活动起始时间 活动每一轮的时间长(s)"
echo "脚本事例:./createdata.sh "2016-03-17 20:00:00" 120"
exit 1;
fi
#################################################################
#起始时间, 轮次间隔
BEGIN=$1
jiange=$2
echo $1
################################################################
#时间处理
#将时间转换成数值
a=`date --date="$1" +%s`
echo $a
#识别是第几周
function IsPart
{
if (($1 < 49));then return 1; fi
if (($1 < 98));then return 2; fi
if (($1 < 147));then return 3;fi
if (($1 < 196));then return 4;fi
return 5;
}
#识别第几天
function IsExtra
{
if (($1 < 25));then return 1; fi
if (($1 < 49));then return 2; fi
if (($1 == 49));then return 0; fi
if (($1 < 74));then return 3; fi
if (($1 < 98));then return 4; fi
if (($1 == 98));then return 0; fi
if (($1 < 123));then return 5; fi
if (($1 < 147));then return 6; fi
if (($1 == 147));then return 0; fi
if (($1 < 172));then return 7; fi
if (($1 < 196));then return 8; fi
return 0;
}
#识别状态
function IsNotify
{
if (($1 < 49));then return 1; fi
if (($1 == 49));then return 3; fi
if (($1 < 98));then return 1; fi
if (($1 == 98));then return 3; fi
if (($1 < 147));then return 1; fi
if (($1 == 147));then return 3; fi
if (($1 < 196));then return 1; fi
return 2;
}
######################################################################
#生成数据库语句
#清理数据库时间
sudo rm -rf toutiaotime.sql
echo "delete from \`_ActivityRoundTimeConfig\`;" >> toutiaotime.sql
s1="INSERT INTO \`_ActivityRoundTimeConfig\` VALUES (20160319, "
sum_begin=$1
sum=a
timesql_begin=$1
#所有轮次
for((i=1;i<=196;++i))
do
#时间相加然后转换成标准时间格式
sum=$[$sum+$2]
sumtime=`date -d "@"$sum"" "+%Y-%m-%d %H:%M:%S"`
echo $sumtime
#函数调用
IsPart $i
part1=$?
IsExtra $i
extra1=$?
IsNotify $i
notify=$?
# sql语句拼接,例:INSERT INTO `_ActivityRoundTimeConfig` VALUES (20160319, 1, '2016-1-28 14:06:26', '2016-1-28 14:09:26', 1, 0, 0);
output=${s1}${i}", '"${sum_begin}"', '"${sumtime}"', "${part1}", "${extra1}", "${notify}");"
sum_begin=$sumtime
echo $output >> toutiaotime.sql
done
################################
#插入_ActivityTimeConfig表数据
echo "delete from \`_ActivityTimeConfig\`;" >> toutiaotime.sql
timesql="INSERT INTO \`_ActivityTimeConfig\` VALUES (20160319, 'auto_created', 20160319, 1, '"${timesql_begin}"', '"${sumtime}"', 0);"
echo $timesql >> toutiaotime.sql
################################################################################################
#将数据导入到数据库
sudo mysql -h******** -P**** -u***** -p***** activity < ./toutiaotime.sql
###################################################################################################
#清理重启voteserver
#调用进程创建voteserver配置文件
sudo ./genconfig "${timesql_begin}" "$2"
#关闭voteserver进程
CLOSE_VOTESERVER=`ps -ef | grep "VoteServer" | grep -Ev "grep|tail|less|update" | awk -F ' ' '{print $2}'`
sudo kill -9 $CLOSE_VOTESERVER
#删除历史文件
sudo rm -rf /data/voteserver/*
#删除配置文件
sudo rm -rf /data/services/voteserver/conf/vote.ini
#拷贝配置文件到指定位置
sudo cp ./vote.ini /data/services/voteserver/conf/
#rm -rf ./vote.ini
#运行voteserver
cd /data/services/voteserver/bin
sudo ./VoteServer &
echo "voteserver running..."
###############################################################################################
#重启进程
REAL_EXE="music_actNode_m"
#杀死旧的进程
echo "killing old process..."
OLDEXEPIDS=$( ps -ef | grep "music_actNode_m" | grep -Ev "grep|tail|less|update" | awk -F ' ' '{print $2}')
if ! [ "$OLDEXEPIDS" = "" ]
then
for p in $OLDEXEPIDS
do
if (($p != 14327))&&(($p != 26193));then
sudo kill $p
fi
done
fi
echo "check..."
sleep 2
maxsum=1
while (( $maxsum < 3 ))
do
NOTKILLPIDS=$( ps -ef | grep "music_actNode_m" | grep -Ev "grep|tail|less|update" | awk -F ' ' '{print $2}')
if [ "$NOTKILLPIDS" = "" ]
then
break;
fi
for p in $NOTKILLPIDS
do
if (($p != 14327))&&(($p != 26193));then
sudo kill -9 $p
fi
done
((maxsum++))
done
cd /data/services/music_actNode_m_shanghai-t378017.0308.r/bin
for(( i=1; i<=4; i++))
do
sudo ./music_actNode_m.t378017.0308.r &
done
#获取当前时间
#beginDATE=$(date +%Y-%m-%d%t%H:%M:%S)
#beginDateTow=$(date +%Y-%m-%d%t%H:%M:%S)
#echo $beginDATE