#!/bin/bash

case "$1" in
        start|stop|restart)
                if systemctl list-unit-files -q "automation-eda-controller.target" | grep -q "automation-eda-controller.target" ; then
                        exec systemctl $1 automation-eda-controller.target
                else
                        exec systemctl $1 automation-eda-controller.service nginx.service
                fi
                ;;
        enable|disable|status)
                if systemctl list-unit-files -q "automation-eda-controller.target" | grep -q "automation-eda-controller.target" ; then
                        exec systemctl $1 $(systemctl list-dependencies --plain automation-eda-controller.target)
                else
                        exec systemctl $1 automation-eda-controller.service nginx.service
                fi
                ;;
        *)
                echo "Usage: automation-eda-controller-service start|stop|restart|status|enable|disable"
                exit 1
                ;;
esac
