pgpool2.initd 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/sbin/openrc-run
  2. # Copyright 1999-2012 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. extra_started_commands="reload"
  5. CONFIGFILE="/etc/pgpool2/pgpool.conf"
  6. LOGFILE="/var/log/pgpool2.log"
  7. depend() {
  8. use net
  9. use postgresql
  10. after logger
  11. }
  12. get_config() {
  13. [ -f ${CONFIGFILE} ] || return 1
  14. eval echo $(sed -e 's:#.*::' ${CONFIGFILE} | \
  15. awk '$1 == "'$1'" { print ($2 == "=" ? $3 : $2) }')
  16. }
  17. PIDFILE="$(get_config pid_file_name)"
  18. : ${PIDFILE:='/run/pgpool/pgpool.pid'}
  19. prep() {
  20. # $logdir contains status file(s), not log files.
  21. local logdir=$(get_config logdir)
  22. local socket_dir=$(get_config socket_dir)
  23. local pcp_socket_dir=$(get_config pcp_socket_dir)
  24. checkpath -o pgpool:postgres -m 0770 -d $(dirname ${PIDFILE}) || return 1
  25. checkpath -o pgpool:postgres -m 0770 -d ${logdir:-'/run/pgpool'} || return 1
  26. checkpath -o pgpool:postgres -m 0660 -f ${LOGFILE} || return 1
  27. checkpath -o postgres:postgres -m 0770 \
  28. -d ${socket_dir:-'/run/postgresql'} || return 1
  29. checkpath -o postgres:postgres -m 0770 \
  30. -d ${pcp_socket_dir:-'/run/postgresql'} || return 1
  31. }
  32. start() {
  33. prep || return 1
  34. ebegin "Starting pgpool2"
  35. start-stop-daemon --start \
  36. --user pgpool:postgres \
  37. --pidfile ${PIDFILE} \
  38. --exec /usr/bin/pgpool
  39. eend
  40. }
  41. stop() {
  42. local seconds=$(( ${NICE_TIMEOUT} + ${RUDE_TIMEOUT} + ${FORCE_TIMEOUT} ))
  43. ebegin "Stopping pgpool (this can take up to ${seconds} seconds)"
  44. local retval
  45. local retries=SIGTERM/${NICE_TIMEOUT}
  46. if [ "${RUDE_QUIT}" != "NO" ] ; then
  47. einfo "RUDE_QUIT enabled."
  48. retries="${retries}/SIGINT/${RUDE_TIMEOUT}"
  49. fi
  50. if [ "${FORCE_QUIT}" = "YES" ] ; then
  51. einfo "FORCE_QUIT enabled."
  52. ewarn "A recover-run might be executed on next startup."
  53. retries="${retries}/SIGQUIT/${FORCE_TIMEOUT}"
  54. fi
  55. # Loops through nice, rude, and force quit in one go.
  56. start-stop-daemon --stop \
  57. --pidfile ${PIDFILE} \
  58. --retry ${retries}
  59. eend
  60. }
  61. reload() {
  62. start-stop-daemon --signal HUP \
  63. --pidfile ${PIDFILE}
  64. }