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.

73 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. 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. config_load "postgresql"
  23. config_get pgdata config PGDATA
  24. config_get pguser config PGUSER
  25. config_get pgctl config PG_CTL
  26. config_get pgopts config PGOPTS
  27. user_exists postgres 5432 || user_add postgres 5432
  28. group_exists postgres 5432 || group_add postgres 5432
  29. if [ ! -d "${pgdata}" ]; then
  30. echo "Create the data directory (${pgdata}) and try again"
  31. return 1
  32. fi
  33. fix_perms
  34. fix_hosts
  35. procd_open_instance
  36. procd_set_param user ${pguser}
  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. }
  43. reload_service() {
  44. config_load "postgresql"
  45. config_get pgdata config PGDATA
  46. config_get pguser config PGUSER
  47. config_get pgctl config PG_CTL
  48. ${pgctl} reload -U ${pguser} -D '${pgdata}' -s
  49. }
  50. status() {
  51. config_load "postgresql"
  52. config_get pgdata config PGDATA
  53. config_get pguser config PGUSER
  54. config_get pgctl config PG_CTL
  55. echo "status postgres..."
  56. ${pgctl} status -U ${pguser} -D '${pgdata}'
  57. echo "ok"
  58. }