#!/bin/bash # removing the database cluster if it exists and prepping everything for posgresql operation # be careful, Will Robinson! # we need to be root for this if [[ `whoami` != 'root' ]]; then echo "we need to be root for this, quitting" exit 1 fi # work the directories # - log mkdir -p /var/log/postgresql chown -R postgres:postgres /var/log/postgresql chmod -R 0700 /var/log/postgresql # - data mkdir -p /var/lib/postgresql cd /var/lib/postgresql chown -R postgres:postgres ./ chmod -R 0700 ./ # do we need to init the db? if [ ! -e /var/lib/postgresql/9.3/main ]; then # initdb as postgres su -c '/usr/lib/postgresql/9.3/bin/initdb /var/lib/postgresql/9.3/main' postgres # config echo " listen_addresses='*' log_destination = 'stderr' logging_collector = on log_directory = '/var/log/postgresql' log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' log_file_mode = 0600 log_rotation_age = 1d log_rotation_size = 10MB log_connections = on log_hostname = on log_timezone = 'UTC' " >> /var/lib/postgresql/9.3/main/postgresql.conf # auth # TODO: this needs to be much mroe specific for production! echo "host all all `hostname -I | sed 's/ //g'`/16 trust" >> /var/lib/postgresql/9.3/main/pg_hba.conf # # create the needed databases # /etc/init.d/postgresql start # run the SQL su -c 'psql < /var/lib/setup.sql' postgres # we're done /etc/init.d/postgresql stop fi # run postgres as user postgres su -c '/usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main' postgres