test.sh 824 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env bash
  2. # 发布测试服务到测试机器
  3. # 机器: 192.168.60.201
  4. # 账号: gaoyagang 互信已添加
  5. user="gt"
  6. target="192.168.60.201"
  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. }
  26. # 清理中间资源
  27. clear () {
  28. rm -rf ${1}
  29. }
  30. # 重启服务
  31. restart () {
  32. echo "restart ${1} and wait 2 seconds..."
  33. sleep 2
  34. ssh ${user}@${target} supervisorctl restart ${1}
  35. }
  36. deploy () {
  37. build $1;
  38. upload $1;
  39. restart $1;
  40. }
  41. deploy 'organization'