#!/bin/bash
# Handler for TrueConf Server services

action=$1
service_name=$2

case $action in "stop"|"start"|"status"|"restart"|"reload"|"enable"|"disable")
    case $service_name in 
        trueconf-ws)
            servicename='trueconf-directory-web'
        ;;
        trueconf-db)
            servicename='trueconf-directory-db'
        ;;
        *)
            echo "Invalid option: -$service_name" >&2
            exit 1
        ;;
    esac
        ;;
    *)
        echo "Invalid option: -$action" >&2
        exit 1
    ;;
esac

if [[ $service_name == "trueconf-ws" && $action != "status" ]]; then
    systemctl "$action" "$servicename" > /dev/null 2>&1 &
else
    systemctl "$action" "$servicename" > /dev/null 2>&1
fi

rc=$?
exit $rc
