-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathdeploy
executable file
·97 lines (78 loc) · 2.43 KB
/
deploy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
set -uo pipefail
#==============================================================#
# File : deploy
# Mtime : 2019-03-12
# Desc : Deploy sql/bash change to remote server
# Path : node/<id>/deploy
# Author : Vonng([email protected])
#==============================================================#
# module info
__MODULE_DEPLOY="deploy"
PROG_DIR="$(cd $(dirname $0) && pwd)"
PROG_NAME="$(basename $0)"
NODE_NAME=$(basename ${PROG_DIR})
NODE_NAME=${NODE_NAME%%.*}
function deploy() {
local change_file=${1}
local node=${2-${NODE_NAME}}
if [[ ! -f ${change_file} ]]; then
echo "error: file ${change_file} not exists"
return 2
fi
# copy change file to remote /tmp
local change_filename=$(basename ${change_file})
scp ${change_file} "${node}:/tmp/${change_filename}"
if [[ $? != 0 ]]; then
echo "error: copy file ${change_file} to ${node}:/tmp failed"
return 3
fi
# deploy it
ssh ${node} "sudo -iu postgres /pg/bin/deploy.sh /tmp/${change_filename}"
if [[ $? != 0 ]]; then
echo "error: deploy ${change_file} failed"
return 4
fi
echo "deploy change ${change_file} to ${node}"
return 0
}
# deploy all changes in dir change
function deploy_all_changes(){
local change_list=$(ls change | sort -n)
for entry in ${change_list}
do
echo "deploying ${entry}"
deploy change/${entry}
done
}
#==============================================================#
# Main #
#==============================================================#
function main(){
cd ${PROG_DIR}
if [[ $1 == 'init' ]]; then
# this will deploy all changes in the change directory
# ordered by ls | sort -n
deploy_all_changes
else
deploy $@
fi
cd -
return $?
}
#==============================================================#
# Main #
#==============================================================#
# Args:
# $1 action: download | install | launch (install by default)
#
# Code:
# 0 ok
# 1 insufficient privilege
# 2 download consul failed
# 3 decompress consul failed
# 4 create user consul failed
# 5 get local IP failed
# 6 launch consul.service failed
#==============================================================#
main $@