#!/bin/sh 
#
#
# For Linux:
#    - Create a smaller PNSD log file in /tmp 
#    - Configure poe.limits file
#    - Generate and store checkpoint key
#    - BSR support configuration

# Configure the PNSD.cfg to use a smaller log so it doesn't use so much memory
# for a stateless image.  Normally, pnsd creates this file if it does not 
# exist, but it will not fill it in if it does exist.
if [ ! -f /etc/PNSD.cfg ]; then
    echo "log_file = /tmp/serverlog" >  /etc/PNSD.cfg
    echo "log_file_size = 2097152"   >> /etc/PNSD.cfg
    echo "socket_file = /tmp/PNSD"   >> /etc/PNSD.cfg
else
    /bin/sed -i 's/log_file_size = .*/log_file_size = 2097152/g'  /etc/PNSD.cfg
    if [ -f "/proc/cmdline" ]; then
      stopsrc -s pnsd
      startsrc -s pnsd
    fi
fi

# Configure the poe.limits file
if [ ! -f /etc/poe.limits ]; then
    echo "MP_POE_LAUNCH=all" > /etc/poe.limits
else
    /bin/sed -i 's/MP_POE_LAUNCH=.*/MP_POE_LAUNCH=all/g'  /etc/poe.limits
fi


# POE requires rsh to be running
  /bin/sed -i 's/disable.*/disable = no/g'  /etc/xinetd.d/rsh
  if [ -f "/proc/cmdline" ]; then
     chkconfig xinetd on
     service xinetd restart
  fi

#max locked memory
if ! grep "max locked memory" /etc/security/limits.conf >/dev/null 2>&1 ; then
    sed -i "/# End of file/d" /etc/security/limits.conf
    echo "#max locked memory" >> /etc/security/limits.conf
    echo "*               soft    memlock           unlimited" >> /etc/security/limits.conf
    echo "*               hard    memlock           unlimited" >> /etc/security/limits.conf
    echo "# End of file"  >> /etc/security/limits.conf
fi

#max nofile configuration
if ! grep "max nofile" /etc/security/limits.conf >/dev/null 2>&1 ; then
    sed -i "/# End of file/d" /etc/security/limits.conf
    echo "#max nofile" >> /etc/security/limits.conf
    echo "*               soft    nofile           4096" >> /etc/security/limits.conf
    echo "*               hard    nofile           4096" >> /etc/security/limits.conf
    echo "# End of file"  >> /etc/security/limits.conf
fi

# several sysctl parameters.
if ! grep "ppe rte sysctl parameters" /etc/sysctl.conf >/dev/null 2>&1 ; then
    echo "#ppe rte sysctl parameters" >> /etc/sysctl.conf
    echo "net.core.wmem_max = 1048576" >> /etc/sysctl.conf
    echo "net.core.rmem_max = 8388608" >> /etc/sysctl.conf
    echo "net.ipv4.ipfrag_low_thresh = 1048576" >> /etc/sysctl.conf
    echo "net.ipv4.ipfrag_high_thresh = 8388608" >> /etc/sysctl.conf
fi

if [ -f "/proc/cmdline" ]; then
    /sbin/sysctl -p
fi

