File sapconf of Package sapconf.4964

#!/bin/bash
#
# /usr/sbin/sapconf
#
# Copyright (c) 2007 SuSE Linux Products GmbH, Nuernberg, Germany.
#
#     This library is free software; you can redistribute it and/or modify it
#     under the terms of the GNU Lesser General Public License as published by
#     the Free Software Foundation; either version 2.1 of the License, or (at
#     your option) any later version.
#                             
#     This library is distributed in the hope that it will be useful, but
#     WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#     Lesser General Public License for more details.
#      
#     You should have received a copy of the GNU Lesser General Public
#     License along with this library; if not, write to the Free Software Foundation
#     51 Franklin Street, Fifth Floor Boston, MA 02110-1301 USA 
#
# Mission: Configure and set the system for the requirements of SAP
#	   systems. Based on scripts written by Holger Achtziger,
#	   and Wolfgang Rosenauer (sapinit-1.1.1), Alexander Hass and
#	   Uwe Menges (sapinit.sh), and Dennis Olsson (SAPinit-2.0.2).
#
# Remark:  This boot script may modify the configuration files
#	   /etc/sysctl.conf and /etc/security/limits.conf with data
#	   get from /etc/sysconfig/sapconf. That is that some
#	   of the configuration data may hold twice, within the first
#	   two files and the last file.
#
# Author:  Werner Fink <werner@suse.de>, 2007
#
# Please send feedback to http://www.suse.de/feedback
#

# Shell functions sourced from /etc/rc.status
. /etc/rc.status

# Standard path only
PATH=/sbin:/bin:/usr/sbin:/usr/bin

rc_reset
case "$1" in
    start|restart|try-restart|reload)
	echo "Setting kernel specific parameters for a SAP system"
	#
	# Declare and initialize the used variables and integers
	#
	typeset -a VARS=(TMPFS_SIZE SHMALL SEMMSL SEMMNS SEMOPM SEMMNI SHMMAX MAX_MAP_COUNT)
	for var in ${VARS[@]} ; do
	    typeset -i ${var}=0
	    typeset -i ${var}_MIN=0
	    typeset -i ${var}_REQ=0
	done

	# Current date in Universal Time
	typeset -r DATE=$(date -u +"%Y-%m-%d %H:%M:%S %Z")

	# Some defaults
	typeset -i VSZ_TMPFS_PERCENT=75

	# Current hardware platform
	typeset -r ARCH=$(uname -i)

	#
	# Read in the configuration and shell functions
	#
	. @@funcdir@@/functions
	if test -r /etc/sysconfig/@@sapconf@@ ; then
	    . /etc/sysconfig/@@sapconf@@
	else
	    case "$ARCH" in
	    ia64|x86_64|ppc64|s390x) 
		. @@confdir@@/config.b64 ;;
	    *)
		. @@confdir@@/config.b32 ;;
	    esac
	fi

	#
	# Maximal number known by the system (don't use -i here)
	#
	typeset -r ULONG_MAX=$(getconf ULONG_MAX 2> /dev/null)

	#
	# Read out the sysctl parameters
	#
	read_sysctl kernel.shmmax    SHMMAX
	read_sysctl kernel.sem       SEMMSL SEMMNS SEMOPM SEMMNI
	read_sysctl kernel.shmall    SHMALL
	read_sysctl vm.max_map_count MAX_MAP_COUNT

	#
	# Calculate some of the requested values
	#

	# The virtual memory of the system in GB
	typeset -ri VSZ=$(virtual_memory)

	# The page size configured for this system in kB
	typeset -ri PSZ=$(page_size)

	# SAP Note 941735: required size of TMPFS: (RAM + SWAP) * 0.75
	TMPFS_SIZE_REQ=$(((VSZ*VSZ_TMPFS_PERCENT)/100))

	# SAP Note 941735: kernel.shmall is in 4 KB pages; minimum 20GB
	SHMALL_REQ=$((VSZ*1024*(1024/PSZ)))

	# SAP Note 941735:  kernel.shmmax is in Bytes; minimum 20GB
	SHMMAX_REQ=$((VSZ*1024*1024*1024))

	#
	# Puzzle out the best value
	#
	typeset -i max
	case "$ARCH" in
	ia64|x86_64|ppc64|s390x)
	    let max=2**63-1 ;;
	*)
	    let max=2**32-1 ;;
	esac
	typeset -i val
	for var in ${VARS[@]} ; do
	    min=${var}_MIN
	    req=${var}_REQ
	    val=${!var}
	    if test ${!req} -lt ${!min} ; then	# If req less than min use min
		eval $req=${!min}
	    fi
	    if test $val -eq -1 ; then		# -1 is equivalent to unlimited
		eval $req=$max
	    elif test $val -gt ${!req} ; then	# current val more than req
		eval $req=$val
	    fi
	    if test ${!req} -gt $max ; then
		eval $req=$max
	    fi
	done
	unset var min req val max

	#
	# Compare tmpfs size and if necessary set the requested size
	#
	tmpfs_size TMPFS_SIZE_REQ
	rc_status

	#
	# Clean out old sysctl.conf file of SAPinit
	#
	sys=/etc/sysctl.conf
	ret=""

	if test -f ${sys} -a ! -f ${sys}~ ; then
	    CleanSYSCTLconf sys ret
	    if test -n "$ret" -a -s "$ret" ; then
		test -s ${sys}~ || cp -p ${sys} ${sys}~
		cat ${ret} > ${sys}
		fsync ${sys}
		rm -f ${ret}
		trap - EXIT
	    fi
	fi

	#
	# Add or change sysctl parameters if needed
	#
	sys=/etc/sysctl.conf
	ret=""

	edit_sysctl sys ret kernel.shmmax    SHMMAX_REQ
	edit_sysctl sys ret kernel.sem       SEMMSL_REQ SEMMNS_REQ SEMOPM_REQ SEMMNI_REQ
	edit_sysctl sys ret kernel.shmall    SHMALL_REQ
	edit_sysctl sys ret vm.max_map_count MAX_MAP_COUNT_REQ

	if test -n "$ret" -a -s "$ret" ; then
	    test -s ${sys}~ || cp -p ${sys} ${sys}~
	    cat ${ret} > ${sys}
	    fsync ${sys}
	    sysctl -e -q -p
	    rc_status
	    rm -f ${ret}
	    trap - EXIT
	fi

	#
	# Add or change limits if needed
	#
	sys=/etc/security/limits.conf
	ret=""
	
	for lim in ${!LIMIT_*} ; do
	    edit_limits sys ret ${!lim}
	done

	if test -n "$ret" -a -s "$ret" ; then
	    test -s ${sys}~ || cp -p ${sys} ${sys}~
	    cat ${ret} > ${sys}
	    fsync ${sys}
	    rm -f ${ret}
	    trap - EXIT
	fi

	rc_status -v1
	;;
    stop)
	# skip / nothing to do
	;;
    status)
	rc_failed 4
	rc_status -v
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart|reload}"
	exit 1
	;;
esac
rc_exit
openSUSE Build Service is sponsored by