This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
/
install_fastcgi.sh
executable file
·258 lines (227 loc) · 5.55 KB
/
install_fastcgi.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/bin/bash
if [ -f /etc/init.d/hhvm ]
then
/etc/init.d/hhvm start
fi
#!/bin/bash
apache_check_installed() {
echo "Checking if Apache is installed"
if [ \( ! -d /etc/apache2/mods-enabled \) -o \( ! -d /etc/apache2/mods-available \) ]
then
echo "WARNING: Couldn't find Apache2 configuration paths, not configuring"
return 1
fi
echo "Detected Apache installation"
return 0
}
apache_check_custom() {
echo "Looking for custom proxy configuration"
if [ ! -z "$(grep 9000 -R /etc/apache2/mods-enabled | grep ProxyPass)" ]
then
echo "WARNING: Clashing existing configuration detected, not configuring"
return 0
fi
echo "No custom proxy configuration found"
return 1
}
apache_check_module() {
echo "Checking for ${2} ${1}.${3}"
if [ ! -f "/etc/apache2/mods-${2}/${1}.${3}" ]
then
echo "Not found"
return 1
fi
echo "Found, checking for loading directives"
if [ "$3" == "load" ]
then
result=$(grep -E "^[^#]*LoadModule\\s*${1}_module" "/etc/apache2/mods-${2}/${1}.${3}")
if [ -z "$result" ]
then
"Loading directive not found"
return 1
fi
fi
echo "Detected ${2} ${1}.${3} configuration, setting up integration"
return 0
}
apache_force_enable_module() {
echo "Force enabling module ${1}.${2}"
if [ ! -f "/etc/apache2/mods-available/${1}.${2}" ]
then
echo "WARNING: Unsupported ${1}, not configuring"
return 1
fi
echo "Available module found"
rm -f "/etc/apache2/mods-enabled/${1}.${2}"
echo "Removed possible duplicates"
apache_enable_module $1 $2
echo "Completed force enabling"
return 0
}
apache_enable_module() {
echo "Enabling module ${1}.${2}"
if [ ! -f "/etc/apache2/mods-available/${1}.${2}" ]
then
echo "WARNING: Could not enable ${1}, not configuring"
return 1
fi
echo "Found available module"
if [ -f "/etc/apache2/mods-enabled/${1}.${2}" ]
then
echo "Module already enabled"
return 0
fi
echo "Creating a symlink"
ln -s "../mods-available/${1}.${2}" "/etc/apache2/mods-enabled/${1}.${2}"
echo "Finished creating a symlink"
return 0
}
apache_disable_module() {
echo "Disabling a module ${1}.${2}"
rm -f "/etc/apache2/mods-enabled/${1}.${2}"
echo "Finished disabling a module"
}
apache_restart() {
echo "Restarting apache"
if [ ! -f "/etc/init.d/apache2" ]
then
echo "Apache init.d script not detected"
return 0
fi
result=$(/etc/init.d/apache2 status | grep 'is running')
if [ ! -z "$result" ]
then
echo "Apache is running, restarting"
/etc/init.d/apache2 restart
echo "Finished restarting"
fi
echo "Finished restarting apache"
return 0
}
#!/bin/bash
apache_postinst() {
if ! apache_check_installed
then
return 0
fi
if apache_check_custom
then
return 0
fi
names="proxy_fcgi fastcgi fcgid"
for name in $names
do
if ! apache_check_module "${name}" "enabled" "load"; then continue; fi
if [ "$name" == "proxy_fcgi" ]
then
if ! apache_check_module "proxy" "enabled" "load"; then continue; fi
if ! apache_check_module "proxy" "enabled" "conf"; then continue; fi
fi
apache_force_enable_module "hhvm_${name}" "conf"
apache_restart
return 0
done
for name in $names
do
if ! apache_check_module "${name}" "available" "load"; then continue; fi
if ! apache_check_module "hhvm_${name}" "available" "conf"; then continue; fi
if [ "$name" == "proxy_fcgi" ]
then
if ! apache_check_module "proxy" "available" "load"; then continue; fi
if ! apache_check_module "proxy" "available" "conf"; then continue; fi
fi
if [ "$name" == "proxy_fcgi" ]
then
apache_enable_module "proxy" "load"
apache_enable_module "proxy" "conf"
fi
apache_enable_module "$name" "load"
apache_force_enable_module "hhvm_${name}" "conf"
apache_restart
return 0
done
echo "No matching Apache configuration found, not configuring"
return 0
}
apache_postinst
#!/bin/bash
insert_line() {
file=`mktemp`
sed -E "s/^(\\s*)${2}$/&\\n\\1${3}/" $1 > $file
cat $file > $1
}
remove_line() {
file=`mktemp`
sed -E "/^.*${2}.*$/d" $1 > $file
cat $file > $1
}
check_line() {
if [ -z "$(grep $2 $1)" ]
then
return 0
fi
return 1
}
nginx_check_installed() {
echo "Checking if Nginx is installed"
if [ -d "/etc/nginx/conf.d/" ]
then
echo "Detected Nginx installation"
return 0
fi
echo "Nginx not found"
return 1
}
nginx_check_custom() {
echo "Checking for custom Nginx configuration"
if [ ! \( -z "$(grep -E "^[^#]*(fastcgi|hhvm.conf)" "/etc/nginx/nginx.conf")" \) \
-o ! \( -z "$(grep -ER "^[^#]*(fastcgi|hhvm.conf)" "/etc/nginx/conf.d/")" \) \
-o ! \( -z "$(grep -ER "^[^#]*(fastcgi|hhvm.conf)" "/etc/nginx/sites-enabled/")" \) ]
then
echo "WARNING: Detected clashing configuration. Look at /etc/nginx/hhvm.conf for information how to connect to the hhvm fastcgi instance."
return 0
fi
return 1
}
nginx_enable_module() {
echo "Enabling hhvm Nginx module"
insert_line "/etc/nginx/sites-enabled/default" 'server_name.*$' 'include hhvm.conf;'
echo "Finished enabling module"
}
nginx_disable_module() {
echo "Disabling hhvm Nginx module"
remove_line "/etc/nginx/sites-enabled/default" "hhvm.conf"
echo "Finished disabling module"
}
nginx_restart() {
echo "Restarting Nginx"
if [ ! -f "/etc/init.d/nginx" ]
then
echo "Nginx init.d script not found"
return 0
fi
result=$(/etc/init.d/nginx status | grep 'is running')
if [ ! -z "$result" ]
then
echo "Nginx is running, restarting"
/etc/init.d/nginx stop
/etc/init.d/nginx start
echo "Restarted nginx"
fi
echo "Finished restarting Nginx"
}
#!/bin/bash
nginx_postinst() {
if ! nginx_check_installed
then
return 0
fi
if nginx_check_custom
then
return 0
fi
nginx_enable_module
nginx_restart
return 0
}
nginx_postinst