#!/bin/bash
################################################################################
# bounceservice.sh - bounce-anywhere script for service run-on-boot setup
#
# This script assumes that the service script is already installed in it's proper
# location.
#

################################################################################
# Source the service type setup.
#
if [ $# -ne 2 ]; then
  echo "ERROR: invalid number of parameters specified" >&2
  exit 1
fi
export tmppath=$1
export servicename=$2
if [ ! -d ${tmppath}/ ]; then
  echo "ERROR: cannot locate path to tar installer: ${tmppath}" >&2
  exit 1
fi
. ${tmppath}/setservicetype.sh ${servicename}
if [ $? -ne 0 ]; then
  echo "ERROR: cannot source ${tmppath}/setservicetype.sh" >&2
  exit 1
fi

################################################################################
# Bounce the service on this machine.
#
case ${myplatform} in
  "arch")
    systemctl status ${servicename} > /dev/null 2>&1 && systemctl stop ${servicename}
    systemctl start ${servicename} ;;
  "centos")
    /etc/init.d/${servicename} status > /dev/null 2>&1 && /etc/init.d/${servicename} stop
    /etc/init.d/${servicename} start ;;
  "fedora")
    /etc/init.d/${servicename} status > /dev/null 2>&1 && /etc/init.d/${servicename} stop
    /etc/init.d/${servicename} start ;;
  "redhat")
    /etc/init.d/${servicename} status > /dev/null 2>&1 && /etc/init.d/${servicename} stop
    /etc/init.d/${servicename} start ;;
  "debian")
    systemctl status ${servicename} > /dev/null 2>&1 && systemctl stop ${servicename}
    systemctl start ${servicename} ;;
  "ubuntu")
    systemctl status ${servicename} > /dev/null 2>&1 && systemctl stop ${servicename}
    systemctl start ${servicename} ;;
  "gentoo")
    /etc/init.d/${servicename} status > /dev/null 2>&1 && rc-service ${servicename} stop
    rc-service ${servicename} start ;;
  *) echo "ERROR: unknown linux flavor" >&2 ;;
esac

