5 # Configure Apache web server
7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2006 The Trustees of Princeton University
13 # Source function library and configuration
14 . /etc/plc.d/functions
15 . /etc/planetlab/plc_config
21 DocumentRoot=/var/www/html
23 httpd_conf=/etc/httpd/conf/httpd.conf
24 ssl_conf=/etc/httpd/conf.d/ssl.conf
25 plc_conf=/etc/httpd/conf.d/plc.conf
29 if [ "$PLC_API_ENABLED" != "1" -a \
30 "$PLC_BOOT_ENABLED" != "1" -a \
31 "$PLC_WWW_ENABLED" != "1" ] ; then
35 MESSAGE=$"Starting web server"
38 # Set the document root to /data/var/www/html (static files
39 # and PlanetLabConf only, no Drupal or admin pages) if the web
40 # server should not run on this machine.
41 if [ "$PLC_WWW_ENABLED" != "1" ] ; then
42 if [ -d "/data" ] ; then
43 sed -i -e "s@^DocumentRoot.*@DocumentRoot \"/data$DocumentRoot\"@" $httpd_conf
44 ln -nsf $DocumentRoot/PlanetLabConf /data$DocumentRoot/PlanetLabConf
46 # NOTE: otherwise, the paths are correct by default.
50 sed -i -e "s@^DocumentRoot.*@DocumentRoot \"$DocumentRoot\"@" $httpd_conf
51 rm -f /data$DocumentRoot/PlanetLabConf
54 # Set the default include path
55 include_path=".:$DocumentRoot/planetlab/includes:$DocumentRoot/plekit/php:$DocumentRoot/generated:/etc/planetlab/php:/usr/share/plc_api/php"
56 sed -i -e "s@[;]*include_path = \"\.:.*\"@include_path = \"$include_path\"@" $php_ini
58 # Disable default Listen directive
59 sed -i -e '/^Listen/d' $httpd_conf
61 # Set the port numbers
62 for server in WWW API BOOT ; do
63 enabled=PLC_${server}_ENABLED
64 if [ "${!enabled}" != "1" ] ; then
67 hostname=PLC_${server}_HOST
68 http_port=PLC_${server}_PORT
69 https_port=PLC_${server}_SSL_PORT
71 # API should always be accessed via SSL
72 if [ "$server" = "API" ] ; then
73 https_port=${!http_port}
77 # Check if we are already listening on these ports
80 for previous_server in WWW API BOOT ; do
81 if [ "$server" = "$previous_server" ] ; then
84 previous_enabled=PLC_${previous_server}_ENABLED
85 if [ "${!previous_enabled}" != "1" ] ; then
88 previous_http_port=PLC_${previous_server}_PORT
89 previous_https_port=PLC_${previous_server}_SSL_PORT
91 if [ "${!http_port}" = "${!previous_http_port}" ] ; then
94 if [ "${!https_port}" = "${!previous_https_port}" ] ; then
100 if [ $skip_http -eq 0 -a -n "${!http_port}" ] ; then
103 # Make sure that the admin web pages and API are always accessed via SSL
104 <VirtualHost *:${!http_port}>
105 Redirect /db https://$PLC_WWW_HOST:$PLC_WWW_SSL_PORT/db
106 Redirect /planetlab https://$PLC_WWW_HOST:$PLC_WWW_SSL_PORT/planetlab
107 Redirect /$PLC_API_PATH https://$PLC_API_HOST:$PLC_API_PORT/$PLC_API_PATH
112 # HTTPS configuration
113 if [ $skip_https -eq 0 -a -n "${!https_port}" ] ; then
114 # XXX Cannot support NameVirtualHost over SSL. If
115 # the API, boot, and web servers are all running
116 # on the same machine, the web server certificate
119 -e "s/^Listen .*/Listen ${!https_port}/" \
120 -e "s/<VirtualHost _default_:.*>/<VirtualHost _default_:${!https_port}>/" \
125 # Set custom Apache directives
127 if [ "$PLC_API_ENABLED" = "1" ] ; then
129 <Location $PLC_API_PATH>
130 SetHandler mod_python
131 PythonPath "sys.path + ['/usr/share/plc_api']"
132 PythonHandler ModPython
137 <Location $PLC_API_PATH>
143 if [ "$PLC_WWW_ENABLED" != "1" ] ; then
145 Redirect /index.html http://$PLC_WWW_HOST:$PLC_WWW_PORT/
149 AddType application/octet-stream .iso
150 AddType application/octet-stream .usb
154 # Make alpina-logs directory writable for bootmanager log upload
155 chown apache:apache $DocumentRoot/alpina-logs/nodes
157 # Make the Drupal files upload directory owned by Apache
158 mkdir -p $DocumentRoot/files
159 chown apache:apache $DocumentRoot/files
161 # Symlink any (real) files or directories in
162 # /data/var/www/html/* to /var/www/html/. We could descend
163 # into subdirectories, but the code to do so properly would be
165 for file in /data/$DocumentRoot/* ; do
166 if [ -e "$file" -a ! -h "$file" ] ; then
167 base=$(basename "$file")
168 if [ ! -e "$DocumentRoot/$base" ] ; then
169 ln -nsf "$file" "$DocumentRoot/$base"
174 # Cleanup broken symlinks
175 for file in $DocumentRoot/* ; do
176 if [ -h "$file" -a ! -e "$file" ] ; then
181 # Old style PHP constants
182 mkdir -p /etc/planetlab/php
183 cat >/etc/planetlab/php/site_constants.php <<"EOF"
185 include('plc_config.php');
187 define('PL_API_SERVER', PLC_API_HOST);
188 define('PL_API_PATH', PLC_API_PATH);
189 define('PL_API_PORT', PLC_API_PORT);
190 define('PL_API_CAPABILITY_AUTH_METHOD', 'capability');
191 define('PL_API_CAPABILITY_PASS', PLC_API_MAINTENANCE_PASSWORD);
192 define('PL_API_CAPABILITY_USERNAME', PLC_API_MAINTENANCE_USER);
193 define('WWW_BASE', PLC_WWW_HOST);
194 define('BOOT_BASE', PLC_BOOT_HOST);
195 define('DEBUG', PLC_WWW_DEBUG);
196 define('API_CALL_DEBUG', PLC_API_DEBUG);
197 define('SENDMAIL', PLC_MAIL_ENABLED);
198 define('PLANETLAB_SUPPORT_EMAIL', PLC_NAME . ' Support <' . PLC_MAIL_SUPPORT_ADDRESS . '>');
199 define('PLANETLAB_SUPPORT_EMAIL_ONLY', PLC_MAIL_SUPPORT_ADDRESS);
205 sed -i -e 's,^memory_limit = 32M *;,memory_limit = 80M ; patch myplc -- ,' $php_ini
206 # log_errors : is On by default
208 if ! grep '^error_log *=' $php_ini > /dev/null ; then
209 echo 'error_log = /var/log/php.log' >> $php_ini
210 touch /var/log/php.log
211 chmod 666 /var/log/php.log
221 MESSAGE=$"Stopping web server"