Skip to content

Commit b56afeb

Browse files
authored
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.
1 parent 2e93a91 commit b56afeb

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

distribution/packages/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ Closure commonPackageConfig(String type) {
9696
postInstall file("${scripts}/postinst")
9797
preUninstall file("${scripts}/prerm")
9898
postUninstall file("${scripts}/postrm")
99+
if (type == 'rpm') {
100+
postTrans file("${scripts}/posttrans")
101+
}
99102

100103
// top level "into" directive is not inherited from ospackage for some reason, so we must
101104
// specify it again explicitly for copying common files

distribution/packages/src/common/scripts/postinst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,22 @@ case "$1" in
1919
if [ -n $2 ]; then
2020
IS_UPGRADE=true
2121
fi
22+
PACKAGE=deb
2223
;;
2324
abort-upgrade|abort-remove|abort-deconfigure)
25+
PACKAGE=deb
2426
;;
2527

2628
# RedHat ####################################################
2729
1)
2830
# If $1=1 this is an install
2931
IS_UPGRADE=false
32+
PACKAGE=rpm
3033
;;
3134
2)
3235
# If $1=1 this is an upgrade
3336
IS_UPGRADE=true
37+
PACKAGE=rpm
3438
;;
3539

3640
*)
@@ -99,7 +103,8 @@ if [ -f ${path.env} ]; then
99103
chown root:elasticsearch ${path.env}
100104
fi
101105

102-
if [ ! -f /etc/elasticsearch/elasticsearch.keystore ]; then
106+
# the equivalent code for rpm is in posttrans
107+
if [ "$PACKAGE" = "deb" -a ! -f /etc/elasticsearch/elasticsearch.keystore ]; then
103108
/usr/share/elasticsearch/bin/elasticsearch-keystore create
104109
chown root:elasticsearch /etc/elasticsearch/elasticsearch.keystore
105110
chmod 660 /etc/elasticsearch/elasticsearch.keystore
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
if [ ! -f /etc/elasticsearch/elasticsearch.keystore ]; then
2+
/usr/share/elasticsearch/bin/elasticsearch-keystore create
3+
chown root:elasticsearch /etc/elasticsearch/elasticsearch.keystore
4+
chmod 660 /etc/elasticsearch/elasticsearch.keystore
5+
md5sum /etc/elasticsearch/elasticsearch.keystore > /etc/elasticsearch/.elasticsearch.keystore.initial_md5sum
6+
fi
7+
8+
${scripts.footer}

0 commit comments

Comments
 (0)