%pre

if [ x"$(pidof systemd >/dev/null && echo yes || echo no)" = "xyes" ]; then
    if [ "x$(systemctl list-unit-files | grep cvmfs-gateway)" != "x" ]; then
        if $(systemctl is-active --quiet cvmfs-gateway); then
            systemctl stop cvmfs-gateway
        fi
        if $(systemctl is-active --quiet cvmfs-gateway@*); then
            systemctl stop cvmfs-gateway@*
        fi
    fi
else
    if [ -x /usr/libexec/cvmfs-gateway/run_cvmfs_gateway.sh ]; then
        /usr/libexec/cvmfs-gateway/run_cvmfs_gateway.sh stop || true
    fi
fi
