diff --git a/salt/common/tools/sbin/so-user b/salt/common/tools/sbin/so-user index f1bfdc213..4a7b6f0da 100755 --- a/salt/common/tools/sbin/so-user +++ b/salt/common/tools/sbin/so-user @@ -220,6 +220,13 @@ function syncElastic() { } function syncAll() { + if [[ -n "$STALE_MIN" ]]; then + staleCount=$(echo "select from identity_credentials where updated_at >= Datetime('now', '-${STALE_MIN} minutes');" \ + | sqlite3 "$databasePath") + if [[ "$staleCount" == "0" ]]; then + return 1 + fi + fi syncElastic } @@ -368,8 +375,7 @@ case "${operation}" in ;; "sync") - syncAll - echo "Synchronization complete" + syncAll && echo "Synchronization completed at $(date)" ;; "validate") diff --git a/salt/soc/init.sls b/salt/soc/init.sls index 18fda41da..5fe403934 100644 --- a/salt/soc/init.sls +++ b/salt/soc/init.sls @@ -62,6 +62,11 @@ soccustom: - mode: 600 - template: jinja +sosyncusers: + cron.present: + - user: root + - name: 'STALE_MIN=1 /usr/sbin/so-user sync &>> /opt/so/log/soc/sync.log' + so-soc: docker_container.running: - image: {{ MANAGER }}:5000/{{ IMAGEREPO }}/so-soc:{{ VERSION }}