#!/usr/bin/env bash

# Copyright (C) 2016 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2016 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only

# Start all enabled and inactive Green Unicorn systemd instances
# This script is executed by the role handler at the end of the playbook run


set -o nounset -o pipefail -o errexit

for instance in $(systemctl list-units -t service --full --all 'gunicorn@*.service' | cut -d' ' -f1 | grep -E '^gunicorn\@.*\.service') ; do
    if [ "$(systemctl is-enabled "${instance}")" == "enabled" ] && [ "$(systemctl is-active "${instance}")" != "active" ] ; then
        systemctl start "${instance}"
    fi
done
