7 # Configure Apache web server
9 # Mark Huang <mlhuang@cs.princeton.edu>
10 # Copyright (C) 2006 The Trustees of Princeton University
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
27 function disable_file () {
29 [ -f $file ] && mv -f $file $file.disabled
31 function enable_file () {
33 [ ! -f $file ] && mv -f $file.disabled $file
38 if [ "$PLC_API_ENABLED" != "1" -a \
39 "$PLC_BOOT_ENABLED" != "1" -a \
40 "$PLC_WWW_ENABLED" != "1" ] ; then
44 MESSAGE=$"Starting web server"
47 # set document root - not really useful on fedora but just in case
48 sed -i -e "s@^DocumentRoot.*@DocumentRoot \"$DocumentRoot\"@" $httpd_conf
49 # whether WWW is enabled or not :
50 if [ "$PLC_WWW_ENABLED" != "1" ] ; then
51 # avoid hitting drupal, that would try to connect to the db and create noise
52 disable_file $DocumentRoot/index.php
54 enable_file $DocumentRoot/index.php
57 # Set the default include path
58 include_path=".:$DocumentRoot/planetlab/includes:$DocumentRoot/plekit/php:$DocumentRoot/generated:/etc/planetlab/php:/usr/share/plc_api/php"
59 sed -i -e "s@[;]*include_path = \"\.:.*\"@include_path = \"$include_path\"@" $php_ini
61 # for php-5.3 under fedora12, otherwise issues tons of warning messages
62 # Set timezone in php.ini if not already there
63 if grep '^;date.timezone' $php_ini >& /dev/null; then
64 dialog 'Setting PHP timezone to GMT'
65 sed -i -e 's,^;date.timezone.*,date.timezone = GMT,' $php_ini
68 if grep '^short_open_tag = Off' $php_ini >& /dev/null; then
69 sed -i -e 's,^short_open_tag = Off,short_open_tag = On,' $php_ini
72 # Disable default Listen directive
73 sed -i -e '/^Listen/d' $httpd_conf
75 # Set the port numbers
76 for server in WWW API BOOT ; do
77 enabled=PLC_${server}_ENABLED
78 if [ "${!enabled}" != "1" ] ; then
81 hostname=PLC_${server}_HOST
82 http_port=PLC_${server}_PORT
83 https_port=PLC_${server}_SSL_PORT
85 # API should always be accessed via SSL
86 if [ "$server" = "API" ] ; then
87 https_port=${!http_port}
91 # Check if we are already listening on these ports
94 for previous_server in WWW API BOOT ; do
95 if [ "$server" = "$previous_server" ] ; then
98 previous_enabled=PLC_${previous_server}_ENABLED
99 if [ "${!previous_enabled}" != "1" ] ; then
102 previous_http_port=PLC_${previous_server}_PORT
103 previous_https_port=PLC_${previous_server}_SSL_PORT
105 if [ "${!http_port}" = "${!previous_http_port}" ] ; then
108 if [ "${!https_port}" = "${!previous_https_port}" ] ; then
113 # Create a separate path for mod_wsgi until we are ready to replace
115 PLC_API_WSGI_PATH=/PLCAPIWSGI
118 if [ $skip_http -eq 0 -a -n "${!http_port}" ] ; then
120 Listen 127.0.0.1:${!http_port}
122 # create wsgi socket where we have the permission
123 ### WSGISocketPrefix run/wsgi
124 # Make sure that the admin web pages and API are always accessed via SSL
125 <VirtualHost *:${!http_port}>
126 Redirect /db https://$PLC_WWW_HOST:$PLC_WWW_SSL_PORT/db
127 Redirect /planetlab https://$PLC_WWW_HOST:$PLC_WWW_SSL_PORT/planetlab
128 Redirect /$PLC_API_PATH https://$PLC_API_HOST:$PLC_API_PORT/$PLC_API_PATH
129 ### Redirect /$PLC_API_WSGI_PATH/ https://$PLC_API_HOST:$PLC_API_PORT/$PLC_API_WSGI_PATH/
130 ### WSGIScriptAlias $PLC_API_WSGI_PATH /usr/share/plc_api/ModWSGI.wsgi
131 # XX make processes and threads configurable
132 ### WSGIDaemonProcess plcapi-wsgi user=apache group=apache processes=1 threads=25
133 ### WSGIProcessGroup plcapi-wsgi
138 # HTTPS configuration
139 if [ $skip_https -eq 0 -a -n "${!https_port}" ] ; then
140 # XXX Cannot support NameVirtualHost over SSL. If
141 # the API, boot, and web servers are all running
142 # on the same machine, the web server certificate
145 -e "s/^Listen .*/Listen ${!https_port}/" \
146 -e "s/<VirtualHost _default_:.*>/<VirtualHost _default_:${!https_port}>/" \
151 # Set custom Apache directives
153 if [ "$PLC_API_ENABLED" = "1" ] ; then
155 # mod_python location
156 <Location $PLC_API_PATH>
157 SetHandler mod_python
158 PythonPath "sys.path + ['/usr/share/plc_api']"
159 PythonHandler ModPython
163 ### <Location $PLC_API_WSGI_PATH/>
164 ### SetHandler mod_wsgi
169 # mod_python location
170 <Location $PLC_API_PATH>
175 ### <Location $PLC_API_WSGI_PATH/>
181 if [ "$PLC_WWW_ENABLED" != "1" ] ; then
183 Redirect /index.html http://$PLC_WWW_HOST:$PLC_WWW_PORT/
187 AddType application/octet-stream .iso
188 AddType application/octet-stream .usb
192 # Make alpina-logs directory writable for bootmanager log upload
193 chown apache:apache $DocumentRoot/alpina-logs/nodes
195 # Make the Drupal files upload directory owned by Apache
196 mkdir -p $DocumentRoot/files
197 chown apache:apache $DocumentRoot/files
199 # Symlink any (real) files or directories in
200 # /data/var/www/html/* to /var/www/html/. We could descend
201 # into subdirectories, but the code to do so properly would be
203 for file in /data/$DocumentRoot/* ; do
204 if [ -e "$file" -a ! -h "$file" ] ; then
205 base=$(basename "$file")
206 if [ ! -e "$DocumentRoot/$base" ] ; then
207 ln -nsf "$file" "$DocumentRoot/$base"
212 # Cleanup broken symlinks
213 for file in $DocumentRoot/* ; do
214 if [ -h "$file" -a ! -e "$file" ] ; then
219 # Old style PHP constants
220 mkdir -p /etc/planetlab/php
221 cat >/etc/planetlab/php/site_constants.php <<"EOF"
223 include('plc_config.php');
225 define('PL_API_SERVER', PLC_API_HOST);
226 define('PL_API_PATH', PLC_API_PATH);
227 define('PL_API_PORT', PLC_API_PORT);
228 define('PL_API_CAPABILITY_AUTH_METHOD', 'capability');
229 define('PL_API_CAPABILITY_PASS', PLC_API_MAINTENANCE_PASSWORD);
230 define('PL_API_CAPABILITY_USERNAME', PLC_API_MAINTENANCE_USER);
231 define('WWW_BASE', PLC_WWW_HOST);
232 define('BOOT_BASE', PLC_BOOT_HOST);
233 define('DEBUG', PLC_WWW_DEBUG);
234 define('API_CALL_DEBUG', PLC_API_DEBUG);
235 define('SENDMAIL', PLC_MAIL_ENABLED);
236 define('PLANETLAB_SUPPORT_EMAIL', PLC_NAME . ' Support <' . PLC_MAIL_SUPPORT_ADDRESS . '>');
237 define('PLANETLAB_SUPPORT_EMAIL_ONLY', PLC_MAIL_SUPPORT_ADDRESS);
243 sed -i -e 's,^memory_limit = 32M *;,memory_limit = 80M ; patch myplc -- ,' $php_ini
244 # log_errors : is On by default
246 if ! grep '^error_log *=' $php_ini > /dev/null ; then
247 echo 'error_log = /var/log/php.log' >> $php_ini
248 touch /var/log/php.log
249 chmod 666 /var/log/php.log
259 MESSAGE=$"Stopping web server"