#!/usr/bin/env bash # 发布测试服务到测试机器 # 机器: 192.168.60.201 # 账号: gaoyagang 互信已添加 user="gt" target="192.168.60.201" # 编译 build () { echo ${1} echo "build for ${1}" rm -f ${1} GOOS=linux GOARCH=amd64 go build -o ${1} app/cmd/${1}/${1}.go # shellcheck disable=SC2181 if [ "$?" != "0" ]; then exit $? fi } # 上传 upload () { echo "start upload ${1}..." rsync -av ./${1} ${user}@${target}:/home/${user}/${1} if [ "$?" != "0" ]; then exit $? fi } # 清理中间资源 clear () { rm -rf ${1} } # 重启服务 restart () { echo "restart ${1} and wait 2 seconds..." sleep 2 ssh ${user}@${target} supervisorctl restart ${1} } deploy () { build $1; upload $1; restart $1; } deploy 'organization'