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.9 2007/02/02 15:37:25 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 default include path
39 include_path=".:$DocumentRoot/planetlab/includes:$DocumentRoot/generated:/etc/planetlab/php:/usr/share/plc_api/php"
40 sed -i -e "s@[;]*include_path = \"\.:.*\"@include_path = \"$include_path\"@" $php_ini
42 # Disable default Listen directive
43 sed -i -e '/^Listen/d' $httpd_conf
45 # Set the port numbers
46 for server in WWW API BOOT ; do
47 enabled=PLC_${server}_ENABLED
48 if [ "${!enabled}" != "1" ] ; then
51 hostname=PLC_${server}_HOST
52 http_port=PLC_${server}_PORT
53 https_port=PLC_${server}_SSL_PORT
55 # API should always be accessed via SSL
56 if [ "$server" = "API" ] ; then
57 https_port=${!http_port}
61 # Check if we are already listening on these ports
64 for previous_server in WWW API BOOT ; do
65 if [ "$server" = "$previous_server" ] ; then
68 previous_enabled=PLC_${previous_server}_ENABLED
69 if [ "${!previous_enabled}" != "1" ] ; then
72 previous_http_port=PLC_${previous_server}_PORT
73 previous_https_port=PLC_${previous_server}_SSL_PORT
75 if [ "${!http_port}" = "${!previous_http_port}" ] ; then
78 if [ "${!https_port}" = "${!previous_https_port}" ] ; then
84 if [ $skip_http -eq 0 -a -n "${!http_port}" ] ; then
87 # Make sure that the admin web pages and API are always accessed via SSL
88 <VirtualHost *:${!http_port}>
89 Redirect /db https://$PLC_WWW_HOST:$PLC_WWW_SSL_PORT/db
90 Redirect /planetlab https://$PLC_WWW_HOST:$PLC_WWW_SSL_PORT/planetlab
91 Redirect /$PLC_API_PATH https://$PLC_API_HOST:$PLC_API_PORT/$PLC_API_PATH
97 if [ $skip_https -eq 0 -a -n "${!https_port}" ] ; then
98 # XXX Cannot support NameVirtualHost over SSL. If
99 # the API, boot, and web servers are all running
100 # on the same machine, the web server certificate
103 -e "s/^Listen .*/Listen ${!https_port}/" \
104 -e "s/<VirtualHost _default_:.*>/<VirtualHost _default_:${!https_port}>/" \
109 # Set custom Apache directives
111 if [ "$PLC_API_ENABLED" = "1" ] ; then
113 <Location $PLC_API_PATH>
114 SetHandler mod_python
115 PythonPath "sys.path + ['/usr/share/plc_api']"
116 PythonHandler ModPython
121 <Location $PLC_API_PATH>
127 if [ "$PLC_WWW_ENABLED" != "1" ] ; then
132 <Location /planetlab>
135 Redirect /index.php http://$PLC_WWW_HOST:$PLC_WWW_PORT/
140 # Make alpina-logs directory writable for bootmanager log upload
141 chown apache:apache $DocumentRoot/alpina-logs/nodes
143 # Make the Drupal files upload directory owned by Apache
144 mkdir -p $DocumentRoot/files
145 chown apache:apache $DocumentRoot/files
147 # Symlink any (real) files or directories in
148 # /data/var/www/html/* to /var/www/html/. We could descend
149 # into subdirectories, but the code to do so properly would be
151 for file in /data/$DocumentRoot/* ; do
152 if [ -e "$file" -a ! -h "$file" ] ; then
153 base=$(basename "$file")
154 if [ ! -e "$DocumentRoot/$base" ] ; then
155 ln -nsf "$file" "$DocumentRoot/$base"
160 # Cleanup broken symlinks
161 for file in $DocumentRoot/* ; do
162 if [ -h "$file" -a ! -e "$file" ] ; then
167 # Old style PHP constants
168 mkdir -p /etc/planetlab/php
169 cat >/etc/planetlab/php/site_constants.php <<"EOF"
171 include('plc_config.php');
173 define('PL_API_SERVER', PLC_API_HOST);
174 define('PL_API_PATH', PLC_API_PATH);
175 define('PL_API_PORT', PLC_API_PORT);
176 define('PL_API_CAPABILITY_AUTH_METHOD', 'capability');
177 define('PL_API_CAPABILITY_PASS', PLC_API_MAINTENANCE_PASSWORD);
178 define('PL_API_CAPABILITY_USERNAME', PLC_API_MAINTENANCE_USER);
179 define('WWW_BASE', PLC_WWW_HOST);
180 define('BOOT_BASE', PLC_BOOT_HOST);
181 define('DEBUG', PLC_WWW_DEBUG);
182 define('API_CALL_DEBUG', PLC_API_DEBUG);
183 define('SENDMAIL', PLC_MAIL_ENABLED);
184 define('PLANETLAB_SUPPORT_EMAIL', PLC_NAME . ' Support <' . PLC_MAIL_SUPPORT_ADDRESS . '>');
185 define('PLANETLAB_SUPPORT_EMAIL_ONLY', PLC_MAIL_SUPPORT_ADDRESS);
196 MESSAGE=$"Stopping web server"