#/bin/bash
#
#
case "$1" in
    start)
        echo -n "Starting Local OpenSUSE Build Service ... "

        sudo systemctl start mysql
        sudo systemctl start memcached

        sudo systemctl start obsrepserver
        sudo systemctl start obssrcserver
        sudo systemctl start obsscheduler
        sudo systemctl start obsdispatcher
        sudo systemctl start obspublisher
        sudo systemctl start obssignd
        sudo systemctl start obssigner
        sudo systemctl start obswarden
        sudo systemctl start obsservice
        sudo systemctl start obsservicedispatch

        sudo systemctl start obsworker

        sudo systemctl start apache2

        echo "Done"

        ;;
    stop)
        echo -n "Shutting down Local OpenSUSE Build Service ... "

        sudo systemctl stop apache2

        sudo systemctl stop obsworker

        sudo systemctl stop obsservicedispatch
        sudo systemctl stop obsservice
        sudo systemctl stop obswarden
        sudo systemctl stop obssigner
        sudo systemctl stop obssignd
        sudo systemctl stop obspublisher
        sudo systemctl stop obsdispatcher
        sudo systemctl stop obsscheduler
        sudo systemctl stop obssrcserver
        sudo systemctl stop obsrepserver

        sudo systemctl stop memcached
        sudo systemctl stop mysql

        echo "Done"
        
        ;;
    restart)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        $0 start

        # Remember status and be quiet
        rc_status
        ;;
    status)
        systemctl status mysql
        systemctl status memcached

        systemctl status obsrepserver
        systemctl status obssrcserver
        systemctl status obsscheduler
        systemctl status obsdispatcher
        systemctl status obspublisher
        systemctl status obssignd
        systemctl status obssigner
        systemctl status obswarden
        systemctl status obsservice
        systemctl status obsservicedispatch

        systemctl status obsworker

        systemctl status apache2

        ;;
    enable)
        systemctl enable mysql
        systemctl enable memcached

        systemctl enable obsrepserver
        systemctl enable obssrcserver
        systemctl enable obsscheduler
        systemctl enable obsdispatcher
        systemctl enable obspublisher
        systemctl enable obssignd
        systemctl enable obssigner
        systemctl enable obswarden
        systemctl enable obsservice
        systemctl enable obsservicedispatch

        systemctl enable obsworker

        systemctl enable apache2

        ;;
    disable)
        systemctl disable mysql
        systemctl disable memcached

        systemctl disable obsrepserver
        systemctl disable obssrcserver
        systemctl disable obsscheduler
        systemctl disable obsdispatcher
        systemctl disable obspublisher
        systemctl disable obssignd
        systemctl disable obssigner
        systemctl disable obswarden
        systemctl disable obsservice
        systemctl disable obsservicedispatch

        systemctl disable obsworker

        systemctl disable apache2

        ;;
    *)
        echo "Usage: $0 {start|stop|restart|enable|disable}"
        exit 1
        ;;
esac
exit 0
