#!/bin/bash
omgstopall
omgstartilid

VERSION=$(omgsysteminfo --filter=os.version --val 2>/dev/null)
OS=$(if [ -e /etc/redhat-release ]; then cat /etc/redhat-release | head -n 1 | cut -d " " -f 1 ; else if [ -r /etc/issue ] ; then cat /etc/issue | head -n 1 | cut -d " " -f 1 ; else echo unknown ; fi; fi)
if [ "${OS}" = "Ubuntu" ]; then
    /usr/bin/switchsyslog
    which /etc/init.d/avahi-daemon 2>&1 && /etc/init.d/avahi-daemon restart
    /etc/init.d/omg.start
elif [ "${OS}" = "Debian" ]; then
    /usr/bin/switchsyslog
    which /etc/init.d/avahi-daemon 2>&1 && systemctl restart avahi-daemon
    systemctl restart omg
else
    VERSION=$(omgsysteminfo --filter=os.version= --val 2>/dev/null)
    if [ "${VERSION}" = "6" ]; then
        /usr/bin/switchsyslog
        service omg start
        service omgproducermanager start
        service omgwebui start
    else
        /usr/bin/switchsyslog
        systemctl restart omg
        systemctl restart omgproducermanager
        systemctl restart omgwebui
    fi
fi
