postgresql.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. fw_depends databases
  3. RETCODE=$(fw_exists ${IROOT}/postgresql.installed)
  4. [ ! "$RETCODE" == 0 ] || { \
  5. source $IROOT/postgresql.installed
  6. return 0; }
  7. # delete any old required files that do not belong to us as
  8. # scp will fail otherwise
  9. ssh $DBHOST 'bash' <<EOF
  10. sudo rm -rf create-postgres-database.sql
  11. sudo rm -rf create-postgres.sql
  12. EOF
  13. # send over the required files
  14. scp $FWROOT/toolset/setup/linux/databases/postgresql/postgresql.conf $DBHOST:~/
  15. scp $FWROOT/toolset/setup/linux/databases/postgresql/pg_hba.conf $DBHOST:~/
  16. scp $FWROOT/toolset/setup/linux/databases/postgresql/60-postgresql-shm.conf $DBHOST:~/
  17. scp $FWROOT/toolset/setup/linux/databases/postgresql/create-postgres-database.sql $DBHOST:~/
  18. scp $FWROOT/toolset/setup/linux/databases/postgresql/create-postgres.sql $DBHOST:~/
  19. ssh $DBHOST 'bash' <<EOF
  20. # install postgresql on database machine
  21. sudo apt-get -y update
  22. sudo apt-get -y install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" postgresql
  23. # This will support all 9.* versions depending on the machine
  24. service postgresql status &> /dev/null && sudo service postgresql stop
  25. # Because postgresql...
  26. sudo killall -9 -u postgres
  27. # Make sure all the configuration files in main belong to postgres
  28. PG_VERSION=`pg_config --version | grep -oP '\d\.\d'`
  29. sudo mv postgresql.conf /etc/postgresql/\${PG_VERSION}/main/postgresql.conf
  30. sudo mv pg_hba.conf /etc/postgresql/\${PG_VERSION}/main/pg_hba.conf
  31. sudo chown -Rf postgres:postgres /etc/postgresql/\${PG_VERSION}/main
  32. sudo rm -rf /ssd/postgresql
  33. sudo cp -R -p /var/lib/postgresql/\${PG_VERSION}/main /ssd/postgresql
  34. sudo mv 60-postgresql-shm.conf /etc/sysctl.d/60-postgresql-shm.conf
  35. sudo chown postgres:postgres /etc/sysctl.d/60-postgresql-shm.conf
  36. sudo chown postgres:postgres create-postgres*
  37. service postgresql status &> /dev/null || sudo service postgresql start
  38. EOF
  39. echo -e "ssh \$DBHOST <<EOF" > $IROOT/postgresql.installed
  40. echo "sudo -u postgres psql -q template1 < create-postgres-database.sql" >> $IROOT/postgresql.installed
  41. echo "sudo -u postgres psql -q hello_world < create-postgres.sql" >> $IROOT/postgresql.installed
  42. echo "EOF" >> $IROOT/postgresql.installed
  43. source $IROOT/postgresql.installed