5 # Configure Apache web server
7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2006 The Trustees of Princeton University
10 # $Id: httpd,v 1.11 2007/02/06 16:24:13 mlhuang Exp $
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/
145 # Make alpina-logs directory writable for bootmanager log upload
146 chown apache:apache $DocumentRoot/alpina-logs/nodes
148 # Make the Drupal files upload directory owned by Apache
149 mkdir -p $DocumentRoot/files
150 chown apache:apache $DocumentRoot/files
152 # Symlink any (real) files or directories in
153 # /data/var/www/html/* to /var/www/html/. We could descend
154 # into subdirectories, but the code to do so properly would be
156 for file in /data/$DocumentRoot/* ; do
157 if [ -e "$file" -a ! -h "$file" ] ; then
158 base=$(basename "$file")
159 if [ ! -e "$DocumentRoot/$base" ] ; then
160 ln -nsf "$file" "$DocumentRoot/$base"
165 # Cleanup broken symlinks
166 for file in $DocumentRoot/* ; do
167 if [ -h "$file" -a ! -e "$file" ] ; then
172 # Old style PHP constants
173 mkdir -p /etc/planetlab/php
174 cat >/etc/planetlab/php/site_constants.php <<"EOF"
176 include('plc_config.php');
178 define('PL_API_SERVER', PLC_API_HOST);
179 define('PL_API_PATH', PLC_API_PATH);
180 define('PL_API_PORT', PLC_API_PORT);
181 define('PL_API_CAPABILITY_AUTH_METHOD', 'capability');
182 define('PL_API_CAPABILITY_PASS', PLC_API_MAINTENANCE_PASSWORD);
183 define('PL_API_CAPABILITY_USERNAME', PLC_API_MAINTENANCE_USER);
184 define('WWW_BASE', PLC_WWW_HOST);
185 define('BOOT_BASE', PLC_BOOT_HOST);
186 define('DEBUG', PLC_WWW_DEBUG);
187 define('API_CALL_DEBUG', PLC_API_DEBUG);
188 define('SENDMAIL', PLC_MAIL_ENABLED);
189 define('PLANETLAB_SUPPORT_EMAIL', PLC_NAME . ' Support <' . PLC_MAIL_SUPPORT_ADDRESS . '>');
190 define('PLANETLAB_SUPPORT_EMAIL_ONLY', PLC_MAIL_SUPPORT_ADDRESS);
201 MESSAGE=$"Stopping web server"