5 # Configure Apache web server
7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2006 The Trustees of Princeton University
11 # Source function library and configuration
12 . /etc/plc.d/functions
13 . /etc/planetlab/plc_config
19 DocumentRoot=/var/www/html
21 httpd_conf=/etc/httpd/conf/httpd.conf
22 ssl_conf=/etc/httpd/conf.d/ssl.conf
23 plc_conf=/etc/httpd/conf.d/plc.conf
24 php_fpm_conf=/etc/php-fpm.d/plc.conf
25 php_fpm_dir=$(dirname $php_fpm_conf)
27 function disable_file () {
29 [ -f $file ] && mv -f $file $file.disabled
31 function enable_file () {
33 [ ! -f $file ] && mv -f $file.disabled $file
38 if [ "$PLC_API_ENABLED" != "1" -a \
39 "$PLC_BOOT_ENABLED" != "1" -a \
40 "$PLC_WWW_ENABLED" != "1" ] ; then
44 MESSAGE=$"Starting web server"
47 # set document root - not really useful on fedora but just in case
48 sed -i -e "s@^DocumentRoot.*@DocumentRoot \"$DocumentRoot\"@" $httpd_conf
49 # whether WWW is enabled or not :
50 if [ "$PLC_WWW_ENABLED" != "1" ] ; then
51 # avoid hitting drupal, that would try to connect to the db and create noise
52 disable_file $DocumentRoot/index.php
54 enable_file $DocumentRoot/index.php
57 # Set the default include path
58 include_path=".:$DocumentRoot/planetlab/includes:$DocumentRoot/plekit/php:$DocumentRoot/generated:/etc/planetlab/php:/usr/share/plc_api/php"
59 sed -i -e "s@[;]*include_path = \"\.:.*\"@include_path = \"$include_path\"@" $php_ini
61 # Set open_basedir so as to avoid leaks
62 open_basedir="$DocumentRoot:/etc/planetlab/php:/usr/share/plc_api/php:/var/log/myslice:/var/tmp/bootmedium:/var/log/bm:/tmp"
63 sed -i -e "s@[;]*open_basedir =.*@open_basedir = \"$open_basedir\"@" $php_ini
65 # for php-5.3 under fedora12, otherwise issues tons of warning messages
66 # Set timezone in php.ini if not already there
67 if grep '^;date.timezone' $php_ini >& /dev/null; then
68 dialog 'Setting PHP timezone to GMT'
69 sed -i -e 's,^;date.timezone.*,date.timezone = GMT,' $php_ini
72 if grep '^short_open_tag = Off' $php_ini >& /dev/null; then
73 sed -i -e 's,^short_open_tag = Off,short_open_tag = On,' $php_ini
78 sed -i -e 's,^memory_limit = 32M *;,memory_limit = 80M ; patch myplc -- ,' $php_ini
79 # log_errors : is On by default
81 if ! grep '^error_log *=' $php_ini > /dev/null ; then
82 echo 'error_log = /var/log/php.log' >> $php_ini
83 touch /var/log/php.log
84 chmod 666 /var/log/php.log
87 # configure php-fpm as well if present (starting with f27)
88 if [ -d $php_fpm_dir ] ; then
89 cat > $php_fpm_conf << EOF
91 php_value[include_path] = $include_path
92 php_value[open_basedir] = $open_basedir
93 php_value[date.timezone] = GMT
94 php_value[short_open_tag] = On
95 php_value[memory_limit] = 80M
97 # this is needed because otherwise, the first time
98 # we do this configuration, the service is already up
99 # and the config is usable only the second time
100 systemctl restart php-fpm
103 # Disable default Listen directive
104 sed -i -e '/^Listen/d' $httpd_conf
106 plc_api_path_noslash=$(echo $PLC_API_PATH | sed -e s,/,,g)
107 # Set the port numbers
108 for server in WWW API BOOT ; do
109 enabled=PLC_${server}_ENABLED
110 if [ "${!enabled}" != "1" ] ; then
113 hostname=PLC_${server}_HOST
114 http_port=PLC_${server}_PORT
115 https_port=PLC_${server}_SSL_PORT
117 # API should always be accessed via SSL
118 if [ "$server" = "API" ] ; then
119 https_port=${!http_port}
123 # Check if we are already listening on these ports
126 for previous_server in WWW API BOOT ; do
127 if [ "$server" = "$previous_server" ] ; then
130 previous_enabled=PLC_${previous_server}_ENABLED
131 if [ "${!previous_enabled}" != "1" ] ; then
134 previous_http_port=PLC_${previous_server}_PORT
135 previous_https_port=PLC_${previous_server}_SSL_PORT
137 if [ -z "${http_port}" ]; then
139 elif [ -z "${!http_port}" ]; then
141 elif [ "${!http_port}" = "${!previous_http_port}" ] ; then
144 if [ -z "${https_port}" ]; then
146 elif [ -z "${!https_port}" ]; then
148 elif [ "${!https_port}" = "${!previous_https_port}" ] ; then
154 if [ $skip_http -eq 0 ] ; then
157 <VirtualHost *:${!http_port}>
158 # Make sure that the admin web pages are always accessed via SSL
159 Redirect /db https://$PLC_WWW_HOST:$PLC_WWW_SSL_PORT/db
160 Redirect /planetlab https://$PLC_WWW_HOST:$PLC_WWW_SSL_PORT/planetlab
161 # as a matter of fact most xmlrpc clients won't follow the redirection
162 # so this is mostly rethorical, but just in case...
163 Redirect /$plc_api_path_noslash https://$PLC_WWW_HOST:$PLC_WWW_SSL_PORT/$plc_api_path_noslash
169 # HTTPS configuration
170 if [ $skip_https -eq 0 ] ; then
171 # XXX Cannot support NameVirtualHost over SSL. If
172 # the API, boot, and web servers are all running
173 # on the same machine, the web server certificate
176 -e "s/^Listen .*/Listen ${!https_port}/" \
177 -e "s/<VirtualHost _default_:.*>/<VirtualHost _default_:${!https_port}>/" \
179 # this is used to locate the right certificates
180 server_lower=$(echo $server | tr 'A-Z' 'a-z')
182 # which one is used is currently configured in myplc.spec,
183 # with mod_python preferred
184 if rpm -q mod_python >& /dev/null ; then
185 configure_for_mod_python=true
186 elif rpm -q mod_wsgi >& /dev/null \
187 || rpm -q python2-mod_wsgi >& /dev/null \
188 || rpm -q python3-mod_wsgi >& /dev/null ; then
189 configure_for_mod_wsgi=true
191 echo "Requires mod_python or mod_wsgi.... exiting"
195 # It would be tempting to use <IfModule> here
196 # but early tests showed this could be tricky/fragile
197 # So let's hard-wire it for one module
198 # A lot of trial-and -error was involved in getting this that way...
200 if [ -n "$configure_for_mod_python" ] ; then
201 #################### for mod_python
203 # mod_python location
205 SetHandler mod_python
206 PythonPath "sys.path + ['/usr/share/plc_api']"
207 PythonHandler apache.ModPython
211 elif [ -n "$configure_for_mod_wsgi" ] ; then
212 #################### for mod_wsgi
214 # create wsgi socket where we have the permission
215 WSGISocketPrefix run/wsgi
217 <VirtualHost *:${!https_port}>
221 SSLCertificateFile /etc/planetlab/${server_lower}_ssl.crt
222 SSLCertificateKeyFile /etc/planetlab/${server_lower}_ssl.key
223 SSLCertificateChainFile /etc/planetlab/${server_lower}_ca_ssl.crt
225 WSGIScriptAlias /$plc_api_path_noslash /usr/share/plc_api/apache/plc.wsgi
226 # xxx would be cool to be able to tweak this through config
227 WSGIDaemonProcess plcapi-wsgi-ssl user=apache group=apache processes=1 threads=25
228 WSGIProcessGroup plcapi-wsgi-ssl
230 <Directory "/usr/share/plc_api/apache">
241 # Set custom Apache directives
243 # could be restricted to boot boxes but harmless..
245 AddType application/octet-stream .iso
246 AddType application/octet-stream .usb
248 # make sure /PLCAPI can't get accessed if API not enabled here
249 if [ "$PLC_API_ENABLED" != "1" ] ; then
252 <Location $PLC_API_PATH>
258 # redirect www requests if not on the right server
259 if [ "$PLC_WWW_ENABLED" != "1" ] ; then
261 Redirect /index.html http://$PLC_WWW_HOST:$PLC_WWW_PORT/
266 # Make alpina-logs directory writable for bootmanager log upload
267 chown apache:apache $DocumentRoot/alpina-logs/nodes
269 # Make the Drupal files upload directory owned by Apache
270 mkdir -p $DocumentRoot/files
271 chown apache:apache $DocumentRoot/files
273 # Symlink any (real) files or directories in
274 # /data/var/www/html/* to /var/www/html/. We could descend
275 # into subdirectories, but the code to do so properly would be
277 for file in /data/$DocumentRoot/* ; do
278 if [ -e "$file" -a ! -h "$file" ] ; then
279 base=$(basename "$file")
280 if [ ! -e "$DocumentRoot/$base" ] ; then
281 ln -nsf "$file" "$DocumentRoot/$base"
286 # Cleanup broken symlinks
287 for file in $DocumentRoot/* ; do
288 if [ -h "$file" -a ! -e "$file" ] ; then
293 # Old style PHP constants
294 mkdir -p /etc/planetlab/php
295 cat >/etc/planetlab/php/site_constants.php <<"EOF"
297 include('plc_config.php');
299 define('PL_API_SERVER', PLC_API_HOST);
300 define('PL_API_PATH', PLC_API_PATH);
301 define('PL_API_PORT', PLC_API_PORT);
302 define('PL_API_CAPABILITY_AUTH_METHOD', 'capability');
303 define('PL_API_CAPABILITY_PASS', PLC_API_MAINTENANCE_PASSWORD);
304 define('PL_API_CAPABILITY_USERNAME', PLC_API_MAINTENANCE_USER);
305 define('WWW_BASE', PLC_WWW_HOST);
306 define('BOOT_BASE', PLC_BOOT_HOST);
307 define('DEBUG', PLC_WWW_DEBUG);
308 define('API_CALL_DEBUG', PLC_API_DEBUG);
309 define('SENDMAIL', PLC_MAIL_ENABLED);
310 define('PLANETLAB_SUPPORT_EMAIL', PLC_NAME . ' Support <' . PLC_MAIL_SUPPORT_ADDRESS . '>');
311 define('PLANETLAB_SUPPORT_EMAIL_ONLY', PLC_MAIL_SUPPORT_ADDRESS);
315 ## make room for logs
316 touch /var/log/plcapi.log
317 chmod 666 /var/log/plcapi.log
326 MESSAGE=$"Stopping web server"