Commit a000b07d8df1a30ec9865469de6ba692e69455df
1 parent
a8d275e0
Exists in
master
and in
1 other branch
faet: sh
Showing
5 changed files
with
156 additions
and
1 deletions
Show diff stats
go.mod
| @@ -0,0 +1,91 @@ | @@ -0,0 +1,91 @@ | ||
| 1 | + # !/bin/bash | ||
| 2 | +if [ ! -n "$1" ]; then | ||
| 3 | + echo "params error" | ||
| 4 | + exit 1 | ||
| 5 | +elif [ $1 != "start" -a $1 != "restart" -a $1 != "stop" ]; then | ||
| 6 | + echo "please input start|stop|restart" | ||
| 7 | + exit 2 | ||
| 8 | +fi | ||
| 9 | +env=pre | ||
| 10 | +nowdate=`date +"%Y%m%d%H%M"` | ||
| 11 | +execdir=/home/exec/merge/api/$nowdate | ||
| 12 | +codedir=/home/code/go/merge/src/api-qixi | ||
| 13 | +execname=api-qixi | ||
| 14 | +execnewname=API_QIXI_$nowdate | ||
| 15 | +ports=(60040) | ||
| 16 | +codeport=80 | ||
| 17 | +echo "${execname} script is begin...." | ||
| 18 | +sleep 1s | ||
| 19 | +# cd $codedir | ||
| 20 | +for i in ${ports[@]}; | ||
| 21 | +do | ||
| 22 | + if [ $1 == "start" ];then | ||
| 23 | + userport=`netstat -antp | grep ":${i}"` | ||
| 24 | + if [ ${#userport} -gt 3 ]; then | ||
| 25 | + echo "port ${i} is busy..." | ||
| 26 | + break | ||
| 27 | + fi | ||
| 28 | + fi | ||
| 29 | + if [ $1 == "start" -o $1 == "restart" ];then | ||
| 30 | + #copy new main | ||
| 31 | + cd $codedir | ||
| 32 | + if [ $? -ne 0 ]; then | ||
| 33 | + echo "cd ${codedir} error,port:${i}" | ||
| 34 | + break | ||
| 35 | + fi | ||
| 36 | + execdirpath=$execdir/$i | ||
| 37 | + if [ ! -d $execdirpath ]; then | ||
| 38 | + mkdir -p $execdirpath | ||
| 39 | + if [ $? -ne 0 ]; then | ||
| 40 | + echo "mkdir ${execdirpath} error" | ||
| 41 | + break | ||
| 42 | + fi | ||
| 43 | + cp $execname $execdirpath/${execnewname}_${i} | ||
| 44 | + cp -r conf $execdirpath/ | ||
| 45 | + cp -r ../conf $execdirpath/../ | ||
| 46 | + sed -i "s#httpport = ${codeport}#httpport = ${i}#g" $execdirpath/conf/${env}.conf | ||
| 47 | + if [ $? -ne 0 ]; then | ||
| 48 | + echo "sed httpport ${codeport},i:${i} error" | ||
| 49 | + break | ||
| 50 | + fi | ||
| 51 | + sed -i "s#appname = ${execname}#appname = ${execnewname}_${i}#g" $execdirpath/conf/${env}.conf | ||
| 52 | + if [ $? -ne 0 ]; then | ||
| 53 | + echo "sed appname ${execname},i:${i} error" | ||
| 54 | + break | ||
| 55 | + fi | ||
| 56 | + rm -rf app.conf | ||
| 57 | + if [ $? -ne 0 ]; then | ||
| 58 | + echo "delete app.conf i:${i} error" | ||
| 59 | + break | ||
| 60 | + fi | ||
| 61 | + echo "include \"${env}.conf\"" > $execdirpath/conf/app.conf | ||
| 62 | + fi | ||
| 63 | + fi | ||
| 64 | + #kill old port main | ||
| 65 | + if [ $1 == "stop" -o $1 == "restart" ];then | ||
| 66 | + userport=`netstat -antp | grep ":${i}"` | ||
| 67 | + if [ ${#userport} -gt 3 ]; then | ||
| 68 | + kill -9 $(netstat -nlp | grep :${i} | awk '{print $7}' | awk -F"/" '{ print $1 }') | ||
| 69 | + if [ $? -ne 0 ]; then | ||
| 70 | + echo "kill port ${i} success" | ||
| 71 | + break | ||
| 72 | + else | ||
| 73 | + echo "kill port ${i} success" | ||
| 74 | + fi | ||
| 75 | + fi | ||
| 76 | + fi | ||
| 77 | + #start new maini | ||
| 78 | + if [ $1 == "start" -o $1 == "restart" ];then | ||
| 79 | + cd $execdirpath/ | ||
| 80 | + nohup ./${execnewname}_${i} >/dev/null 2>$execdirpath/error.log 2>&1 & | ||
| 81 | + if [ $? -ne 0 ]; then | ||
| 82 | + echo "${execnewname}_${i} start error " | ||
| 83 | + break | ||
| 84 | + else | ||
| 85 | + echo "${execnewname}_${i} start ok " | ||
| 86 | + fi | ||
| 87 | + fi | ||
| 88 | + sleep 5s | ||
| 89 | +done | ||
| 90 | +echo "${execname} script is end...." | ||
| 91 | +exit 0 |
| @@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
| 1 | +# !/bin/bash | ||
| 2 | +if [ ! -n "$1" ]; then | ||
| 3 | + echo "params error" | ||
| 4 | + exit 1 | ||
| 5 | +elif [ $1 != "api-qixi" ]; then | ||
| 6 | + echo "please input api-qixi" | ||
| 7 | + exit 2 | ||
| 8 | +fi | ||
| 9 | +if [ ! -n "$2" ]; then | ||
| 10 | + echo "params error" | ||
| 11 | + exit 1 | ||
| 12 | +elif [ $2 != "start" -a $2 != "restart" -a $2 != "stop" ]; then | ||
| 13 | + echo "please input start|stop|restart" | ||
| 14 | + exit 2 | ||
| 15 | +fi | ||
| 16 | + | ||
| 17 | + | ||
| 18 | +sh /sh/qixi/git.sh | ||
| 19 | +if [ $? -ne 0 ];then | ||
| 20 | + exit 3 | ||
| 21 | +fi | ||
| 22 | + | ||
| 23 | +binname=$1 | ||
| 24 | +sh /sh/qixi/build.sh ${binname} | ||
| 25 | +if [ $? -ne 0 ];then | ||
| 26 | + exit 1 | ||
| 27 | +fi | ||
| 28 | + | ||
| 29 | + | ||
| 30 | +sleep 1s | ||
| 31 | +sh /sh/qixi/${1}.sh ${2} | ||
| 32 | +if [ $? -ne 0 ];then | ||
| 33 | + exit 1 | ||
| 34 | +fi |
| @@ -0,0 +1,17 @@ | @@ -0,0 +1,17 @@ | ||
| 1 | +# !/bin/bash | ||
| 2 | +export GOPATH="/home/www/gopath:/home/code/go/apigame" | ||
| 3 | + | ||
| 4 | +codedir=/home/code/go/apigame/src | ||
| 5 | + | ||
| 6 | +cd ${codedir} | ||
| 7 | +if [ $? -ne 0 ];then | ||
| 8 | + echo "cd ${codedir} error" | ||
| 9 | + exit 3 | ||
| 10 | +fi | ||
| 11 | +go build | ||
| 12 | +if [ $? -ne 0 ]; then | ||
| 13 | + echo "go build $codedir error" | ||
| 14 | + exit 3 | ||
| 15 | +fi | ||
| 16 | +echo "go build $codedir is ok...." | ||
| 17 | +exit 0 |