Commit 3f4646e0ac6f1704d3155a25586423ca527906c7

Authored by 王家文
1 parent 81a9e55a
Exists in master and in 1 other branch dev-wjw

build📦️:脚本

conf/prod.conf
1 1 appname = api-game
2   -httpport = 39080
  2 +httpport = 9051
3 3 runmode = prod
4 4 autorender = false
5 5 copyrequestbody = true
... ...
sh/prod/apigame.sh 0 → 100644
... ... @@ -0,0 +1,106 @@
  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 +
  10 +
  11 +env=prod
  12 +nowdate=`date +"%Y%m%d%H%M"`
  13 +execdir=/goexec/exec/apigame/api/$nowdate
  14 +codedir=/code/apigame/src
  15 +execname=apigame
  16 +execnewname=APIGAME_$nowdate
  17 +ports=(9051 9052 9053 9054 9055)
  18 +codeport=80
  19 +
  20 +
  21 +echo "${execname} script is begin...."
  22 +sleep 1s
  23 +
  24 +# cd $codedir
  25 +for i in ${ports[@]};
  26 +do
  27 +
  28 + if [ $1 == "start" ];then
  29 + userport=`netstat -antp | grep ":${i}"`
  30 + if [ ${#userport} -gt 3 ]; then
  31 + echo "port ${i} is busy..."
  32 + break
  33 + fi
  34 + fi
  35 +
  36 + if [ $1 == "start" -o $1 == "restart" ];then
  37 + #copy new main
  38 + cd $codedir
  39 + if [ $? -ne 0 ]; then
  40 + echo "cd ${codedir} error,port:${i}"
  41 + break
  42 + fi
  43 + execdirpath=$execdir/$i
  44 + if [ ! -d $execdirpath ]; then
  45 + mkdir -p $execdirpath
  46 + if [ $? -ne 0 ]; then
  47 + echo "mkdir ${execdirpath} error"
  48 + break
  49 + fi
  50 + cp $execname $execdirpath/${execnewname}_${i}
  51 + cp -r conf $execdirpath/
  52 +
  53 + #cp -r ../conf $execdirpath/../
  54 +
  55 + sed -i "s#httpport = ${codeport}#httpport = ${i}#g" $execdirpath/conf/${env}.conf
  56 + if [ $? -ne 0 ]; then
  57 + echo "sed httpport ${codeport},i:${i} error"
  58 + break
  59 + fi
  60 + sed -i "s#appname = ${execname}#appname = ${execnewname}_${i}#g" $execdirpath/conf/${env}.conf
  61 + if [ $? -ne 0 ]; then
  62 + echo "sed appname ${execname},i:${i} error"
  63 + break
  64 + fi
  65 + rm -rf app.conf
  66 + if [ $? -ne 0 ]; then
  67 + echo "delete app.conf i:${i} error"
  68 + break
  69 + fi
  70 + echo "include \"${env}.conf\"" > $execdirpath/conf/app.conf
  71 + fi
  72 + fi
  73 +
  74 + #kill old port main
  75 + if [ $1 == "stop" -o $1 == "restart" ];then
  76 + userport=`netstat -antp | grep ":${i}"`
  77 + if [ ${#userport} -gt 3 ]; then
  78 + kill -9 $(netstat -nlp | grep :${i} | awk '{print $7}' | awk -F"/" '{ print $1 }')
  79 + if [ $? -ne 0 ]; then
  80 + echo "kill port ${i} success"
  81 + break
  82 + else
  83 + echo "kill port ${i} success"
  84 + fi
  85 + fi
  86 + fi
  87 +
  88 + #start new maini
  89 + if [ $1 == "start" -o $1 == "restart" ];then
  90 + cd $execdirpath/
  91 + nohup ./${execnewname}_${i} >/dev/null 2>$execdirpath/error.log 2>&1 &
  92 + if [ $? -ne 0 ]; then
  93 + echo "${execnewname}_${i} start error "
  94 + break
  95 + else
  96 + echo "${execnewname}_${i} start ok "
  97 + fi
  98 + fi
  99 + sleep 5s
  100 +
  101 +done
  102 +
  103 +
  104 +
  105 +echo "${execname} script is end...."
  106 +exit 0
... ...
sh/prod/auto.sh 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +# !/bin/bash
  2 +binname=$1
  3 +
  4 +sh /sh/apigame/build.sh apigame
  5 +if [ $? -ne 0 ];then
  6 + exit 1
  7 +fi
  8 +
  9 +sleep 1s
  10 +
  11 +sh /sh/apigame/apigame.sh ${1}
  12 +if [ $? -ne 0 ];then
  13 + exit 1
  14 +fi
... ...
sh/prod/build.sh 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +# !/bin/bash
  2 +
  3 +
  4 +export GOPATH="/code/go:/code/apigame"
  5 +
  6 +codedir=/code/apigame/src
  7 +cd ${codedir}
  8 +if [ $? -ne 0 ];then
  9 + echo "cd ${codedir} error"
  10 + exit 3
  11 +fi
  12 +go build
  13 +if [ $? -ne 0 ]; then
  14 + echo "go build $codedir error"
  15 + exit 3
  16 +fi
  17 +
  18 +echo "go build $codedir is ok...."
  19 +exit 0
... ...