Last active
June 6, 2018 11:41
-
-
Save mansurali901/27c91ac31e6376f0ac62dd5526eb94c7 to your computer and use it in GitHub Desktop.
Adjust value of OOM score to avoid process killed by kernel in case of Out of Memory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script is used to disable OOM Killer for Ruby | |
# Process script will find the ruby process pid and change | |
# the OOM value to avoid being killed by kernel | |
# Author : Mansur Ul Hasan | |
# Email : [email protected] | |
# Function to find the PID | |
ProcessName='ruby' # Process Name | |
AppDir='/usr/local/script/oomadjust' # Application path | |
PidFinder () { | |
# Checking PID for process defined in {ProcessName} variable | |
pgrep -f ruby |grep -v "grep\|pgrep" > $AppDir/conf/ruby.pid | |
# Changing oom value to safe the process state in OOM situation | |
for pid in `cat $AppDir/conf/ruby.pid` | |
do | |
## Variable to check the process name with the help of $pid | |
pidvalue=`cat /proc/$pid/status |grep Name |awk '{print $2}'` | |
## Checking if process is really the process we looking to optimize | |
case $pidvalue in | |
*ruby*) | |
# If process is valid value for oom_score_adj will be tune to lower value | |
echo "Process is valid $pidvalue" | |
echo -10 > /proc/$pid/oom_score_adj | |
;; | |
*) | |
# if process is not valid event will not be logged. | |
echo $pidvalue | |
echo "Process is not valid ..." | |
;; | |
esac | |
done | |
} | |
# Main function caller | |
PidFinder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment