-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfigure
executable file
·170 lines (135 loc) · 4.11 KB
/
configure
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
root=$(id -u)
if [ "$root" -ne 0 ]; then
echo must run as root
exit 1
fi
if [ "X$1" != "Xlocal" -a "X$1" != "Xtest" -a "X$1" != "Xsit" -a "X$1" != "Xuat" -a "X$1" != "Xprod" ]; then
echo "Please select env: local test sit uat prod"
echo "Such as ./configure sit"
exit
fi
TFS_SERVER=
REDIS_SERVER=
HTTP_SERVER=
HTTP_PORT=10502
CPU=
#cpu count
ip_command=`cat /proc/cpuinfo | grep processor | wc -l`
CPU=`echo $ip_command`
if [ $CPU -gt 16 ]; then
CPU=16
fi
echo "Checking for cpu count... $CPU"
if [ "X$CPU" == "X0" ]; then
echo "Error: can't get cpu count!"
exit
fi
network=`ls /sys/class/net | awk -F ' ' '{print $1}' | head -1`
#inet addr:ip
if ifconfig |grep $network >/dev/null ;then
ip_command=`ifconfig $network | grep 'inet addr' | awk '{ print $2}' | awk -F: '{print $2}'`
HTTP_SERVER=`echo $ip_command`
if [ -z "$HTTP_SERVER" ]; then
ip_command=`ifconfig $network | grep 'inet ' | awk '{ print $2}'`
HTTP_SERVER=`echo $ip_command`
fi
fi
#prod
if [ "X$HTTP_SERVER" == "X" ]; then
if ifconfig |grep bond0 >/dev/null ;then
ip_command=`ifconfig bond0 | grep 'inet addr' | awk '{ print $2}' | awk -F: '{print $2}'`
HTTP_SERVER=`echo $ip_command`
fi
fi
echo "Checking for local ip... $HTTP_SERVER"
if [ "X$HTTP_SERVER" == "X" ]; then
echo "Error: can't get local ip!"
exit
fi
# local or sit or test env
if [ $1 == "local" -o $1 == "sit" -o $1 == "test" ]; then
TFS_SERVER="10.213.33.177:11100"
REDIS_SERVER="10.213.33.155:10388"
fi
# uat
if [ $1 == "uat" ]; then
TFS_SERVER="10.213.129.75:11100"
REDIS_SERVER="10.213.33.155:10388"
fi
# prod
if [ $1 == "prod" ]; then
TFS_SERVER="10.209.18.2:11100"
REDIS_SERVER="10.209.33.19:10388"
fi
if [ -z "$TFS_SERVER" -o -z "$REDIS_SERVER" ]; then
echo "Invalid environment: $1"
exit
fi
echo "Checking tfs server... $TFS_SERVER"
echo "Checking redis server... $REDIS_SERVER"
echo "Checking worker process count... $CPU"
echo "Create /usr/local/tfsname/i* folder"
for((i=1;i<=5;i++)); do
dir="/usr/local/tfsimage/i"$i
if [ ! -d "$dir" ]; then
mkdir -p $dir
fi
sudo chown nobody $dir
sudo chgrp nobody $dir
sudo chmod 777 $dir
done
# set worker_processes
sed -ri "s/(.*)worker_processes\s+([0-9]+)/\1worker_processes $CPU/g" nginx.conf
#set lua_package_path
sed -ri "s/(.*)lua_package_path(.*)\?\.(.*)/\1lua_package_path \"\/var\/wd\/wrs\/webroot\/picture\/?.\3/g" nginx.conf
# set http port
sed -ri "s/(.*)listen\s+80/\1listen $HTTP_PORT/g" nginx.conf
##According to port match
#redis server
sed -ri "s/(.*)server\s*(([0-9]+\.){3}[0-9]+):10388(.*)/\1server $REDIS_SERVER\4/g" nginx.conf
#tfs server
sed -ri "s/(.*)server\s*(([0-9]+\.){3}[0-9]+):11100/\1server $TFS_SERVER/g" nginx.conf
#http server
sed -ri "s/(.*)server_name\s*(([0-9]+\.){3}[0-9]+).*/\1server_name $HTTP_SERVER;/g" nginx.conf
#---------test----------
sed -ri "s/(.*)IP\s=(.*)/\1IP = '$HTTP_SERVER:10502'/g" tests/img.py
chmod 755 ./tests/img.py
echo "Starting make ..."
# back nginx.conf
DATE=$(date +%m%d%H%M)
if [ -f /usr/local/tengine/conf/nginx.conf ]; then
cp /usr/local/tengine/conf/nginx.conf /usr/local/tengine/conf/nginx.${DATE}
echo "Back-up /usr/local/tengine/conf/nginx.conf to /usr/local/tengine/conf/nginx.${DATE}"
fi
py=""
if type py3 2>/dev/null; then
py="py3"
elif type python3 2>/dev/null; then
py="python3"
else
echo >&2 "Require python3 but it's not installed."
fi
PIC_MAKEFILE=./Makefile
TENGINE_CONF=/usr/local/tengine/conf
echo "creating $PIC_MAKEFILE"
cat << END > $PIC_MAKEFILE
all :
@echo "Please input make install..."
install : nginx.conf
mv ${TENGINE_CONF}/nginx.conf ${TENGINE_CONF}/nginx.bak
install -c -m 644 nginx.conf ${TENGINE_CONF}/
install -c -m 644 nginx_log_roll.sh ${TENGINE_CONF}/
# crontab -u root crontab
run :
/usr/local/tengine/sbin/nginx -s reload
nginx.conf :
test : tests/b.jpg tests/c.png tests/img.py
./tests/img.py
tests/b.jpg :
tests/c.png :
tests/img.py :
clean :
mv ${TENGINE_CONF}/nginx.bak ${TENGINE_CONF}/nginx.conf
.PHONY: all install test clean
END