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.10 2007/02/05 19:56:26 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 # only, no Drupal or admin pages) if the web server should not
40 # run on this machine.
41 if [ "$PLC_WWW_ENABLED" != "1" ] ; then
42 sed -i -e "s@^DocumentRoot.*@DocumentRoot \"/data$DocumentRoot\"@" $httpd_conf
44 sed -i -e "s@^DocumentRoot.*@DocumentRoot \"$DocumentRoot\"@" $httpd_conf
47 # Set the default include path
48 include_path=".:$DocumentRoot/planetlab/includes:$DocumentRoot/generated:/etc/planetlab/php:/usr/share/plc_api/php"
49 sed -i -e "s@[;]*include_path = \"\.:.*\"@include_path = \"$include_path\"@" $php_ini
51 # Disable default Listen directive
52 sed -i -e '/^Listen/d' $httpd_conf
54 # Set the port numbers
55 for server in WWW API BOOT ; do
56 enabled=PLC_${server}_ENABLED
57 if [ "${!enabled}" != "1" ] ; then
60 hostname=PLC_${server}_HOST
61 http_port=PLC_${server}_PORT
62 https_port=PLC_${server}_SSL_PORT
64 # API should always be accessed via SSL
65 if [ "$server" = "API" ] ; then
66 https_port=${!http_port}
70 # Check if we are already listening on these ports
73 for previous_server in WWW API BOOT ; do
74 if [ "$server" = "$previous_server" ] ; then
77 previous_enabled=PLC_${previous_server}_ENABLED
78 if [ "${!previous_enabled}" != "1" ] ; then
81 previous_http_port=PLC_${previous_server}_PORT
82 previous_https_port=PLC_${previous_server}_SSL_PORT
84 if [ "${!http_port}" = "${!previous_http_port}" ] ; then
87 if [ "${!https_port}" = "${!previous_https_port}" ] ; then
93 if [ $skip_http -eq 0 -a -n "${!http_port}" ] ; then
96 # Make sure that the admin web pages and API are always accessed via SSL
97 <VirtualHost *:${!http_port}>
98 Redirect /db https://$PLC_WWW_HOST:$PLC_WWW_SSL_PORT/db
99 Redirect /planetlab https://$PLC_WWW_HOST:$PLC_WWW_SSL_PORT/planetlab
100 Redirect /$PLC_API_PATH https://$PLC_API_HOST:$PLC_API_PORT/$PLC_API_PATH
105 # HTTPS configuration
106 if [ $skip_https -eq 0 -a -n "${!https_port}" ] ; then
107 # XXX Cannot support NameVirtualHost over SSL. If
108 # the API, boot, and web servers are all running
109 # on the same machine, the web server certificate
112 -e "s/^Listen .*/Listen ${!https_port}/" \
113 -e "s/<VirtualHost _default_:.*>/<VirtualHost _default_:${!https_port}>/" \
118 # Set custom Apache directives
120 if [ "$PLC_API_ENABLED" = "1" ] ; then
122 <Location $PLC_API_PATH>
123 SetHandler mod_python
124 PythonPath "sys.path + ['/usr/share/plc_api']"
125 PythonHandler ModPython
130 <Location $PLC_API_PATH>
136 if [ "$PLC_WWW_ENABLED" != "1" ] ; then
141 <Location /planetlab>
144 Redirect /index.php http://$PLC_WWW_HOST:$PLC_WWW_PORT/
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);
205 MESSAGE=$"Stopping web server"