From 556ddc2ee47f658117c3b3518607f3ab42460b56 Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Tue, 27 Sep 2022 09:24:34 -0400 Subject: [PATCH] sync in background --- salt/common/tools/sbin/so-user | 4 ++-- salt/soc/files/bin/salt-relay.sh | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/salt/common/tools/sbin/so-user b/salt/common/tools/sbin/so-user index 2c6a28914..0a287aa7c 100755 --- a/salt/common/tools/sbin/so-user +++ b/salt/common/tools/sbin/so-user @@ -370,9 +370,9 @@ function syncElastic() { mv "${rolesTmpFile}" "${elasticRolesFile}" if [[ -z "$SKIP_STATE_APPLY" ]]; then - echo "Elastic state will be re-applied to affected minions. This may take several minutes..." + echo "Elastic state will be re-applied to affected minions. This will run in the background and may take several minutes to complete." echo "Applying elastic state to elastic minions at $(date)" >> /opt/so/log/soc/sync.log 2>&1 - salt -C 'G@role:so-standalone or G@role:so-eval or G@role:so-import or G@role:so-manager or G@role:so-managersearch or G@role:so-searchnode or G@role:so-heavynode' state.apply elasticsearch queue=True >> /opt/so/log/soc/sync.log 2>&1 + salt --async -C 'G@role:so-standalone or G@role:so-eval or G@role:so-import or G@role:so-manager or G@role:so-managersearch or G@role:so-searchnode or G@role:so-heavynode' state.apply elasticsearch queue=True >> /opt/so/log/soc/sync.log 2>&1 fi else echo "Newly generated users/roles files are incomplete; aborting." diff --git a/salt/soc/files/bin/salt-relay.sh b/salt/soc/files/bin/salt-relay.sh index c912cbeff..386b91612 100755 --- a/salt/soc/files/bin/salt-relay.sh +++ b/salt/soc/files/bin/salt-relay.sh @@ -120,17 +120,21 @@ function manage_user() { function manage_salt() { request=$1 op=$(echo "$request" | jq -r .operation) + minion=$(echo "$request" | jq -r .minion) + if [[ -s $minion ]]; then + minion=$(cat /etc/salt/minion | grep "id:" | awk '{print $2}') + fi case "$op" in state) - log "Performing '$op' for '$state'" + log "Performing '$op' for '$state' on minion '$minion'" state=$(echo "$request" | jq -r .state) - response=$(salt '*' state.apply "$state" queue=True) + response=$(salt --async $minion state.apply "$state" queue=True) exit_code=$? ;; highstate) - log "Performing '$op'" - response=$(salt '*' state.highstate queue=True) + log "Performing '$op' on minion '$minion'" + response=$(salt --async $minion state.highstate queue=True) exit_code=$? ;; *)