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.

75 lines
1.6 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2006-2015 OpenWrt.org
  3. START=50
  4. PROG=/usr/bin/postmaster
  5. USE_PROCD=1
  6. fix_hosts() {
  7. # make sure localhost (without a dot) is in /etc/hosts
  8. grep -q 'localhost$' /etc/hosts || echo '127.0.0.1 localhost' >> /etc/hosts
  9. }
  10. fix_perms() {
  11. # for whatever reason, /dev/null gets wrong perms
  12. chmod a+w /dev/null
  13. }
  14. cleanup() {
  15. if [ -f "$1/postmaster.pid" ]; then
  16. rm "$1/postmaster.pid"
  17. fi
  18. }
  19. start_service() {
  20. . /lib/functions/postgresql.sh
  21. config_load "postgresql"
  22. config_get pgdata config PGDATA
  23. config_get pgopts config PGOPTS
  24. user_exists postgres 5432 || user_add postgres 5432
  25. group_exists postgres 5432 || group_add postgres 5432
  26. fix_perms
  27. fix_hosts
  28. if [ ! -d "${pgdata}" ]; then
  29. pg_init_data ${pgdata}
  30. [ $? -gt 0 ] && return 1
  31. fi
  32. cleanup "${pgdata}"
  33. procd_open_instance
  34. procd_set_param user postgres
  35. procd_set_param command $PROG
  36. procd_append_param command -D "${pgdata}"
  37. [ -n "${pgopts}" ] && procd_append_param command -o "${pgopts}"
  38. procd_set_param respawn retry=60
  39. procd_close_instance
  40. procd_open_instance
  41. procd_set_param user postgres
  42. procd_set_param command /lib/functions/postgresql.sh init "${pgdata}"
  43. procd_close_instance
  44. }
  45. reload_service() {
  46. config_load "postgresql"
  47. config_get pgdata config PGDATA
  48. /usr/bin/pg_ctl reload -U postgres -D "${pgdata}" -s
  49. }
  50. stop_service() {
  51. config_load "postgresql"
  52. config_get pgdata config PGDATA
  53. /usr/bin/pg_ctl stop -U postgres -D "${pgdata}" -s
  54. }
  55. status_service() {
  56. config_load "postgresql"
  57. config_get pgdata config PGDATA
  58. /usr/bin/pg_ctl status -U postgres -D "${pgdata}"
  59. }