Skip to content

Commit

Permalink
Updated the regex for soft and hard memlock
Browse files Browse the repository at this point in the history
- get only the last entry in the event of duplicates.
- recognize 'infinity' and '-1' in addition to 'unlimited' as per
  limits.conf man page
  • Loading branch information
jkstill committed Aug 4, 2016
1 parent 565aeed commit b2a786d
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 6 deletions.
22 changes: 22 additions & 0 deletions limits-test.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536

oracle soft memlock 2048
oracle soft memlock 1024
#oracle soft memlock -1
#oracle soft memlock infinity
#oracle soft memlock unlimited
oracle soft memlock bogus

oracle hard memlock 2048
oracle hard memlock 1024
#oracle hard memlock -1
#oracle hard memlock infinity
oracle hard memlock unlimited
oracle hard memlock bogus



15 changes: 9 additions & 6 deletions mem_verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,20 @@ SHMALL=$(cat /proc/sys/kernel/shmall)
# if 'unlimited' then set to value of total memory
LIMITS_FILE='/etc/security/limits.conf'

SOFT_MEMLOCK=$( grep -E '^oracle.*soft.*memlock.*unlimited|^oracle.*soft.*memlock.*[0-9]++' $LIMITS_FILE | awk '{ print $4 }')
# from the limits.conf man page
# All items support the values -1, unlimited or infinity indicating no limit, except for priority and nice.

SOFT_MEMLOCK=$( grep -E '^oracle.*soft.*memlock.*(unlimited|infinity|-1)|^oracle.*soft.*memlock.*[0-9]++' $LIMITS_FILE | tail -1 | awk '{ print $4 }')
if [[ -z $SOFT_MEMLOCK ]]; then
SOFT_MEMLOCK=$( grep -E '^\*.*soft.*memlock.*unlimited|^\*.*soft.*memlock.*[0-9]+' $LIMITS_FILE | awk '{ print $4 }')
SOFT_MEMLOCK=$( grep -E '^\*.*soft.*memlock.*(unlimited|infinity|-1)|^\*.*soft.*memlock.*[0-9]+' $LIMITS_FILE | tail -1 | awk '{ print $4 }')
fi
[[ $SOFT_MEMLOCK == 'unlimited' ]] && SOFT_MEMLOCK=$TOTALMEM
[[ $(echo $SOFT_MEMLOCK | grep -E 'unlimited|infinity|-1') ]] && SOFT_MEMLOCK=$TOTALMEM

HARD_MEMLOCK=$( grep -E '^oracle.*hard.*memlock.*unlimited|^oracle.*hard.*memlock.*[0-9]+' $LIMITS_FILE | awk '{ print $4 }')
HARD_MEMLOCK=$( grep -E '^oracle.*hard.*memlock.*(unlimited|infinity|-1)|^oracle.*hard.*memlock.*[0-9]+' $LIMITS_FILE | tail -1 | awk '{ print $4 }')
if [[ -z $HARD_MEMLOCK ]]; then
HARD_MEMLOCK=$( grep -E '^\*.*hard.*memlock.*unlimited|^\*.*hard.*memlock.*[0-9]+' $LIMITS_FILE | awk '{ print $4 }')
HARD_MEMLOCK=$( grep -E '^\*.*hard.*memlock.*(unlimited|infinity|-1)|^\*.*hard.*memlock.*[0-9]+' $LIMITS_FILE | tail -1 | awk '{ print $4 }')
fi
[[ $HARD_MEMLOCK == 'unlimited' ]] && HARD_MEMLOCK=$TOTALMEM
[[ $(echo $HARD_MEMLOCK | grep -E '(unlimited|infinity|-1)|infinity|-1') ]] && HARD_MEMLOCK=$TOTALMEM

[[ -z $SOFT_MEMLOCK ]] && SOFT_MEMLOCK=0
[[ -z $HARD_MEMLOCK ]] && HARD_MEMLOCK=0
Expand Down
53 changes: 53 additions & 0 deletions regex-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/bash

# test regex for pulling memlock from /etc/security/limits.conf

# duplicate entries may appear in the file
# the following are duplicates for 'oracle soft memlock'
# the second one of 1078768 will be the one used by the system
#
# oracle soft memlock 5078768
# oracle soft memlock 1078768

# Test Variables
TOTALMEM=33554432
(( TOTALMEM_BYTES = TOTALMEM * 1024 ))
LIMITS_FILE=limits-test.conf
#######################################

# from the limits.conf man page
# All items support the values -1, unlimited or infinity indicating no limit, except for priority and nice.

SOFT_MEMLOCK=$( grep -E '^oracle.*soft.*memlock.*(unlimited|infinity|-1)|^oracle.*soft.*memlock.*[0-9]++' $LIMITS_FILE | tail -1 | awk '{ print $4 }')
if [[ -z $SOFT_MEMLOCK ]]; then
SOFT_MEMLOCK=$( grep -E '^\*.*soft.*memlock.*(unlimited|infinity|-1)|^\*.*soft.*memlock.*[0-9]+' $LIMITS_FILE | tail -1 | awk '{ print $4 }')
fi
[[ $(echo $SOFT_MEMLOCK | grep -E 'unlimited|infinity|-1') ]] && SOFT_MEMLOCK=$TOTALMEM

HARD_MEMLOCK=$( grep -E '^oracle.*hard.*memlock.*(unlimited|infinity|-1)|^oracle.*hard.*memlock.*[0-9]+' $LIMITS_FILE | tail -1 | awk '{ print $4 }')
if [[ -z $HARD_MEMLOCK ]]; then
HARD_MEMLOCK=$( grep -E '^\*.*hard.*memlock.*(unlimited|infinity|-1)|^\*.*hard.*memlock.*[0-9]+' $LIMITS_FILE | tail -1 | awk '{ print $4 }')
fi
[[ $(echo $HARD_MEMLOCK | grep -E '(unlimited|infinity|-1)|infinity|-1') ]] && HARD_MEMLOCK=$TOTALMEM

[[ -z $SOFT_MEMLOCK ]] && SOFT_MEMLOCK=0
[[ -z $HARD_MEMLOCK ]] && HARD_MEMLOCK=0

(( SOFT_MEMLOCK_BYTES = SOFT_MEMLOCK * 1024 ))
(( HARD_MEMLOCK_BYTES = HARD_MEMLOCK * 1024 ))


cat <<MEMINFO
OS:
totalmem: $TOTALMEM
in bytes: $TOTALMEM_BYTES
soft_memlock: $SOFT_MEMLOCK
in bytes: $SOFT_MEMLOCK_BYTES
hard_memlock: $HARD_MEMLOCK
in bytes: $HARD_MEMLOCK_BYTES
MEMINFO


0 comments on commit b2a786d

Please sign in to comment.