Skip to content

Commit 3a82782

Browse files
authored
Avoid failing install if system-sysctl is masked
On Debian-based systems the install scripts are run with set -e meaning that if there is an error in executing one of these scripts then the script fails. If systemd-sysctl is masked then trying to restart the systemd-sysctl service to pick up the changes to vm.max_map_count will fail leading to the post-install script failing. Instead, we should account for the possbility of failure here by not letting the command to restart this service exit with non-zero status code. This commit does this, and adds a test for this situation. Relates #25657
1 parent 847378a commit 3a82782

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

distribution/src/main/packaging/scripts/postinst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ esac
4949

5050
# to pick up /usr/lib/sysctl.d/elasticsearch.conf
5151
if command -v systemctl > /dev/null; then
52-
systemctl restart systemd-sysctl.service
52+
systemctl restart systemd-sysctl.service || true
5353
fi
5454

5555
if [ "x$IS_UPGRADE" != "xtrue" ]; then

qa/vagrant/src/test/resources/packaging/tests/60_systemd.bats renamed to qa/vagrant/src/test/resources/packaging/tests/10_systemd.bats

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,12 @@ setup() {
186186

187187
systemctl stop elasticsearch.service
188188
}
189+
190+
@test "[SYSTEMD] masking systemd-sysctl" {
191+
clean_before_test
192+
193+
systemctl mask systemd-sysctl.service
194+
install_package
195+
196+
systemctl unmask systemd-sysctl.service
197+
}

qa/vagrant/src/test/resources/packaging/utils/utils.bash

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,16 @@ clean_before_test() {
268268
userdel elasticsearch > /dev/null 2>&1 || true
269269
groupdel elasticsearch > /dev/null 2>&1 || true
270270

271-
272271
# Removes all files
273272
for d in "${ELASTICSEARCH_TEST_FILES[@]}"; do
274273
if [ -e "$d" ]; then
275274
rm -rf "$d"
276275
fi
277276
done
277+
278+
if is_systemd; then
279+
systemctl unmask systemd-sysctl.service
280+
fi
278281
}
279282

280283
purge_elasticsearch() {

0 commit comments

Comments
 (0)