-
Notifications
You must be signed in to change notification settings - Fork 470
/
run.sh
executable file
·95 lines (85 loc) · 2.38 KB
/
run.sh
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
#!/usr/bin/env bash
# Author : Lock
# Email: [email protected]
CONFIG_ENV=$1
IPADDR=$2
valid_ip () {
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
return $stat
}
if [ "${CONFIG_ENV}" = "dev" -o "${CONFIG_ENV}" = "prod" ]
then
echo "run ${CONFIG_ENV} env..."
else
echo 'Sorry, error! Please execute For example:'
echo ' sh run.sh dev 127.0.0.1'
echo ' sh run.sh prod x.x.x.x'
exit 1
fi
if ! valid_ip "${IPADDR}";then
echo "ip address error !!! please check '${IPADDR}' is ip address? "
exit 1
fi
echo "now env is:${CONFIG_ENV}"
if [ "${CONFIG_ENV}" == "dev" ]
then
DOCKER_IMAGE="lockgit/gochat:1.18"
elif [ "${CONFIG_ENV}" == "prod" ]
then
# You can use your own build docker image
DOCKER_IMAGE="lockgit/gochat:1.18"
fi
echo "nice, now set docker image is:${DOCKER_IMAGE}"
# docker run
if [ "${CONFIG_ENV}" == "dev" ]
then
sudo docker run \
--name gochat-${CONFIG_ENV} \
-h gochat-${CONFIG_ENV} \
-e TZ=Asia/Shanghai \
-e RUN_MODE=dev \
-e HOST_IP=${IPADDR} \
-e ETCD_DATA_DIR=/root/default.etcd \
-v `pwd`:/go/src/gochat \
-v `pwd`/docker/${CONFIG_ENV}/supervisord.d:/etc/supervisord.d \
-v `pwd`/docker/${CONFIG_ENV}/supervisord.conf:/etc/supervisord.conf \
-v `pwd`/docker/${CONFIG_ENV}/redis.conf:/root/redis.conf \
-d \
-p 8080:8080 \
-p 7070:7070 \
-p 7000:7000 \
-p 7001:7001 \
-p 7002:7002 \
${DOCKER_IMAGE} \
supervisord -n && docker exec gochat-${CONFIG_ENV} /bin/sh './reload.sh'
else
sudo docker run \
--name gochat-${CONFIG_ENV} \
-h gochat-${CONFIG_ENV} \
-e TZ=Asia/Shanghai \
-e RUN_MODE=prod \
-e HOST_IP=${IPADDR} \
-e ETCD_DATA_DIR=/root/default.etcd \
-v `pwd`:/go/src/gochat \
-v `pwd`/docker/${CONFIG_ENV}/supervisord.d:/etc/supervisord.d \
-v `pwd`/docker/${CONFIG_ENV}/supervisord.conf:/etc/supervisord.conf \
-v `pwd`/docker/${CONFIG_ENV}/redis.conf:/root/redis.conf \
-d \
-p 8080:8080 \
-p 7070:7070 \
-p 7000:7000 \
-p 7001:7001 \
-p 7002:7002 \
${DOCKER_IMAGE} \
supervisord -n && docker exec gochat-${CONFIG_ENV} /bin/sh './reload.sh'
fi