#!/usr/bin/env bash

# {{ ansible_managed }}

# After ferm is restarted, libvirtd needs to be reloaded so that it adds its
# own iptables rules where needed

set -o nounset -o pipefail -o errexit

# Check if we are running under systemd
if pidof systemd > /dev/null 2>&1 ; then

    if [ "$(systemctl is-active libvirtd.service)" == "active" ] ; then
        logger -t "ferm-post-hook" "Reloading libvirtd via ferm post hook..."
        systemctl reload libvirtd.service
    fi

else

    # I'm not sure if that's a good way to check for running libvirtd under
    # non-systemd systems, if there are issues please provide a better solution
    if [ -r /var/run/libvirtd.pid ] ; then
        logger -t "ferm-post-hook" "Reloading libvirtd via ferm post hook..."
        service libvirtd restart
    fi

fi
