#!/bin/bash
#
-# priority: 800
+# priority: 450
#
-# Bootstrap the database
+# Configure the API. Must be done after SSL certificates are generated
+# and before the API web server is brought up.
#
# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: api,v 1.1 2006/04/06 21:51:59 mlhuang Exp $
+# $Id: api,v 1.4 2006/06/23 21:41:31 mlhuang Exp $
#
# Source function library and configuration
. /etc/plc.d/functions
+. /etc/planetlab/plc_config
-# Export so that we do not have to specify -p to psql invocations
-export PGPORT=$PLC_DB_PORT
+# Be verbose
+set -x
case "$1" in
start)
exit 0
fi
- MESSAGE=$"Bootstrapping the database"
+ MESSAGE=$"Configuring the API"
dialog "$MESSAGE"
- # Update the maintenance account username. This can't be
- # done through the api-config script since it uses the
- # maintenance account to access the API. The maintenance
- # account should be person_id 1 since it is created by the
- # DB schema itself.
- psql -U $PLC_DB_USER -c "UPDATE persons SET email='$PLC_API_MAINTENANCE_USER' WHERE person_id=1" $PLC_DB_NAME
+ # Generate old DB configuration file
+ ln -sf plc_config /etc/planetlab/plc_db
- # Bootstrap the DB
+ # Make sure that the API maintenance account is protected by a
+ # password.
+ if [ -z "$PLC_API_MAINTENANCE_PASSWORD" ] ; then
+ PLC_API_MAINTENANCE_PASSWORD=$(uuidgen)
+ plc-config --category=plc_api --variable=maintenance_password --value="$PLC_API_MAINTENANCE_PASSWORD" --save
+ fi
+
+ # Make sure that all PLC servers are allowed to access the API
+ # through the maintenance account.
+ PLC_API_MAINTENANCE_SOURCES=$(
+ for server in API BOOT WWW ; do
+ hostname=PLC_${server}_HOST
+ gethostbyname ${!hostname}
+ done | sort -u
+ )
+ plc-config --category=plc_api --variable=maintenance_sources --value="$PLC_API_MAINTENANCE_SOURCES" --save
+
+ # Generate old API configuration file
api-config
check