Last active
April 14, 2016 09:55
-
-
Save zauberstuhl/1455688388e5d818308dc88615439ff8 to your computer and use it in GitHub Desktop.
Sidekiq 3 Memory Killer Script - https://blog.zauberstuhl.de/sidekiq-3-memory-killer
This file contains 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 | |
# check if script is already running | |
SELFCHECK=$(ps -eo pid,command |grep -v grep |grep $0 |wc -l) | |
if [ "$SELFCHECK" -gt 2 ]; then | |
echo "$0 is already running!"; | |
exit 1; | |
fi; | |
NAPTIME=120 | |
MAXRSS=$(( 4200 * 1024 )); # 4.2GB | |
FOUND=$(ps -eo rss,pid,command |grep sidekiq |grep -v grep |grep -v $0); | |
while read -r line; do | |
echo -n "$line ..."; | |
USAGE=$(echo $line |cut -d' ' -f1); | |
PID=$(echo $line |cut -d' ' -f2); | |
if [ "$USAGE" -gt $MAXRSS ]; then | |
echo -e " \033[0;31mrestart\033[0m"; | |
kill -SIGUSR1 $PID; | |
# wait before we forget about the graceful stuff | |
sleep $NAPTIME; | |
kill -SIGKILL $PID; | |
# prevent killing all worker at once | |
sleep $(( $NAPTIME / 2 )); | |
else | |
echo -e " \033[0;32mok\033[0m"; | |
fi; | |
done <<< "$FOUND" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment