12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #!/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}
- if [ "${1}" == "datacenter" ]; then
- GOOS=linux GOARCH=amd64 go build -o ${1} app/cmd/api/${1}.go
- else
- GOOS=linux GOARCH=amd64 go build -o ${1} app/cmd/${1}/${1}.go
- fi
- # 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}.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
|