propset - enables svn keywords
[myplc.git] / plc.d / postgresql
index c16f152..f5ad0d0 100755 (executable)
@@ -7,12 +7,13 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: postgresql,v 1.9 2007/01/19 16:42:08 mlhuang Exp $
+# $Id$
 #
 
 # Source function library and configuration
 . /etc/plc.d/functions
 . /etc/planetlab/plc_config
+local_config=/etc/planetlab/configs/site.xml
 
 # Be verbose
 set -x
@@ -29,7 +30,7 @@ export PGPORT=$PLC_DB_PORT
 postgresql_start ()
 {
     # start() always returns 0
-    service postgresql start
+    (exec 3>&- 4>&- ; service postgresql start)
 
     # status() will still return 0 even while still initializing
     if status postmaster && [ -f /var/lock/subsys/postgresql ] ; then
@@ -90,18 +91,25 @@ case "$1" in
        # Enable passwordless localhost access
        echo "local all all trust" >>$pghba_conf
 
-       # Enable access from the API and web servers
+       # Enable access from the API, boot, and web servers
        PLC_API_IP=$(gethostbyname $PLC_API_HOST)
+       PLC_BOOT_IP=$(gethostbyname $PLC_BOOT_HOST)
        PLC_WWW_IP=$(gethostbyname $PLC_WWW_HOST)
        (
            echo "host $PLC_DB_NAME $PLC_DB_USER 127.0.0.1/32 password"
            echo "host $PLC_DB_NAME $PLC_DB_USER $PLC_API_IP/32 password"
+           echo "host $PLC_DB_NAME $PLC_DB_USER $PLC_BOOT_IP/32 password"
            echo "host $PLC_DB_NAME $PLC_DB_USER $PLC_WWW_IP/32 password"
            # Drupal also uses PostgreSQL
            echo "host drupal $PLC_DB_USER 127.0.0.1/32 password"
            echo "host drupal $PLC_DB_USER $PLC_WWW_IP/32 password"
        ) >>$pghba_conf
 
+       # Append site-specific access rules
+       for file in $pghba_conf.d/*.conf ; do
+           cat "$file" >>$pghba_conf
+       done
+
        # Fix ownership (sed -i changes it)
        chown postgres:postgres $postgresql_conf $pghba_conf
 
@@ -112,7 +120,8 @@ case "$1" in
        # Create/update the unprivileged database user and password
        if [ -z "$PLC_DB_PASSWORD" ] ; then
            PLC_DB_PASSWORD=$(uuidgen)
-           plc-config --category=plc_db --variable=password --value="$PLC_DB_PASSWORD" --save
+           plc-config --category=plc_db --variable=password --value="$PLC_DB_PASSWORD" --save=$local_config $local_config
+           service plc reload
        fi
        if ! psql -U $PLC_DB_USER -c "" template1 >/dev/null 2>&1 ; then
            psql -U postgres -c "CREATE USER $PLC_DB_USER PASSWORD '$PLC_DB_PASSWORD'" template1