# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: postgresql,v 1.4.2.3 2006/08/21 21:21:12 mlhuang Exp $
+# $Id: postgresql,v 1.11 2007/02/05 19:11:06 mlhuang Exp $
#
# Source function library and configuration
# 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
# Create the databases if necessary
if ! psql -U $PLC_DB_USER -c "" $PLC_DB_NAME >/dev/null 2>&1 ; then
- createdb -U postgres $PLC_DB_NAME
+ createdb -U postgres --encoding=UNICODE --owner=$PLC_DB_USER $PLC_DB_NAME
psql -U $PLC_DB_USER -f /usr/share/plc_api/$PLC_DB_NAME.sql $PLC_DB_NAME
fi
check
# Shut down the server
service postgresql stop
- check
+
+ # /etc/init.d/postgresql fails if it is not running
+ [ "$PLC_DB_ENABLED" = 1 ] && check
result "$MESSAGE"
;;