-# http://docs.fedoraproject.org/en-US/Fedora/16/html/Release_Notes/sect-Release_Notes-Changes_for_Sysadmin.html
- if type postgresql-setup >& /dev/null ; then
- postgresql-setup initdb || :
- check
- else
- service postgresql initdb &> /dev/null || postgresql :
- check
- fi
- fi
-
- ######## /var/lib/pgsql/data/postgresql.conf
- # Enable DB server. drop Postgresql<=7.x
- # PostgreSQL >=8.0 defines listen_addresses
- # listen on a specific IP + localhost, more robust when run within a vserver
- sed -i -e '/^listen_addresses/d' $postgresql_conf
- echo "listen_addresses = '${PLC_DB_HOST},localhost'" >> $postgresql_conf
- # tweak timezone to be 'UTC'
- sed -i -e '/^timezone=/d' $postgresql_conf
- echo "timezone='UTC'" >> $postgresql_conf
-
- ######## /var/lib/pgsql/data/pg_hba.conf
- # Disable access to MyPLC and drupal DBs from all hosts
- sed -i -e '/^\(host\|local\)/d' $pghba_conf
-
- # Enable passwordless localhost access
- echo "local all all trust" >>$pghba_conf
-
- # 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)
- 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"
- 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
-
- ######## Start up the server - ignore retcod and check this our way
- (exec 3>&- 4>&- ; service postgresql start)
- postgresql_check
- check
-
- ######## 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=$local_config $local_config
+# http://docs.fedoraproject.org/en-US/Fedora/16/html/Release_Notes/sect-Release_Notes-Changes_for_Sysadmin.html
+ if type postgresql-setup >& /dev/null ; then
+ postgresql-setup initdb || :
+ check
+ else
+ sudo postgresql-setup --initdb --unit postgresql &> /dev/null || postgresql :
+ check
+ fi
+ fi
+
+ ######## /var/lib/pgsql/data/postgresql.conf
+ # Enable DB server. drop Postgresql<=7.x
+ # PostgreSQL >=8.0 defines listen_addresses
+ # listen on a specific IP + localhost, more robust when run within a vserver
+ sed -i -e '/^listen_addresses/d' $postgresql_conf
+ echo "listen_addresses = '${PLC_DB_HOST},localhost'" >> $postgresql_conf
+ # tweak timezone to be 'UTC'
+ sed -i -e '/^timezone=/d' $postgresql_conf
+ echo "timezone='UTC'" >> $postgresql_conf
+
+ ######## /var/lib/pgsql/data/pg_hba.conf
+ # Disable access to MyPLC and drupal DBs from all hosts
+ sed -i -e '/^\(host\|local\)/d' $pghba_conf
+
+ # Enable passwordless localhost access
+ echo "local all all trust" >>$pghba_conf
+
+ # 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)
+ 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"
+ 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
+
+ ######## Start up the server - ignore retcod and check this our way
+ (exec 3>&- 4>&- ; systemctl start postgresql)
+ postgresql_check
+ check
+
+ ######## 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=$local_config $local_config