5 # Configure Apache web server
7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2006 The Trustees of Princeton University
11 # Source function library and configuration
12 . /etc/plc.d/functions
13 . /etc/planetlab/plc_config
19 DocumentRoot=/var/www/html
21 httpd_conf=/etc/httpd/conf/httpd.conf
22 ssl_conf=/etc/httpd/conf.d/ssl.conf
23 plc_conf=/etc/httpd/conf.d/plc.conf
25 function disable_file () {
27 [ -f $file ] && mv -f $file $file.disabled
29 function enable_file () {
31 [ ! -f $file ] && mv -f $file.disabled $file
36 if [ "$PLC_API_ENABLED" != "1" -a \
37 "$PLC_BOOT_ENABLED" != "1" -a \
38 "$PLC_WWW_ENABLED" != "1" ] ; then
42 MESSAGE=$"Starting web server"
45 # set document root - not really useful on fedora but just in case
46 sed -i -e "s@^DocumentRoot.*@DocumentRoot \"$DocumentRoot\"@" $httpd_conf
47 # whether WWW is enabled or not :
48 if [ "$PLC_WWW_ENABLED" != "1" ] ; then
49 # avoid hitting drupal, that would try to connect to the db and create noise
50 disable_file $DocumentRoot/index.php
52 enable_file $DocumentRoot/index.php
55 # Set the default include path
56 include_path=".:$DocumentRoot/planetlab/includes:$DocumentRoot/plekit/php:$DocumentRoot/generated:/etc/planetlab/php:/usr/share/plc_api/php"
57 sed -i -e "s@[;]*include_path = \"\.:.*\"@include_path = \"$include_path\"@" $php_ini
59 # Set open_basedir so as to avoid leaks
60 open_basedir="$DocumentRoot:/etc/planetlab/php:/usr/share/plc_api/php:/var/log/myslice:/var/tmp/bootmedium:/tmp"
61 sed -i -e "s@[;]*open_basedir =.*@open_basedir = \"$open_basedir\"@" $php_ini
63 # for php-5.3 under fedora12, otherwise issues tons of warning messages
64 # Set timezone in php.ini if not already there
65 if grep '^;date.timezone' $php_ini >& /dev/null; then
66 dialog 'Setting PHP timezone to GMT'
67 sed -i -e 's,^;date.timezone.*,date.timezone = GMT,' $php_ini
70 if grep '^short_open_tag = Off' $php_ini >& /dev/null; then
71 sed -i -e 's,^short_open_tag = Off,short_open_tag = On,' $php_ini
74 # Disable default Listen directive
75 sed -i -e '/^Listen/d' $httpd_conf
77 # Set the port numbers
78 for server in WWW API BOOT ; do
79 enabled=PLC_${server}_ENABLED
80 if [ "${!enabled}" != "1" ] ; then
83 hostname=PLC_${server}_HOST
84 http_port=PLC_${server}_PORT
85 https_port=PLC_${server}_SSL_PORT
87 # # API should always be accessed via SSL
88 # if [ "$server" = "API" ] ; then
89 # https_port=${!http_port}
93 # Check if we are already listening on these ports
96 for previous_server in WWW API BOOT ; do
97 if [ "$server" = "$previous_server" ] ; then
100 previous_enabled=PLC_${previous_server}_ENABLED
101 if [ "${!previous_enabled}" != "1" ] ; then
104 previous_http_port=PLC_${previous_server}_PORT
105 previous_https_port=PLC_${previous_server}_SSL_PORT
107 if [ "${!http_port}" = "${!previous_http_port}" ] ; then
110 if [ "${!https_port}" = "${!previous_https_port}" ] ; then
116 if [ $skip_http -eq 0 -a -n "${!http_port}" ] ; then
119 <VirtualHost *:${!http_port}>
120 # Make sure that the admin web pages are always accessed via SSL
121 Redirect /db https://$PLC_WWW_HOST:$PLC_WWW_SSL_PORT/db
122 Redirect /planetlab https://$PLC_WWW_HOST:$PLC_WWW_SSL_PORT/planetlab
123 # as a matter of fact most xmlrpc clients won't follow the redirection
124 # so this is mostly rethorical, but just in case...
125 Redirect /$PLC_API_PATH https://$PLC_WWW_HOST:$PLC_WWW_SSL_PORT/$PLC_API_PATH
130 # HTTPS configuration
131 if [ $skip_https -eq 0 -a -n "${!https_port}" ] ; then
132 # XXX Cannot support NameVirtualHost over SSL. If
133 # the API, boot, and web servers are all running
134 # on the same machine, the web server certificate
137 -e "s/^Listen .*/Listen ${!https_port}/" \
138 -e "s/<VirtualHost _default_:.*>/<VirtualHost _default_:${!https_port}>/" \
140 # this is used to locate the right certificates
141 server_lower=$(echo $server | tr 'A-Z' 'a-z')
143 # create wsgi socket where we have the permission
144 WSGISocketPrefix run/wsgi
146 <VirtualHost *:${!https_port}>
148 WSGIScriptAlias /$PLC_API_PATH /usr/share/plc_api/wsgi/plc.wsgi
149 # xxx would be cool to be able to tweak this through config
150 WSGIDaemonProcess plcapi-wsgi-ssl user=apache group=apache processes=1 threads=25
151 WSGIProcessGroup plcapi-wsgi-ssl
155 SSLCertificateFile /etc/planetlab/${server_lower}_ssl.crt
156 SSLCertificateKeyFile /etc/planetlab/${server_lower}_ssl.key
157 SSLCertificateChainFile /etc/planetlab/${server_lower}_ca_ssl.crt
164 # Set custom Apache directives
166 # could be restricted to boot boxes but harmless..
168 AddType application/octet-stream .iso
169 AddType application/octet-stream .usb
171 # make sure /PLCAPI can't get accessed if API not enabled here
172 if [ "$PLC_API_ENABLED" != "1" ] ; then
175 <Location $PLC_API_PATH>
181 # redirect www requests if not on the right server
182 if [ "$PLC_WWW_ENABLED" != "1" ] ; then
184 Redirect /index.html http://$PLC_WWW_HOST:$PLC_WWW_PORT/
189 # Make alpina-logs directory writable for bootmanager log upload
190 chown apache:apache $DocumentRoot/alpina-logs/nodes
192 # Make the Drupal files upload directory owned by Apache
193 mkdir -p $DocumentRoot/files
194 chown apache:apache $DocumentRoot/files
196 # Symlink any (real) files or directories in
197 # /data/var/www/html/* to /var/www/html/. We could descend
198 # into subdirectories, but the code to do so properly would be
200 for file in /data/$DocumentRoot/* ; do
201 if [ -e "$file" -a ! -h "$file" ] ; then
202 base=$(basename "$file")
203 if [ ! -e "$DocumentRoot/$base" ] ; then
204 ln -nsf "$file" "$DocumentRoot/$base"
209 # Cleanup broken symlinks
210 for file in $DocumentRoot/* ; do
211 if [ -h "$file" -a ! -e "$file" ] ; then
216 # Old style PHP constants
217 mkdir -p /etc/planetlab/php
218 cat >/etc/planetlab/php/site_constants.php <<"EOF"
220 include('plc_config.php');
222 define('PL_API_SERVER', PLC_API_HOST);
223 define('PL_API_PATH', PLC_API_PATH);
224 define('PL_API_PORT', PLC_API_PORT);
225 define('PL_API_CAPABILITY_AUTH_METHOD', 'capability');
226 define('PL_API_CAPABILITY_PASS', PLC_API_MAINTENANCE_PASSWORD);
227 define('PL_API_CAPABILITY_USERNAME', PLC_API_MAINTENANCE_USER);
228 define('WWW_BASE', PLC_WWW_HOST);
229 define('BOOT_BASE', PLC_BOOT_HOST);
230 define('DEBUG', PLC_WWW_DEBUG);
231 define('API_CALL_DEBUG', PLC_API_DEBUG);
232 define('SENDMAIL', PLC_MAIL_ENABLED);
233 define('PLANETLAB_SUPPORT_EMAIL', PLC_NAME . ' Support <' . PLC_MAIL_SUPPORT_ADDRESS . '>');
234 define('PLANETLAB_SUPPORT_EMAIL_ONLY', PLC_MAIL_SUPPORT_ADDRESS);
240 sed -i -e 's,^memory_limit = 32M *;,memory_limit = 80M ; patch myplc -- ,' $php_ini
241 # log_errors : is On by default
243 if ! grep '^error_log *=' $php_ini > /dev/null ; then
244 echo 'error_log = /var/log/php.log' >> $php_ini
245 touch /var/log/php.log
246 chmod 666 /var/log/php.log
256 MESSAGE=$"Stopping web server"