-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstartalkdockerctl
More file actions
executable file
·145 lines (136 loc) · 5.17 KB
/
startalkdockerctl
File metadata and controls
executable file
·145 lines (136 loc) · 5.17 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
set -e
help(){
echo "
Usage: startalkdockerctl <options>
<options>:
init set config
reset delte all volume and logs
start docker compose all modules in background way
help show help info
"
}
get_os() {
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;;
*) machine="UNKNOWN:${unameOut}"
esac
if [ ${machine} = "MinGw" ]
then
echo "WARNING: This script may malfunction besides of Linux and Darwin..."
fi
}
find_ip() {
OLD_IP=`grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' ${PWD}/compose/conf/im_http_service/classes/nav.json|head -n 1`
if [[ -z $OLD_IP ]];
then
OLD_IP="ip"
fi
}
set_ip() {
get_os
find_ip
mkdir -p ${PWD}/.data_backup/ && cp -r ${PWD}/compose/conf/ ${PWD}/.data_backup/
if [ ${machine} == "Linux" ]
then
ip a
ALL_IP=`ip -o addr show up primary scope global | while read -r num dev fam addr rest; do echo ${addr%/*}; done|head -n 1`
elif [ ${machine} == "Mac" ]
then
ifconfig
ALL_IP=`ipconfig getifaddr en0`
elif [ ${machine} == "MinGw" ]
then
ipconfig
ALL_IP=`ipconfig.exe | grep -im1 'IPv4 Address' | cut -d ':' -f2 | xargs `
fi
if [ -z ${ALL_IP} ]
then
read -r -p "******* No IP found, please input your IP : " MY_IP
else
read -r -p "******* Is $ALL_IP the ip you gonna use? [y/N] : " response
case "$response" in
[yY][eE][sS]|[yY][\e])
MY_IP=${ALL_IP}
echo $MY_IP
;;
"")
MY_IP=${ALL_IP}
echo $MY_IP
;;
*)
read -r -p "******* Please input your IP : " MY_IP
;;
esac
fi
SED_IP=$(echo "$OLD_IP" | sed 's/\./\\\./g')
if [ ${machine} == "Linux" ]
then
#redis
#sed -i"s/host: \"$SED_IP\" \#IP_TOBECHANGE/\"$MY_IP\" \#IP_TOBECHANGE/g" ${PWD}/compose/conf/ejabberd/ejabberd.yml.qunar
#sql
#sed -i "s/sql_server: \"$SED_IP\"/sql_server: \"$MY_IP\"/g" ${PWD}/compose/conf/ejabberd/ejabberd.yml.qunar
sed -i "s/$SED_IP/$MY_IP/g" ${PWD}/compose/conf/im_http_service/classes/*.json
#sed -i "s/$SED_IP/$MY_IP/g" ${PWD}/compose/conf/im_http_service/classes/jdbc.properties
#sed -i "s/$SED_IP/$MY_IP/g" ${PWD}/compose/conf/im_http_service/classes/redis.properties
#sed -i "s/$SED_IP/$MY_IP/g" ${PWD}/compose/conf/push_service/classes/app.properties
#sed -i "s/$SED_IP/$MY_IP/g" ${PWD}/compose/conf/push_service/classes/jdbc.properties
#sed -i "s/$SED_IP/$MY_IP/g" ${PWD}/compose/conf/push_service/classes/redis.properties
#sed -i "s/$SED_IP/$MY_IP/g" ${PWD}/compose/conf//qfproxy/classes/qfproxy.properties
#sed -i "s/$SED_IP/$MY_IP/g" ${PWD}/java/im_http_service/conf/classes/*.json
#sed -i "s/$SED_IP/$MY_IP/g" ${PWD}/java/im_http_service/classes/jdbc.properties
#sed -i "s/$SED_IP/$MY_IP/g" ${PWD}/java/im_http_service/classes/redis.properties
#sed -i "s/$SED_IP/$MY_IP/g" ${PWD}/java/qfproxy/conf/classes/qfproxy.properties
#sed -i "s/http:\/\/$SED_IP/http:\/\/$MY_IP/g" ${PWD}/compose/conf/push_service/classes/app.properties
#sed -i "s/$SED_IP/$MY_IP/g" ${PWD}/java/push_service/classes/jdbc.properties
#sed -i "s/$SED_IP/$MY_IP/g" ${PWD}/java/push_service/classes/redis.properties
elif [ ${machine} == "Mac" ]
then
#sql
#sed -i '' "s/host: \"$SED_IP\" \#IP_TOBECHANGE/sql_server: \"$MY_IP\" \#IP_TOBECHANGE/g" ${PWD}/compose/conf/ejabberd/ejabberd.yml.qunar
#redis
#sed -i '' "s/sql_server: \"$SED_IP\"/sql_server: \"$MY_IP\"/g" ${PWD}/compose/conf/ejabberd/ejabberd.yml.qunar
sed -i '' "s/$SED_IP/$MY_IP/g" ${PWD}/compose/conf/im_http_service/classes/*.json
#sed -i '' "s/$SED_IP/$MY_IP/g" ${PWD}/compose/conf/im_http_service/classes/jdbc.properties
#sed -i '' "s/$SED_IP/$MY_IP/g" ${PWD}/compose/conf/im_http_service/classes/redis.properties
#sed -i '' "s/http:\/\/$SED_IP/http:\/\/$MY_IP/g" ${PWD}/compose/conf/push_service/classes/app.properties
#sed -i '' "s/$SED_IP/$MY_IP/g" ${PWD}/compose/conf/push_service/classes/jdbc.properties
#sed -i '' "s/$SED_IP/$MY_IP/g" ${PWD}/compose/conf/push_service/classes/redis.properties
#sed -i '' "s/$SED_IP/$MY_IP/g" ${PWD}/compose/conf//qfproxy/classes/qfproxy.properties
#sed -i '' "s/$SED_IP/$MY_IP/g" ${PWD}/java/im_http_service/conf/classes/*.json
#sed -i '' "s/$SED_IP/$MY_IP/g" ${PWD}/java/qfproxy/conf/classes/qfproxy.properties
#sed -i '' "s/$SED_IP/$MY_IP/g" ${PWD}/java/push_service/conf/classes/app.properties
elif [ ${machine} == "MinGw" ]
then
#ipconfig
#ALL_IP=`ipconfig.exe | grep -im1 'IPv4 Address' | cut -d ':' -f2`
sed -i "s/$SED_IP/$MY_IP/g" ${PWD}/compose/conf/im_http_service/classes/*.json
else
echo "Please modify ${PWD}/compose/conf/im_http_service/classes/*.json to your IP manually"
fi
}
go_path() {
BASEDIR=$(dirname $0)
cd ${BASEDIR}
}
reset_all() {
go_path
set_ip
rm -rf ${PWD}/compose/volume/data/pg
find ${PWD}/compose/volume/log/ -type f|xargs -I {} rm -f {}
}
start() {
go_path
cd compose && docker-compose up -d
}
case $1 in
init) go_path; set_ip;;
reset) reset_all;;
start) start;;
help) help;;
*) help;;
esac