123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #!/usr/bin/env bash
- # 发布测试服务到测试机器
- # 机器: 192.168.60.201
- # 账号: gaoyagang 互信已添加
- user="gt"
- target="47.96.12.136"
- # 编译
- 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
- echo "start upload ${1}.yaml"
- rsync -av ./app/cmd/${1}/etc/${1}.test.yaml ${user}@${target}:/home/${user}/etc/${1}.yaml
- echo "remove ${1}"
- rm -f ./${1}
- }
- # 清理中间资源
- clear () {
- rm -rf ${1}
- }
- # 重启服务
- restart () {
- echo "restart ${1} and wait 2 seconds..."
- sleep 2
- ssh ${user}@${target} sudo /usr/local/bin/supervisorctl restart ${1}
- }
- deploy () {
- build $1;
- upload $1;
- restart $1;
- }
- deploy $1
|