Your IP : 216.73.216.81


Current Path : /var/lib/dpkg/info/
Upload File :
Current File : //var/lib/dpkg/info/elasticsearch.prerm

#!/bin/sh -e


#
# This script is executed in the pre-remove phase
#
#   On Debian,
#       $1=remove    : indicates a removal
#       $1=upgrade   : indicates an upgrade
#
#   On RedHat,
#       $1=0         : indicates a removal
#       $1=1         : indicates an upgrade

# source the default env file
if [ -f "/etc/default/elasticsearch" ]; then
    . "/etc/default/elasticsearch"
fi

export ES_PATH_CONF=${ES_PATH_CONF:-/etc/elasticsearch}

STOP_REQUIRED=false
REMOVE_SERVICE=false

case "$1" in

    # Debian ####################################################
    remove)
        STOP_REQUIRED=true
        REMOVE_SERVICE=true
    ;;
    upgrade)
        if [ "$RESTART_ON_UPGRADE" = "true" ]; then
            STOP_REQUIRED=true
        fi
    ;;
    deconfigure|failed-upgrade)
    ;;

    # RedHat ####################################################
    0)
        STOP_REQUIRED=true
        REMOVE_SERVICE=true
    ;;
    1)
        # Dont do anything on upgrade, because the preun script in redhat gets executed after the postinst (madness!)
    ;;

    *)
        echo "pre remove script called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# Stops the service
if [ "$STOP_REQUIRED" = "true" ]; then
    echo -n "Stopping elasticsearch service..."
    if command -v systemctl >/dev/null; then
        systemctl --no-reload stop elasticsearch.service

    elif [ -x /etc/init.d/elasticsearch ]; then
        if command -v invoke-rc.d >/dev/null; then
            invoke-rc.d elasticsearch stop
        else
            /etc/init.d/elasticsearch stop
        fi

    # older suse linux distributions do not ship with systemd
    # but do not have an /etc/init.d/ directory
    # this tries to start the elasticsearch service on these
    # as well without failing this script
    elif [ -x /etc/rc.d/init.d/elasticsearch ] ; then
        /etc/rc.d/init.d/elasticsearch stop
    fi
    echo " OK"
fi

if [ -f "${ES_PATH_CONF}"/elasticsearch.keystore ]; then
  if md5sum --status -c "${ES_PATH_CONF}"/.elasticsearch.keystore.initial_md5sum; then
    rm "${ES_PATH_CONF}"/elasticsearch.keystore "${ES_PATH_CONF}"/.elasticsearch.keystore.initial_md5sum
  fi
fi

if [ "$REMOVE_SERVICE" = "true" ]; then
    if command -v systemctl >/dev/null; then
        systemctl disable elasticsearch.service > /dev/null 2>&1 || true
    fi

    if command -v chkconfig >/dev/null; then
        chkconfig --del elasticsearch 2> /dev/null || true
    fi

    if command -v update-rc.d >/dev/null; then
        update-rc.d elasticsearch remove >/dev/null || true
    fi
fi

exit 0
# Built for packages-7.17.29 (deb)