Skip to content

Commit 6fd80b3

Browse files
committed
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 e61c54c commit 6fd80b3

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
@@ -53,7 +53,7 @@ esac
5353

5454
# to pick up /usr/lib/sysctl.d/elasticsearch.conf
5555
if command -v systemctl > /dev/null; then
56-
systemctl restart systemd-sysctl.service
56+
systemctl restart systemd-sysctl.service || true
5757
fi
5858

5959
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
@@ -191,3 +191,12 @@ setup() {
191191

192192
systemctl stop elasticsearch.service
193193
}
194+
195+
@test "[SYSTEMD] masking systemd-sysctl" {
196+
clean_before_test
197+
198+
systemctl mask systemd-sysctl.service
199+
install_package
200+
201+
systemctl unmask systemd-sysctl.service
202+
}

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)