#!/bin/bash # # priority: 700 # # Configure Apache web server # # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # # $Id: httpd,v 1.7 2006/10/30 22:38:22 mlhuang Exp $ # # Source function library and configuration . /etc/plc.d/functions . /etc/planetlab/plc_config # Be verbose set -x # Default locations DocumentRoot=/var/www/html php_ini=/etc/php.ini httpd_conf=/etc/httpd/conf/httpd.conf ssl_conf=/etc/httpd/conf.d/ssl.conf plc_conf=/etc/httpd/conf.d/plc.conf case "$1" in start) if [ "$PLC_API_ENABLED" != "1" -a \ "$PLC_BOOT_ENABLED" != "1" -a \ "$PLC_WWW_ENABLED" != "1" ] ; then exit 0 fi MESSAGE=$"Starting web server" dialog "$MESSAGE" # Set the default include path include_path=".:$DocumentRoot/planetlab/includes:$DocumentRoot/generated:/etc/planetlab/php:/usr/share/plc_api/php" sed -i -e "s@[;]*include_path = \"\.:.*\"@include_path = \"$include_path\"@" $php_ini # Disable default Listen directive sed -i -e '/^Listen/d' $httpd_conf # Set the port numbers for server in WWW API BOOT ; do enabled=PLC_${server}_ENABLED if [ "${!enabled}" != "1" ] ; then continue fi hostname=PLC_${server}_HOST http_port=PLC_${server}_PORT https_port=PLC_${server}_SSL_PORT # API should always be accessed via SSL if [ "$server" = "API" ] ; then https_port=${!http_port} http_port= fi # Check if we are already listening on these ports skip_http=0 skip_https=0 for previous_server in WWW API BOOT ; do if [ "$server" = "$previous_server" ] ; then break fi previous_hostname=PLC_${previous_server}_HOST previous_http_port=PLC_${previous_server}_PORT previous_https_port=PLC_${previous_server}_SSL_PORT if [ "${!http_port}" = "${!previous_http_port}" ] ; then skip_http=1 fi if [ "${!https_port}" = "${!previous_https_port}" ] ; then skip_https=1 fi done # Listen on these ports if [ $skip_http -eq 0 -a -n "${!http_port}" ] ; then cat < Redirect /db https://$PLC_WWW_HOST:$PLC_WWW_SSL_PORT/db Redirect /$PLC_API_PATH https://$PLC_API_HOST:$PLC_API_PORT/$PLC_API_PATH EOF fi if [ $skip_https -eq 0 -a -n "${!https_port}" ] ; then # XXX Cannot support NameVirtualHost over SSL. If # the API, boot, and web servers are all running # on the same machine, the web server certificate # takes precedence. sed -i \ -e "s/^Listen .*/Listen ${!https_port}/" \ -e "s///" \ $ssl_conf fi done >$plc_conf # Set custom Apache directives ( if [ "$PLC_API_ENABLED" = "1" ] ; then cat < SetHandler mod_python PythonPath "sys.path + ['/usr/share/plc_api']" PythonHandler ModPython EOF else cat < Deny from all EOF fi if [ "$PLC_WWW_ENABLED" != "1" ] ; then cat < Deny from all EOF fi ) >>$plc_conf # Make alpina-logs directory writable for bootmanager log upload chown apache:apache $DocumentRoot/alpina-logs/nodes # Make the Drupal files upload directory owned by Apache mkdir -p $DocumentRoot/files chown apache:apache $DocumentRoot/files # Old style PHP constants mkdir -p /etc/planetlab/php cat >/etc/planetlab/php/site_constants.php <<"EOF" '); define('PLANETLAB_SUPPORT_EMAIL_ONLY', PLC_MAIL_SUPPORT_ADDRESS); ?> EOF plc_daemon httpd check result "$MESSAGE" ;; stop) MESSAGE=$"Stopping web server" dialog "$MESSAGE" killproc plc_httpd check result "$MESSAGE" ;; esac exit $ERRORS