#!/bin/sh

##
# Osiris
##

. /etc/rc.common

StartService ()
{
    if [ "${OSIRISSERVER:=-NO-}" = "-YES-" ]; then

        if [ -f @INSTALLDIR@/osirismd ]; then
        echo "Starting osiris management daemon."
        @INSTALLDIR@/osirismd 
        fi

        if [ -f @INSTALLDIR@/osirisd ]; then
        echo "Starting osiris scanning daemon."
        @INSTALLDIR@/osirisd -l2
        fi
    fi
}

StopService ()
{
    MGMT_RUNNING=`ps -auxw | grep osirismd | grep -v grep`
    SCANNER_RUNNING=`ps -auxw | grep osirisd | grep -v grep`

    if [ "${MGMT_RUNNING}" != "" ]; then
        killall osirismd
        echo "Osiris Management daemon stopped."
    fi

    if [ "${SCANNER_RUNNING}" != "" ]; then
        killall osirisd
        echo "Osiris Scanning daemon stopped."
    fi 
}

RestartService ()
{
    StopService
    StartService
}

RunService "$1"
