#!/bin/bash # Syncs journal-pull@ systemd instances with /etc/opengnsys/journal-pull-sources.conf. # Triggered by journal-pull-sync.path whenever the config file changes. set -euo pipefail CONF=/opt/opengnsys/ogcore/etc/journal-pull-sources.conf [[ -f "$CONF" ]] || exit 0 mapfile -t WANTED < <(grep -v '^\s*#' "$CONF" | grep -v '^\s*$' | sort -u) mapfile -t CURRENT < <( systemctl list-units 'journal-pull@*.service' --all --plain --no-legend \ | awk '{print $1}' | sed 's/journal-pull@//;s/\.service//' | sort -u ) for ip in "${WANTED[@]:-}"; do [[ -z "$ip" ]] && continue if ! printf '%s\n' "${CURRENT[@]:-}" | grep -qxF "$ip"; then systemctl enable --now "journal-pull@${ip}.service" echo "journal-pull-sync: enabled journal-pull@${ip}" fi done for ip in "${CURRENT[@]:-}"; do [[ -z "$ip" ]] && continue if ! printf '%s\n' "${WANTED[@]:-}" | grep -qxF "$ip"; then systemctl disable --now "journal-pull@${ip}.service" echo "journal-pull-sync: disabled journal-pull@${ip}" fi done