Skip to content

Commit

Permalink
Fix creating keystore when upgrading (#29121)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jasontedor authored Mar 17, 2018
1 parent 2e93a91 commit b56afeb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions distribution/packages/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion distribution/packages/src/common/scripts/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;

*)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions distribution/packages/src/common/scripts/posttrans
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit b56afeb

Please sign in to comment.