-
Notifications
You must be signed in to change notification settings - Fork 29
/
docker-entrypoint.sh
executable file
·58 lines (49 loc) · 2.13 KB
/
docker-entrypoint.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
#!/bin/bash
ORANGE_CONF="/usr/local/orange/conf/orange.conf"
NGINX_CONF="/usr/local/orange/conf/nginx.conf"
# DNS resolve for nginx and add the internal DNS
INTERNAL_DNS=$(cat /etc/resolv.conf | grep nameserver)
sed -i "s/INTERNAL_DNS/${INTERNAL_DNS}/g" /etc/resolv.dnsmasq.conf
dnsmasq
# if command starts with option, init mysql
if [[ "X${ORANGE_DATABASE}" != "X" ]]; then
sed -i "s/\"host\": \"127.0.0.1\"/\"host\": \"${ORANGE_HOST}\"/g" ${ORANGE_CONF}
sed -i "s/\"port\": \"3306\"/\"port\": \"${ORANGE_PORT}\"/g" ${ORANGE_CONF}
sed -i "s/\"database\": \"orange\"/\"database\": \"${ORANGE_DATABASE}\"/g" ${ORANGE_CONF}
sed -i "s/\"user\": \"root\"/\"user\": \"${ORANGE_USER}\"/g" ${ORANGE_CONF}
sed -i "s/\"password\": \"\"/\"password\": \"${ORANGE_PWD}\"/g" ${ORANGE_CONF}
fi
# Waiting for a mysql fully started
netConnection() {
while true
do
TELNET_1=`echo "quit" | telnet $1 $2 | grep "Escape character is"`
if [ "$?" -ne 0 ]; then
echo "Reconnect after 5 seconds"
sleep 5
else
echo "Connected"
break;
fi
done
}
waitForDatabase() {
echo "Check database connection"
netConnection ${ORANGE_HOST} ${ORANGE_PORT}
echo "Database connected"
}
waitForDatabase
# Nginx conf modify
grep "www www" ${NGINX_CONF} > /dev/null
if [ $? -ne 0 ];then
sed -i "s/worker_processes 4;/user www www;\nworker_processes 4;\ndaemon off;/g" ${NGINX_CONF}
# Auto Init database for the first time
ORANGE_DATABASE_IP=`getent hosts ${ORANGE_HOST} | awk '{ print $1 }'`
orange store -t=mysql -d=${ORANGE_DATABASE} -hh=${ORANGE_DATABASE_IP} -pp=${ORANGE_PORT} -p=${ORANGE_PWD} -u=${ORANGE_USER} -o=init -f=/usr/local/orange/install/orange-v${ORANGE_VERSION}.sql
fi
sed -i "s/resolver 114.114.114.114;/resolver 127.0.0.1 ipv6=off;/g" ${NGINX_CONF}
sed -i "s/lua_package_path '..\/?.lua;\/usr\/local\/lor\/?.lua;;';/lua_package_path '\/usr\/local\/orange\/?.lua;\/usr\/local\/lor\/?.lua;;';/g" ${NGINX_CONF}
sed -i "s/listen 80;/listen 8888;/g" ${NGINX_CONF}
/usr/local/bin/orange start
# log to docker
tail -f /usr/local/orange/logs/access.log