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.

92 lines
2.1 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. [ "$_BOOT" = "1" ] &&
  27. [ "$(procd_get_mountpoints $pgdata)" ] && return 0
  28. fix_perms
  29. fix_hosts
  30. if [ ! -e "${pgdata}/PG_VERSION" ]; then
  31. pg_init_data ${pgdata}
  32. [ $? -gt 0 ] && return 1
  33. fi
  34. cleanup "${pgdata}"
  35. mkdir -m 0755 -p /var/run/postgresql
  36. chmod 0750 /var/run/postgresql
  37. chown postgres:postgres /var/run/postgresql
  38. procd_open_instance postmaster
  39. procd_set_param user postgres
  40. procd_set_param command $PROG
  41. procd_append_param command -D "${pgdata}"
  42. procd_append_param command -k "/var/run/postgresql"
  43. [ -n "${pgopts}" ] && procd_append_param command -o "${pgopts}"
  44. procd_set_param respawn retry=60
  45. procd_add_jail postgresql log
  46. procd_add_jail_mount /usr/lib/postgresql /usr/share/postgresql
  47. procd_add_jail_mount_rw /var/run/postgresql "${pgdata}"
  48. procd_add_jail_mount_rw /dev/shm
  49. procd_set_param stderr 1
  50. procd_set_param stdout 1
  51. procd_close_instance
  52. procd_open_instance uci_dbinit
  53. procd_set_param user postgres
  54. procd_set_param command /lib/functions/postgresql.sh init "${pgdata}"
  55. procd_set_param stdout 1
  56. procd_set_param stderr 1
  57. procd_close_instance
  58. }
  59. boot() {
  60. _BOOT=1 start
  61. }
  62. service_triggers() {
  63. config_load "postgresql"
  64. config_get pgdata config PGDATA
  65. procd_add_restart_mount_trigger "${pgdata}"
  66. }
  67. stop_service() {
  68. procd_send_signal "postgresql" postmaster SIGTERM
  69. }
  70. status_service() {
  71. config_load "postgresql"
  72. config_get pgdata config PGDATA
  73. /usr/bin/pg_ctl status -U postgres -D "${pgdata}"
  74. }