#!/bin/bash

sanityLog()
{
    /nn/bin/AddNnuDiagLog "$@"
    if [ $? -ne 0 ];then
        echo `date` $0 sanity script failed to log message using AddNnuDiagLog "$@" >> /var/log/StartupSequence.log
    fi
}

# Assign class + priority to processes that have not been treated yet
/nn/bin/changeprocesspolicy.sh ksoftirqd_CPU0 IO 50
/nn/bin/changeprocesspolicy.sh Pdrd MGMT 90
/nn/bin/changeprocesspolicy.sh mps CALLP 40
/nn/bin/changeprocesspolicy.sh mgs CALLP 40
/nn/bin/changeprocesspolicy.sh utps CALLP 40
/nn/bin/changeprocesspolicy.sh feps CALLP 40


# Check that monit and crond have started correctly and that previous indicators have been set
# and then set the LED status.

# if  /sbin/pidof monit -eq 0 &&
#     /sbin/pidof crond -eq 0; then
/sbin/pidof monit
RC1=$?
/sbin/pidof crond
RC2=$?

if [ $RC1 -eq 0 ] && [ $RC2 -eq 0 ];then
    touch /var/run/hc_sanity5
    
    if  [ -f /var/run/hc_sanity1 ]  &&
        [ -f /var/run/hc_sanity2 ]  &&
        [ -f /var/run/hc_sanity3 ]  &&
        [ -f /var/run/hc_sanity4 ]; then
        # Examine the current setting of the Status LED "LED1".
        # If set to Solid Red "(1,0)", use alternate alarm to prevent override of alarm condition.
        # If /proc/nn/led does not exist, treat as alternate alarm so alarm system still notified of startup status.
        cat /proc/nn/led | grep "LED1: (1,0)" > /dev/null
        if [ $? -ne 0 ] && [ -e /proc/nn/led ]; then
            sanityLog -mStartupSequence -lStartupSequence.log -wR -sI -v10909 "System Startup - startup complete"
        else
            sanityLog -mStartupSequence -lStartupSequence.log -wR -sI -v10919 "System Startup - startup complete. Separate error detected."
        fi
    else
        sanityLog -mStartupSequence -lStartupSequence.log -wR -sI -v10938 "hc_sanity5 passed - previous condition failed"
    fi
else
    sanityLog -mStartupSequence -lStartupSequence.log -wR -sI -v10939 "hc_sanity5 failed"
fi

exit 0
