#!/usr/bin/bash
#
# (c) 2017 siveo, http://www.siveo.net
#
# This file is part of Pulse 2, http://www.siveo.net
#
# Pulse 2 is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Pulse 2 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Pulse 2; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

SERVICES='mmc-agent \
          pulse2-inventory-server \
          pulse2-package-server \
          pulse-xmpp-agent-relay \
          pulse-xmpp-agent-log \
          pulse2-register-pxe \
          isc-dhcp-server \
          tftpd-hpa \
          pulse-xmpp-master-substitute-inventory \
          pulse-xmpp-master-substitute-registration \
          pulse-package-watching \
          pulse-xmpp-master-substitute-assessor \
          pulse-xmpp-master-substitute-deployment \
          pulse-xmpp-master-substitute-subscription \
          pulse-xmpp-master-substitute-logger \
          pulse-xmpp-master-substitute-reconfigurator \
          pulse-xmpp-master-substitute-monitoring \
          pulse-xmpp-master-substitute-all'

systemctl daemon-reload

for service in ${SERVICES}; do
  if systemctl is-enabled ${service} &>/dev/null ; then
    if [ -z $1 ]; then
        echo "Restarting ${service}"
        systemctl restart ${service}
    elif [ $1 = "--stop" ] || [ $1 = "stop" ]; then
      echo "Stopping ${service}"
      systemctl stop ${service}
  elif [ $1 = "--restart" ] || [ $1 = "restart" ] || [ $1 = "--start" ] || [ $1 = "start" ]; then
    echo "Restarting ${service}"
    systemctl restart ${service}
    else
      echo "Usage: $0 [--stop]"
      exit 1
    fi
  fi
done
