From fb53624ed8b6a8a183b6089976c26fd56d21463d Mon Sep 17 00:00:00 2001 From: Manuel Gutierrez <1380243+xr09@users.noreply.github.com> Date: Fri, 23 Oct 2020 15:24:47 +0200 Subject: [PATCH] Shutdown container if API configuration fails --- .../config/etc/cont-init.d/2-manager | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/wazuh-opendistro/config/etc/cont-init.d/2-manager b/wazuh-opendistro/config/etc/cont-init.d/2-manager index 1ac0139e..4419011a 100644 --- a/wazuh-opendistro/config/etc/cont-init.d/2-manager +++ b/wazuh-opendistro/config/etc/cont-init.d/2-manager @@ -22,6 +22,11 @@ function echoyellow() echo $(__colortext "$1" "33") } +function echored() +{ + echo $(__colortext "$1" "31") +} + function_wazuh_migration(){ if [ -d "/wazuh-migration" ]; then if [ ! -e /wazuh-migration/.migration-completed ]; then @@ -84,8 +89,16 @@ function_create_custom_user() { } EOF - # create or customize API user - /var/ossec/framework/python/bin/python3 /var/ossec/framework/scripts/create_user.py + # create or customize API user + if /var/ossec/framework/python/bin/python3 /var/ossec/framework/scripts/create_user.py; then + # remove json if exit code is 0 + rm /var/ossec/api/configuration/admin.json + else + echored "There was an error configuring the API user" + # terminate container to avoid unpredictable behavior + exec s6-svscanctl -t /var/run/s6/services + exit 1 + fi fi }