X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plc.d%2Fpostgresql;h=f4c20931254667044f0cb7b31f72808fbc659097;hb=00ce026d1b2662f9579ed5b2a5589c670e000285;hp=18ca08170aa13a46b7e63819d205d0c38e5731ec;hpb=ca2f6a3d5be100ef9fffa1700ec9141bb76988be;p=myplc.git diff --git a/plc.d/postgresql b/plc.d/postgresql index 18ca081..f4c2093 100755 --- a/plc.d/postgresql +++ b/plc.d/postgresql @@ -7,12 +7,13 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id: postgresql,v 1.11 2007/02/05 19:11:06 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 @@ -45,13 +46,19 @@ postgresql_start () return 1 } +postgresql_init () +{ + service postgresql initdb &> /dev/null || : + postgresql_start +} + case "$1" in start) if [ "$PLC_DB_ENABLED" != "1" ] ; then exit 0 fi - MESSAGE=$"Starting database server" + MESSAGE=$"Starting PostgreSQL server" dialog "$MESSAGE" # Set data directory and redirect startup output to /var/log/pgsql @@ -68,7 +75,7 @@ case "$1" in # PostgreSQL must be started at least once to bootstrap # /var/lib/pgsql/data if [ ! -f $postgresql_conf ] ; then - postgresql_start + postgresql_init check service postgresql stop check @@ -94,6 +101,27 @@ case "$1" in PLC_API_IP=$(gethostbyname $PLC_API_HOST) PLC_BOOT_IP=$(gethostbyname $PLC_BOOT_HOST) PLC_WWW_IP=$(gethostbyname $PLC_WWW_HOST) + ip_failure=0 + if [ -z "$PLC_API_IP" ] ; then + MESSAGE=$"PLC_API_IP is not set" + dialog "$MESSAGE" + ip_failure=1 + fi + if [ -z "$PLC_BOOT_IP" ] ; then + MESSAGE=$"PLC_BOOT_IP is not set" + dialog "$MESSAGE" + ip_failure=1 + fi + if [ -z "$PLC_WWW_IP" ] ; then + MESSAGE=$"PLC_WWW_IP is not set" + dialog "$MESSAGE" + ip_failure=1 + fi + if [ $ip_failure -eq 1 ] ; then + /bin/false + check + fi + ( 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" @@ -119,7 +147,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 @@ -136,7 +165,7 @@ case "$1" in check if ! psql -U $PLC_DB_USER -c "" drupal >/dev/null 2>&1 ; then createdb -U postgres --encoding=UNICODE --owner=$PLC_DB_USER drupal - psql -U $PLC_DB_USER -f /var/www/html/database/database.pgsql drupal + psql -U $PLC_DB_USER -f /var/www/html/database/database.pgsql drupal fi check @@ -144,7 +173,7 @@ case "$1" in ;; stop) - MESSAGE=$"Stopping database server" + MESSAGE=$"Stopping PostgreSQL server" dialog "$MESSAGE" # Drop the current user in case the username changes