finish 850 B

12345678910111213141516171819202122232425262728293031
  1. #!/command/with-contenv bash
  2. EXIT_CODE="$1"
  3. EXIT_SIGNAL="$2"
  4. SCRIPT_ROOT=/etc/s6-overlay/scripts
  5. source "$SCRIPT_ROOT/base.sh"
  6. # The config should be ready before starting
  7. if [ -f "$GPUSTACK_POSTGRES_CONFIG" ]; then
  8. source "$GPUSTACK_POSTGRES_CONFIG"
  9. fi
  10. source "$SCRIPT_ROOT/default-variables.sh"
  11. PGDATA="${POSTGRES_DATA_DIR}"
  12. echo "[INFO] PostgreSQL service is stopping..."
  13. if [ -f "$PGDATA/postmaster.pid" ]; then
  14. echo "[ERROR] Gracefully shutting down PostgreSQL..."
  15. gosu postgres pg_ctl -D "$PGDATA" -m fast stop || \
  16. gosu postgres pg_ctl -D "$PGDATA" -m immediate stop
  17. sleep 2
  18. fi
  19. if [ -f "$PGDATA/postmaster.pid" ]; then
  20. echo "[ERROR] PostgreSQL did not exit cleanly. Forcing immediate shutdown."
  21. gosu postgres pg_ctl -D "$PGDATA" -m immediate stop
  22. fi
  23. handleServiceExit "postgres" "$EXIT_CODE" "$EXIT_SIGNAL"