prerm 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #
  2. # This script is executed in the pre-remove phase
  3. #
  4. # On Debian,
  5. # $1=remove : indicates a removal
  6. # $1=upgrade : indicates an upgrade
  7. #
  8. # On RedHat,
  9. # $1=0 : indicates a removal
  10. # $1=1 : indicates an upgrade
  11. # source the default env file
  12. if [ -f "${path.env}" ]; then
  13. . "${path.env}"
  14. fi
  15. export ES_PATH_CONF=${ES_PATH_CONF:-${path.conf}}
  16. STOP_REQUIRED=false
  17. REMOVE_SERVICE=false
  18. case "$1" in
  19. # Debian ####################################################
  20. remove)
  21. STOP_REQUIRED=true
  22. REMOVE_SERVICE=true
  23. ;;
  24. upgrade)
  25. if [ "$RESTART_ON_UPGRADE" = "true" ]; then
  26. STOP_REQUIRED=true
  27. fi
  28. ;;
  29. deconfigure|failed-upgrade)
  30. ;;
  31. # RedHat ####################################################
  32. 0)
  33. STOP_REQUIRED=true
  34. REMOVE_SERVICE=true
  35. ;;
  36. 1)
  37. # Dont do anything on upgrade, because the preun script in redhat gets executed after the postinst (madness!)
  38. ;;
  39. *)
  40. echo "pre remove script called with unknown argument \`$1'" >&2
  41. exit 1
  42. ;;
  43. esac
  44. # Stops the service
  45. if [ "$STOP_REQUIRED" = "true" ]; then
  46. echo -n "Stopping elasticsearch service..."
  47. if command -v systemctl >/dev/null; then
  48. systemctl --no-reload stop elasticsearch.service || true
  49. fi
  50. echo " OK"
  51. fi
  52. if [ -f "${ES_PATH_CONF}"/elasticsearch.keystore ]; then
  53. if md5sum --status -c "${ES_PATH_CONF}"/.elasticsearch.keystore.initial_md5sum; then
  54. rm "${ES_PATH_CONF}"/elasticsearch.keystore "${ES_PATH_CONF}"/.elasticsearch.keystore.initial_md5sum
  55. fi
  56. fi
  57. if [ "$REMOVE_SERVICE" = "true" ]; then
  58. if command -v systemctl >/dev/null; then
  59. systemctl disable elasticsearch.service > /dev/null 2>&1 || true
  60. fi
  61. fi
  62. ${scripts.footer}