test.sh 1001 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env bash
  2. # 发布测试服务到测试机器
  3. # 机器: 192.168.60.201
  4. # 账号: gaoyagang 互信已添加
  5. user="gt"
  6. target="47.96.12.136"
  7. # 编译
  8. build () {
  9. echo ${1}
  10. echo "build for ${1}"
  11. rm -f ${1}
  12. GOOS=linux GOARCH=amd64 go build -o ${1} app/cmd/${1}/${1}.go
  13. # shellcheck disable=SC2181
  14. if [ "$?" != "0" ]; then
  15. exit $?
  16. fi
  17. }
  18. # 上传
  19. upload () {
  20. echo "start upload ${1}..."
  21. rsync -av ./${1} ${user}@${target}:/home/${user}/${1}
  22. if [ "$?" != "0" ]; then
  23. exit $?
  24. fi
  25. echo "start upload ${1}.yaml"
  26. rsync -av ./app/cmd/${1}/etc/${1}.test.yaml ${user}@${target}:/home/${user}/etc/${1}.yaml
  27. echo "remove ${1}"
  28. rm -f ./${1}
  29. }
  30. # 清理中间资源
  31. clear () {
  32. rm -rf ${1}
  33. }
  34. # 重启服务
  35. restart () {
  36. echo "restart ${1} and wait 2 seconds..."
  37. sleep 2
  38. ssh ${user}@${target} sudo /usr/local/bin/supervisorctl restart ${1}
  39. }
  40. deploy () {
  41. build $1;
  42. upload $1;
  43. restart $1;
  44. }
  45. deploy $1