Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sidekiq 3 Memory Killer Script - https://blog.zauberstuhl.de/sidekiq-3-memory-killer
#!/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