Skip to content

Commit da09dc2

Browse files
Always set default ES_PATH_CONF for package scriptlets (#51827)
* Set default ES_PATH_CONF for package scriptlets Our packages use scriptlets to create or update the Elasticsearch keystore as necessary when installing or upgrading an Elasticsearch package. If these scriptlets don't work as expected, Elasticsearch may try and fail to create or upgrade the keystore at startup time. This will prevent Elasticsearch from starting up at all. These scriptlets use the Elasticsearch keystore command-line tools. Like most of our command-line tools, the keystore tools will by default get their value for ES_PATH_CONF from a system configuration file: /etc/sysconfig/elasticsearch for RPMs, /etc/default/elasticsearch for debian packages. Previously, if the user removed ES_PATH_CONF from that system configuration file (perhaps thinking that it is obsolete when the same variables is also defined in the systemd unit file), the keystore command-line tools would fail. Scriptlet errors do not seem to cause the installation to fail, and for RPMs the error message is easy to miss in command output. This commit adds a line of bash to scriptlets that will set ES_PATH_CONF to a default when ES_PATH_CONF is unset, rather than only when the system configuration file is missing.
1 parent d16f92b commit da09dc2

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

distribution/packages/src/common/env/elasticsearch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#JAVA_HOME=
1010

1111
# Elasticsearch configuration directory
12+
# Note: this setting will be shared with command-line tools
1213
ES_PATH_CONF=${path.conf}
1314

1415
# Elasticsearch PID directory

distribution/packages/src/common/scripts/postinst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
# source the default env file
1212
if [ -f "${path.env}" ]; then
1313
. "${path.env}"
14-
else
15-
ES_PATH_CONF="${path.conf}"
1614
fi
1715

16+
export ES_PATH_CONF=${ES_PATH_CONF:-${path.conf}}
17+
1818
IS_UPGRADE=false
1919

2020
case "$1" in

distribution/packages/src/common/scripts/postrm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
# source the default env file
1313
if [ -f "${path.env}" ]; then
1414
. "${path.env}"
15-
else
16-
ES_PATH_CONF="${path.conf}"
1715
fi
1816

17+
export ES_PATH_CONF=${ES_PATH_CONF:-${path.conf}}
18+
1919
REMOVE_DIRS=false
2020
REMOVE_JVM_OPTIONS_DIRECTORY=false
2121
REMOVE_USER_AND_GROUP=false

distribution/packages/src/common/scripts/posttrans

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# source the default env file
22
if [ -f "${path.env}" ]; then
33
. "${path.env}"
4-
else
5-
ES_PATH_CONF="${path.conf}"
64
fi
75

6+
export ES_PATH_CONF=${ES_PATH_CONF:-${path.conf}}
7+
88
if [ ! -f "${ES_PATH_CONF}"/elasticsearch.keystore ]; then
99
/usr/share/elasticsearch/bin/elasticsearch-keystore create
1010
chown root:elasticsearch "${ES_PATH_CONF}"/elasticsearch.keystore

distribution/packages/src/common/scripts/preinst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ err_exit() {
1818
# source the default env file
1919
if [ -f "${path.env}" ]; then
2020
. "${path.env}"
21-
else
22-
ES_PATH_CONF="${path.conf}"
2321
fi
2422

23+
export ES_PATH_CONF=${ES_PATH_CONF:-${path.conf}}
24+
2525
case "$1" in
2626

2727
# Debian ####################################################

distribution/packages/src/common/scripts/prerm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
# source the default env file
1313
if [ -f "${path.env}" ]; then
1414
. "${path.env}"
15-
else
16-
ES_PATH_CONF="${path.conf}"
1715
fi
1816

17+
export ES_PATH_CONF=${ES_PATH_CONF:-${path.conf}}
18+
1919
STOP_REQUIRED=false
2020
REMOVE_SERVICE=false
2121

0 commit comments

Comments
 (0)