You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.2 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2006 OpenWrt.org
  3. START=50
  4. EXTRA_COMMANDS="status reload"
  5. config_load "postgresql"
  6. config_get pgdata config PGDATA
  7. config_get pguser config PGUSER
  8. config_get pgctl config PG_CTL
  9. config_get pglog config PGLOG
  10. start() {
  11. if [ ! -e /usr/bin/su ]; then
  12. echo "The su command is requred to run postgres"
  13. exit 1
  14. fi
  15. if [ ! -d ${pgdata} ]; then
  16. echo "Create the data directory (${pgdata}) and try again"
  17. exit 1
  18. fi
  19. echo "starting postgres..."
  20. # make sure localhost (without a dot) is in /etc/hosts
  21. grep -q 'localhost$' /etc/hosts || echo '127.0.0.1 localhost' >> /etc/hosts
  22. # for whatever reason, /dev/null gets wrong perms
  23. chmod a+w /dev/null
  24. if [ -f ${pgdata}/postmaster.pid ]; then
  25. rm ${pgdata}/postmaster.pid
  26. fi
  27. config_get pgopts config PGOPTS
  28. if [ -n "${pgopts}" ]; then
  29. pgopts="-o ${pgopts}"
  30. fi
  31. /usr/bin/su ${pguser} -c "/usr/bin/postmaster -D '${pgdata}' &" >> ${pglog} 2>&1
  32. while :
  33. do
  34. cnt=$((${cnt} + 1))
  35. if [ -f "${pgdata}/postmaster.pid" ]; then
  36. ret=0
  37. break
  38. fi
  39. if [ ${cnt} -eq 30 ]; then
  40. echo "Postgres failed to start. See ${pglog} for details"
  41. ret=1
  42. break
  43. fi
  44. sleep 1
  45. done
  46. echo "ok"
  47. return ${ret}
  48. }
  49. stop() {
  50. echo "stopping postgres..."
  51. /usr/bin/su ${pguser} -c "${pgctl} stop -D '${pgdata}' -s -m fast"
  52. ret=$?
  53. if [ -f ${pgdata}/postmaster.pid ]; then
  54. rm ${pgdata}/postmaster.pid
  55. fi
  56. echo "ok"
  57. return ${ret}
  58. }
  59. restart() {
  60. echo "restarting postgres..."
  61. /usr/bin/su ${pguser} -c "${pgctl} stop -D '${pgdata}' -s -m fast -w"
  62. if [ -f ${pgdata}/postmaster.pid ]; then
  63. rm ${pgdata}/postmaster.pid
  64. fi
  65. /usr/bin/su ${pguser} -c "/usr/bin/postmaster -D '${pgdata}' &" >> ${pglog} 2>&1
  66. echo "ok"
  67. return $?
  68. }
  69. reload() {
  70. echo "reloading postgres..."
  71. /usr/bin/su ${pguser} -c "${pgctl} reload -D '${pgdata}' -s"
  72. echo "ok"
  73. }
  74. status() {
  75. echo "status postgres..."
  76. /usr/bin/su ${pguser} -c "${pgctl} status -D '${pgdata}'"
  77. echo "ok"
  78. }