Skip to content

Commit 801d9cc

Browse files
committed
Restart ES after keystore upgrade in postinst (#84224)
Closes #82433. If the environment variable `RESTART_ON_UPGRADE` is true, then ensure that we delay restarting Elasticseach until after the keystore is upgraded, or else we can run into permissions problems.
1 parent c52de74 commit 801d9cc

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

distribution/packages/src/common/scripts/postinst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,6 @@ if [ "x$IS_UPGRADE" != "xtrue" ]; then
122122
echo " sudo systemctl start elasticsearch.service"
123123
fi
124124
set -e
125-
126-
elif [ "$RESTART_ON_UPGRADE" = "true" ]; then
127-
128-
echo -n "Restarting elasticsearch service..."
129-
if command -v systemctl >/dev/null; then
130-
systemctl daemon-reload
131-
systemctl restart elasticsearch.service || true
132-
fi
133-
echo " OK"
134125
fi
135126

136127
# the equivalent code for rpm is in posttrans
@@ -149,4 +140,14 @@ if [ "$PACKAGE" = "deb" ]; then
149140
fi
150141
fi
151142

143+
if [ "$RESTART_ON_UPGRADE" = "true" ]; then
144+
145+
echo -n "Restarting elasticsearch service..."
146+
if command -v systemctl >/dev/null; then
147+
systemctl daemon-reload
148+
systemctl restart elasticsearch.service || true
149+
fi
150+
echo " OK"
151+
fi
152+
152153
@scripts.footer@

docs/changelog/84224.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 84224
2+
summary: Restart ES after keystore upgrade in postinst
3+
area: Packaging
4+
type: bug
5+
issues:
6+
- 82433

qa/os/src/test/java/org/elasticsearch/packaging/test/DebPreservationTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
package org.elasticsearch.packaging.test;
1010

1111
import org.elasticsearch.packaging.util.Distribution;
12+
import org.elasticsearch.packaging.util.Packages;
13+
import org.elasticsearch.packaging.util.ServerUtils;
1214
import org.junit.BeforeClass;
1315

1416
import java.nio.file.Paths;
@@ -83,5 +85,27 @@ public void test30Purge() throws Exception {
8385
assertPathsDoNotExist(installation.config, installation.envFile);
8486

8587
assertThat(packageStatus(distribution()).exitCode(), is(1));
88+
89+
installation = null;
90+
}
91+
92+
/**
93+
* Check that restarting on upgrade doesn't run into a problem where the keystore
94+
* upgrade is attempted as the wrong user i.e. the restart happens at the correct
95+
* point. See #82433.
96+
*/
97+
public void test40RestartOnUpgrade() throws Exception {
98+
assertRemoved(distribution());
99+
installation = installPackage(sh, distribution());
100+
assertInstalled(distribution());
101+
102+
// Ensure ES is started
103+
Packages.runElasticsearchStartCommand(sh);
104+
ServerUtils.waitForElasticsearch(installation);
105+
106+
sh.getEnv().put("RESTART_ON_UPGRADE", "true");
107+
installation = installPackage(sh, distribution());
108+
109+
ServerUtils.waitForElasticsearch(installation);
86110
}
87111
}

0 commit comments

Comments
 (0)