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.

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