#!/bin/sh

on_rt () {
    if [ -f /sys/kernel/realtime ]; then
        return 0
    fi
    return 1
}

# exit if not on a realtime kernel
if ! on_rt; then
    echo "Not running on a RHEL-RT kernel!"
    exit 0
fi

# get our configs
. /etc/sysconfig/rtctl

service_running () {
    service=$1
    systemctl status $service | egrep "Active: active|; enabled\)" >/dev/null 2>&1
    return $?
}

disable_service () {
    service=$1
    /usr/bin/logger -t RTCTL "turning $service off"
    systemctl stop $service
    systemctl disable $service
}

## if irqbalance is running and the user doesn't want it
## turn it off as it may hurt determinism in RT

if [ "$IRQBALANCE" = "off" ] && service_running irqbalance; then
    disable_service irqbalance
fi

## if cpuspeed is running and the user doesn't explicitly want it
## turn it off as it will hurt determinism

if [ "$CPUSPEED" = "off" ] && service_running cpuspeed; then
    disable_service cpuspeed
fi

rtctl reset
RET=$?
exit $RET

