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 sed -i -e "s@^DocumentRoot.*@DocumentRoot \"/data$DocumentRoot\"@" $httpd_conf
43 ln -nsf $DocumentRoot/PlanetLabConf /data$DocumentRoot/PlanetLabConf
45 sed -i -e "s@^DocumentRoot.*@DocumentRoot \"$DocumentRoot\"@" $httpd_conf
46 rm -f /data$DocumentRoot/PlanetLabConf
49 # Set the default include path
50 include_path=".:$DocumentRoot/planetlab/includes:$DocumentRoot/generated:/etc/planetlab/php:/usr/share/plc_api/php"
51 sed -i -e "s@[;]*include_path = \"\.:.*\"@include_path = \"$include_path\"@" $php_ini
53 # Disable default Listen directive
54 sed -i -e '/^Listen/d' $httpd_conf
56 # Set the port numbers
57 for server in WWW API BOOT ; do
58 enabled=PLC_${server}_ENABLED
59 if [ "${!enabled}" != "1" ] ; then
62 hostname=PLC_${server}_HOST
63 http_port=PLC_${server}_PORT
64 https_port=PLC_${server}_SSL_PORT
66 # API should always be accessed via SSL
67 if [ "$server" = "API" ] ; then
68 https_port=${!http_port}
72 # Check if we are already listening on these ports
75 for previous_server in WWW API BOOT ; do
76 if [ "$server" = "$previous_server" ] ; then
79 previous_enabled=PLC_${previous_server}_ENABLED
80 if [ "${!previous_enabled}" != "1" ] ; then
83 previous_http_port=PLC_${previous_server}_PORT
84 previous_https_port=PLC_${previous_server}_SSL_PORT
86 if [ "${!http_port}" = "${!previous_http_port}" ] ; then
89 if [ "${!https_port}" = "${!previous_https_port}" ] ; then
95 if [ $skip_http -eq 0 -a -n "${!http_port}" ] ; then
98 # Make sure that the admin web pages and API are always accessed via SSL
99 <VirtualHost *:${!http_port}>
100 Redirect /db https://$PLC_WWW_HOST:$PLC_WWW_SSL_PORT/db
101 Redirect /planetlab https://$PLC_WWW_HOST:$PLC_WWW_SSL_PORT/planetlab
102 Redirect /$PLC_API_PATH https://$PLC_API_HOST:$PLC_API_PORT/$PLC_API_PATH
107 # HTTPS configuration
108 if [ $skip_https -eq 0 -a -n "${!https_port}" ] ; then
109 # XXX Cannot support NameVirtualHost over SSL. If
110 # the API, boot, and web servers are all running
111 # on the same machine, the web server certificate
114 -e "s/^Listen .*/Listen ${!https_port}/" \
115 -e "s/<VirtualHost _default_:.*>/<VirtualHost _default_:${!https_port}>/" \
120 # Set custom Apache directives
122 if [ "$PLC_API_ENABLED" = "1" ] ; then
124 <Location $PLC_API_PATH>
125 SetHandler mod_python
126 PythonPath "sys.path + ['/usr/share/plc_api']"
127 PythonHandler ModPython
132 <Location $PLC_API_PATH>
138 if [ "$PLC_WWW_ENABLED" != "1" ] ; then
140 Redirect /index.html http://$PLC_WWW_HOST:$PLC_WWW_PORT/
144 AddType application/octet-stream .iso
145 AddType application/octet-stream .usb
149 # Make alpina-logs directory writable for bootmanager log upload
150 chown apache:apache $DocumentRoot/alpina-logs/nodes
152 # Make the Drupal files upload directory owned by Apache
153 mkdir -p $DocumentRoot/files
154 chown apache:apache $DocumentRoot/files
156 # Symlink any (real) files or directories in
157 # /data/var/www/html/* to /var/www/html/. We could descend
158 # into subdirectories, but the code to do so properly would be
160 for file in /data/$DocumentRoot/* ; do
161 if [ -e "$file" -a ! -h "$file" ] ; then
162 base=$(basename "$file")
163 if [ ! -e "$DocumentRoot/$base" ] ; then
164 ln -nsf "$file" "$DocumentRoot/$base"
169 # Cleanup broken symlinks
170 for file in $DocumentRoot/* ; do
171 if [ -h "$file" -a ! -e "$file" ] ; then
176 # Old style PHP constants
177 mkdir -p /etc/planetlab/php
178 cat >/etc/planetlab/php/site_constants.php <<"EOF"
180 include('plc_config.php');
182 define('PL_API_SERVER', PLC_API_HOST);
183 define('PL_API_PATH', PLC_API_PATH);
184 define('PL_API_PORT', PLC_API_PORT);
185 define('PL_API_CAPABILITY_AUTH_METHOD', 'capability');
186 define('PL_API_CAPABILITY_PASS', PLC_API_MAINTENANCE_PASSWORD);
187 define('PL_API_CAPABILITY_USERNAME', PLC_API_MAINTENANCE_USER);
188 define('WWW_BASE', PLC_WWW_HOST);
189 define('BOOT_BASE', PLC_BOOT_HOST);
190 define('DEBUG', PLC_WWW_DEBUG);
191 define('API_CALL_DEBUG', PLC_API_DEBUG);
192 define('SENDMAIL', PLC_MAIL_ENABLED);
193 define('PLANETLAB_SUPPORT_EMAIL', PLC_NAME . ' Support <' . PLC_MAIL_SUPPORT_ADDRESS . '>');
194 define('PLANETLAB_SUPPORT_EMAIL_ONLY', PLC_MAIL_SUPPORT_ADDRESS);
200 sed -i -e 's,^memory_limit = 8M *;,memory_limit = 24M ; patch myplc -- ,' $php_ini
201 # log_errors : is On by default
203 if ! grep '^error_log *=' $php_ini > /dev/null ; then
204 echo 'error_log = /var/log/php.log' >> $php_ini
205 touch /var/log/php.log
206 chmod 666 /var/log/php.log
216 MESSAGE=$"Stopping web server"