Skip to content

Commit 78715d8

Browse files
committed
Add a setup script and according makefile target to upgrade ES keystore from older versions of java
1 parent fd7f419 commit 78715d8

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ endif
2424
keystore: ## Setup Elasticsearch Keystore, by initializing passwords, and add credentials defined in `keystore.sh`.
2525
$(DOCKER_COMPOSE_COMMAND) -f docker-compose.setup.yml run --rm keystore
2626

27+
upgrade-keystore: ## Upgrade Elasticsearch Keystore, which is necessary when upgrading to an Elasticsearch version that uses a newer Java version.
28+
@if [ -n "$$($(DOCKER_COMPOSE_COMMAND) ps -q)" ]; then \
29+
echo "Please stop all running containers before upgrading the keystore."; \
30+
exit 1; \
31+
fi
32+
$(DOCKER_COMPOSE_COMMAND) -f docker-compose.setup.yml run --rm upgrade-keystore
33+
2734
certs: ## Generate Elasticsearch SSL Certs.
2835
$(DOCKER_COMPOSE_COMMAND) -f docker-compose.setup.yml run --rm certs
2936

docker-compose.setup.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3.5'
22

33
services:
4-
keystore:
4+
keystore: &keystore-service
55
image: elastdocker/elasticsearch:${ELK_VERSION}
66
build:
77
context: elasticsearch/
@@ -15,6 +15,10 @@ services:
1515
environment:
1616
ELASTIC_PASSWORD: ${ELASTIC_PASSWORD}
1717

18+
upgrade-keystore:
19+
<<: *keystore-service
20+
command: bash /setup/upgrade-keystore.sh
21+
1822
certs:
1923
image: elastdocker/elasticsearch:${ELK_VERSION}
2024
build:

setup/upgrade-keystore.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Exit on Error
2+
set -e
3+
4+
KEYSTORE_TO_UPGRADE=/secrets/keystore/elasticsearch.keystore
5+
KEYSTORE_TO_UPGRADE_BACKUP=$KEYSTORE_TO_UPGRADE.pre-upgrade
6+
KEYSTORE_LOCATION_FOR_TOOL=/usr/share/elasticsearch/config/elasticsearch.keystore
7+
8+
if [ -f $KEYSTORE_TO_UPGRADE_BACKUP ]; then
9+
echo "A backup of a previous run of this script was found at $KEYSTORE_TO_UPGRADE_BACKUP. Aborting execution!"
10+
echo "Please remove the backup file and run the script again if you're sure that you want to run the upgrade script again."
11+
exit 1
12+
fi
13+
14+
echo "=========== Upgrading Elasticsearch Keystore =========="
15+
16+
cp $KEYSTORE_TO_UPGRADE $KEYSTORE_LOCATION_FOR_TOOL
17+
18+
echo "Running elasticsearch-keystore upgrade"
19+
elasticsearch-keystore upgrade
20+
21+
mv $KEYSTORE_TO_UPGRADE $KEYSTORE_TO_UPGRADE_BACKUP
22+
mv $KEYSTORE_LOCATION_FOR_TOOL $KEYSTORE_TO_UPGRADE
23+
24+
echo "======= Keystore upgrade completed successfully ======="
25+
echo "Old keystore was backed up to $KEYSTORE_TO_UPGRADE_BACKUP"

0 commit comments

Comments
 (0)