From 8950f94fb04a2bcaf33a8740b69f985a7d7974b6 Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Wed, 5 Jan 2022 12:02:53 -0500 Subject: [PATCH 1/5] restore state files so python3-influxdb state doesnt try to patch during a restinstall --- setup/so-functions | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/setup/so-functions b/setup/so-functions index 8352d0430..e67edab41 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -2096,6 +2096,10 @@ reinstall_init() { # Backup /opt/so since we'll be rebuilding this directory during setup backup_dir /opt/so "$date_string" + # We need to restore these files during a reinstall so python3-influxdb state doesn't try to patch again + restore_file "/opt/so_old_$date_string/state/influxdb_continuous_query.py.patched" "/opt/so/state/" + restore_file "/opt/so_old_$date_string/state/influxdb_retention_policy.py.patched" "/opt/so/state/" + restore_file "/opt/so_old_$date_string/state/influxdbmod.py.patched" "/opt/so/state/" # Backup directories in /nsm to prevent app errors backup_dir /nsm/mysql "$date_string" @@ -2129,6 +2133,16 @@ reset_proxy() { fi } +restore_file() { + src=$1 + dst=$2 + if [ -f "$src" ]; then + [ ! -d "$dst" ] && mkdir -v -p "$dst" + echo "Restoring $src to $dst." >> "$setup_log" 2>&1 + cp -v "$src" "$dst" + fi +} + backup_dir() { dir=$1 backup_suffix=$2 From 0ff5e3cf6f4cece518b6e76195d41f0663bebf24 Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Wed, 5 Jan 2022 14:48:41 -0500 Subject: [PATCH 2/5] require so-elasticsearch container to be running to run the scripts --- salt/elasticsearch/init.sls | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/salt/elasticsearch/init.sls b/salt/elasticsearch/init.sls index 58a53b19c..a7de1160e 100644 --- a/salt/elasticsearch/init.sls +++ b/salt/elasticsearch/init.sls @@ -330,13 +330,15 @@ so-elasticsearch-pipelines-file: ELASTICCURL: {{ ELASTICAUTH.elasticcurl }} so-elasticsearch-pipelines: - cmd.run: - - name: /opt/so/conf/elasticsearch/so-elasticsearch-pipelines {{ grains.host }} - - onchanges: + cmd.run: + - name: /opt/so/conf/elasticsearch/so-elasticsearch-pipelines {{ grains.host }} + - onchanges: - file: esingestconf - file: esingestdynamicconf - file: esyml - file: so-elasticsearch-pipelines-file + - require: + - docker_container: so-elasticsearch {% if TEMPLATES %} so-elasticsearch-templates: @@ -344,6 +346,8 @@ so-elasticsearch-templates: - name: /usr/sbin/so-elasticsearch-templates-load - cwd: /opt/so - template: jinja + - require: + - docker_container: so-elasticsearch {% endif %} so-elasticsearch-roles-load: @@ -351,6 +355,8 @@ so-elasticsearch-roles-load: - name: /usr/sbin/so-elasticsearch-roles-load - cwd: /opt/so - template: jinja + - require: + - docker_container: so-elasticsearch {% endif %} {# if grains['role'] != 'so-helix' #} From 9357995bfaacaf786dd6faa9fa5e884ba838d490 Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Wed, 5 Jan 2022 16:04:32 -0500 Subject: [PATCH 3/5] remove root cron and restore yeselastic.txt --- setup/so-functions | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/setup/so-functions b/setup/so-functions index e67edab41..ac8f7d825 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -2042,6 +2042,9 @@ reserve_ports() { reinstall_init() { info "Putting system in state to run setup again" + # remove all of root's cronjobs + crontab -r -u root + if [[ $install_type =~ ^(MANAGER|EVAL|HELIXSENSOR|MANAGERSEARCH|STANDALONE|FLEET|IMPORT)$ ]]; then local salt_services=( "salt-master" "salt-minion" ) else @@ -2100,6 +2103,8 @@ reinstall_init() { restore_file "/opt/so_old_$date_string/state/influxdb_continuous_query.py.patched" "/opt/so/state/" restore_file "/opt/so_old_$date_string/state/influxdb_retention_policy.py.patched" "/opt/so/state/" restore_file "/opt/so_old_$date_string/state/influxdbmod.py.patched" "/opt/so/state/" + # If the elastic license has been accepted restore the state file + restore_file "/opt/so_old_$date_string/state/yeselastic.txt" "/opt/so/state/" # Backup directories in /nsm to prevent app errors backup_dir /nsm/mysql "$date_string" From 8af74e8bb32bf8fa50e2c45c5292c9f786a6ac94 Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Wed, 5 Jan 2022 16:53:54 -0500 Subject: [PATCH 4/5] remove more salt configs for reinstall --- setup/so-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/so-functions b/setup/so-functions index ac8f7d825..eb62b46d0 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -2084,7 +2084,7 @@ reinstall_init() { done # Remove all salt configs - rm -rf /etc/salt/grains /etc/salt/minion /etc/salt/pki/* + rm -rf /etc/salt/engines/* /etc/salt/grains /etc/salt/master /etc/salt/master.d/* /etc/salt/minion /etc/salt/minion.d/* /etc/salt/pki/* /etc/salt/proxy /etc/salt/proxy.d/* if command -v docker &> /dev/null; then # Stop and remove all so-* containers so files can be changed with more safety From 6338ba2e45b8aba0c784dff13b5e579a5b4996eb Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Wed, 5 Jan 2022 16:54:56 -0500 Subject: [PATCH 5/5] remove /var/cache/salt/ for reinstall --- setup/so-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/so-functions b/setup/so-functions index eb62b46d0..ff7904e61 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -2084,7 +2084,7 @@ reinstall_init() { done # Remove all salt configs - rm -rf /etc/salt/engines/* /etc/salt/grains /etc/salt/master /etc/salt/master.d/* /etc/salt/minion /etc/salt/minion.d/* /etc/salt/pki/* /etc/salt/proxy /etc/salt/proxy.d/* + rm -rf /etc/salt/engines/* /etc/salt/grains /etc/salt/master /etc/salt/master.d/* /etc/salt/minion /etc/salt/minion.d/* /etc/salt/pki/* /etc/salt/proxy /etc/salt/proxy.d/* /var/cache/salt/ if command -v docker &> /dev/null; then # Stop and remove all so-* containers so files can be changed with more safety