diff --git a/conf/prod.conf b/conf/prod.conf index d5ce190..de0669d 100644 --- a/conf/prod.conf +++ b/conf/prod.conf @@ -1,5 +1,5 @@ appname = api-game -httpport = 39080 +httpport = 9051 runmode = prod autorender = false copyrequestbody = true diff --git a/sh/prod/apigame.sh b/sh/prod/apigame.sh new file mode 100644 index 0000000..670b6e9 --- /dev/null +++ b/sh/prod/apigame.sh @@ -0,0 +1,106 @@ +# !/bin/bash +if [ ! -n "$1" ]; then + echo "params error" + exit 1 +elif [ $1 != "start" -a $1 != "restart" -a $1 != "stop" ]; then + echo "please input start|stop|restart" + exit 2 +fi + + +env=prod +nowdate=`date +"%Y%m%d%H%M"` +execdir=/goexec/exec/apigame/api/$nowdate +codedir=/code/apigame/src +execname=apigame +execnewname=APIGAME_$nowdate +ports=(9051 9052 9053 9054 9055) +codeport=80 + + +echo "${execname} script is begin...." +sleep 1s + +# cd $codedir +for i in ${ports[@]}; +do + + if [ $1 == "start" ];then + userport=`netstat -antp | grep ":${i}"` + if [ ${#userport} -gt 3 ]; then + echo "port ${i} is busy..." + break + fi + fi + + if [ $1 == "start" -o $1 == "restart" ];then + #copy new main + cd $codedir + if [ $? -ne 0 ]; then + echo "cd ${codedir} error,port:${i}" + break + fi + execdirpath=$execdir/$i + if [ ! -d $execdirpath ]; then + mkdir -p $execdirpath + if [ $? -ne 0 ]; then + echo "mkdir ${execdirpath} error" + break + fi + cp $execname $execdirpath/${execnewname}_${i} + cp -r conf $execdirpath/ + + #cp -r ../conf $execdirpath/../ + + sed -i "s#httpport = ${codeport}#httpport = ${i}#g" $execdirpath/conf/${env}.conf + if [ $? -ne 0 ]; then + echo "sed httpport ${codeport},i:${i} error" + break + fi + sed -i "s#appname = ${execname}#appname = ${execnewname}_${i}#g" $execdirpath/conf/${env}.conf + if [ $? -ne 0 ]; then + echo "sed appname ${execname},i:${i} error" + break + fi + rm -rf app.conf + if [ $? -ne 0 ]; then + echo "delete app.conf i:${i} error" + break + fi + echo "include \"${env}.conf\"" > $execdirpath/conf/app.conf + fi + fi + + #kill old port main + if [ $1 == "stop" -o $1 == "restart" ];then + userport=`netstat -antp | grep ":${i}"` + if [ ${#userport} -gt 3 ]; then + kill -9 $(netstat -nlp | grep :${i} | awk '{print $7}' | awk -F"/" '{ print $1 }') + if [ $? -ne 0 ]; then + echo "kill port ${i} success" + break + else + echo "kill port ${i} success" + fi + fi + fi + + #start new maini + if [ $1 == "start" -o $1 == "restart" ];then + cd $execdirpath/ + nohup ./${execnewname}_${i} >/dev/null 2>$execdirpath/error.log 2>&1 & + if [ $? -ne 0 ]; then + echo "${execnewname}_${i} start error " + break + else + echo "${execnewname}_${i} start ok " + fi + fi + sleep 5s + +done + + + +echo "${execname} script is end...." +exit 0 diff --git a/sh/prod/auto.sh b/sh/prod/auto.sh new file mode 100644 index 0000000..6d31bcd --- /dev/null +++ b/sh/prod/auto.sh @@ -0,0 +1,14 @@ +# !/bin/bash +binname=$1 + +sh /sh/apigame/build.sh apigame +if [ $? -ne 0 ];then + exit 1 +fi + +sleep 1s + +sh /sh/apigame/apigame.sh ${1} +if [ $? -ne 0 ];then + exit 1 +fi diff --git a/sh/prod/build.sh b/sh/prod/build.sh new file mode 100644 index 0000000..d9385b2 --- /dev/null +++ b/sh/prod/build.sh @@ -0,0 +1,19 @@ +# !/bin/bash + + +export GOPATH="/code/go:/code/apigame" + +codedir=/code/apigame/src +cd ${codedir} +if [ $? -ne 0 ];then + echo "cd ${codedir} error" + exit 3 +fi +go build +if [ $? -ne 0 ]; then + echo "go build $codedir error" + exit 3 +fi + +echo "go build $codedir is ok...." +exit 0 -- libgit2 0.21.0