#!/bin/sh
#
# template	Summary of the service.
#
# chkconfig: 2345 90 10
# description: dynamic tuning kernel parameters
# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

RETVAL=0
LIMITSFILE=/etc/security/limits.d/90-hpc.conf

SourceIfNotEmpty /etc/sysconfig/hpc

tune_limits()
{
    local memsize="$(sed -n 's,^MemTotal:[[:space:]]\+\([0-9]\+\).*,\1,p' /proc/meminfo)"
    
    [ -n "$memsize" ] || return

    printf '#automaticaly generated by hpc init script\n' >"$LIMITSFILE"
    printf '*\tsoft\tmemlock\t%d\n' "$memsize">>"$LIMITSFILE"
    printf '*\thard\tmemlock\t%d\n' "$memsize">>"$LIMITSFILE"
}

hpc_action()
{
    local fun="$1";shift
    local msg="$1";shift

    printf "%s:" "$msg"

    if "$fun";then
	success "$msg" 
	echo
    else
	failure "$msg"
	echo
	return 1
    fi
}

start()
{ 
	hpc_action tune_limits "Tuning limits"
	RETVAL=$?

	return $RETVAL
}


# See how we were called.
case "$1" in
	start)
		start
		;;
	condrestart|stop)
		true
		;;
	*)
		msg_usage "${0##*/} {start|stop|condrestart}"
		RETVAL=1
esac

exit $RETVAL
