| # postgresql-setup Initialization operation for PostgreSQL |
| # For SELinux we need to use 'runuser' not 'su' |
| PGDATA=/var/lib/postgresql/data |
| PGLOG=/var/lib/postgresql/pgstartup.log |
| if [ -f "$PGDATA/PG_VERSION" ] |
| echo -n "Data directory is not empty!" |
| echo -n "Initializing database: " |
| if [ ! -e "$PGDATA" -a ! -h "$PGDATA" ] |
| mkdir -p "$PGDATA" || exit 1 |
| chown postgres:postgres "$PGDATA" |
| # Clean up SELinux tagging for PGDATA |
| [ -x /sbin/restorecon ] && /sbin/restorecon "$PGDATA" |
| # Make sure the startup-time log file is OK, too |
| if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ] |
| chown postgres:postgres "$PGLOG" |
| [ -x /sbin/restorecon ] && /sbin/restorecon "$PGLOG" |
| # Initialize the database |
| $SU -l postgres -c "$PGENGINE/initdb --pgdata='$PGDATA' --auth='ident'" >> "$PGLOG" 2>&1 < /dev/null |
| # Create directory for postmaster log |
| chown postgres:postgres "$PGDATA/pg_log" |
| chmod go-rwx "$PGDATA/pg_log" |
| if [ -f "$PGDATA/PG_VERSION" ] |