#!/bin/bash
#  This script is used to start stop the backend.
#  Intended to be used via hotkeys.


MYTH_RUN_STATUS="1"
. /etc/profile
. /etc/systemconfig


if [ -e /etc/X11/WINDOWMANAGER ]
then
    . /etc/X11/WINDOWMANAGER
fi

MV_BEC="/usr/MythVantage/bin/backend_control.sh"

case $1 in
    stop)
        if [ x$STARTUP_STYLE = xenhanced ]
        then
            #/usr/MythVantage/bin/mythbeselect  -stop
            if [ -e $MV_BEC ]
            then
                $MV_BEC stop $dbhost
            else
                msg_client.py --msg "Stopping MythBackend"
                sudo sv stop mythbackend
            fi
        else
            #linhes style
            sudo sv stop mythbackend
        fi
        ;;

    start)
        if [ x$STARTUP_STYLE = xenhanced ]
        then
            #/usr/MythVantage/bin/mythbeselect  -stop
            if [ -e $MV_BEC ]
            then
                $MV_BEC start $dbhost
            else
                msg_client.py --msg "Starting MythBackend"
                sudo sv start mythbackend
            fi
        else
            #linhes style
            sudo sv start mythbackend
        fi
        ;;

    restart)
        if [ x$STARTUP_STYLE = xenhanced ]
        then
            #/usr/MythVantage/bin/mythbeselect  -stop
            if [ -e $MV_BEC ]
            then
                $MV_BEC restart $dbhost
            else
                msg_client.py --msg "Restarting MythBackend"
                sudo sv restart mythbackend
            fi
        else
            #linhes style
            sudo sv restart mythbackend
        fi
        ;;

        *)  echo "options are:  stop  start restart"
        ;;

esac