From b56afebad1e983221762691ae126ae8aa41b349e Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Sat, 17 Mar 2018 07:48:40 -0400 Subject: [PATCH] Fix creating keystore when upgrading (#29121) When upgrading via the RPM package, we can run into a problem where the keystore fails to be created. This arises because the %post script on RPM runs after the new package files are installed but before the removal of the old package files. This means that the contents of the lib folder can contain files from the old package and the new package and thus running the create keystore tool can encounter JAR hell issues and fail. To solve this, we move creating the keystore to the %posttrans script which runs after the old package files are removed. We only need to do this on the RPM package, so we add a switch in the shared post-install script. --- distribution/packages/build.gradle | 3 +++ distribution/packages/src/common/scripts/postinst | 7 ++++++- distribution/packages/src/common/scripts/posttrans | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 distribution/packages/src/common/scripts/posttrans diff --git a/distribution/packages/build.gradle b/distribution/packages/build.gradle index 0f47f8263a7..6c5d149a10a 100644 --- a/distribution/packages/build.gradle +++ b/distribution/packages/build.gradle @@ -96,6 +96,9 @@ Closure commonPackageConfig(String type) { postInstall file("${scripts}/postinst") preUninstall file("${scripts}/prerm") postUninstall file("${scripts}/postrm") + if (type == 'rpm') { + postTrans file("${scripts}/posttrans") + } // top level "into" directive is not inherited from ospackage for some reason, so we must // specify it again explicitly for copying common files diff --git a/distribution/packages/src/common/scripts/postinst b/distribution/packages/src/common/scripts/postinst index abc7c91b81d..38e1f4452ad 100644 --- a/distribution/packages/src/common/scripts/postinst +++ b/distribution/packages/src/common/scripts/postinst @@ -19,18 +19,22 @@ case "$1" in if [ -n $2 ]; then IS_UPGRADE=true fi + PACKAGE=deb ;; abort-upgrade|abort-remove|abort-deconfigure) + PACKAGE=deb ;; # RedHat #################################################### 1) # If $1=1 this is an install IS_UPGRADE=false + PACKAGE=rpm ;; 2) # If $1=1 this is an upgrade IS_UPGRADE=true + PACKAGE=rpm ;; *) @@ -99,7 +103,8 @@ if [ -f ${path.env} ]; then chown root:elasticsearch ${path.env} fi -if [ ! -f /etc/elasticsearch/elasticsearch.keystore ]; then +# the equivalent code for rpm is in posttrans +if [ "$PACKAGE" = "deb" -a ! -f /etc/elasticsearch/elasticsearch.keystore ]; then /usr/share/elasticsearch/bin/elasticsearch-keystore create chown root:elasticsearch /etc/elasticsearch/elasticsearch.keystore chmod 660 /etc/elasticsearch/elasticsearch.keystore diff --git a/distribution/packages/src/common/scripts/posttrans b/distribution/packages/src/common/scripts/posttrans new file mode 100644 index 00000000000..d3550bdbed2 --- /dev/null +++ b/distribution/packages/src/common/scripts/posttrans @@ -0,0 +1,8 @@ +if [ ! -f /etc/elasticsearch/elasticsearch.keystore ]; then + /usr/share/elasticsearch/bin/elasticsearch-keystore create + chown root:elasticsearch /etc/elasticsearch/elasticsearch.keystore + chmod 660 /etc/elasticsearch/elasticsearch.keystore + md5sum /etc/elasticsearch/elasticsearch.keystore > /etc/elasticsearch/.elasticsearch.keystore.initial_md5sum +fi + +${scripts.footer}