postgresql.sh 2.1 KB

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