My system gets me an error that saying 'Too many open files'. I investigated this error and turned out that /usr/bin/uwsgi
created sockets(?) more than 1020. If it creates more than 1020, I guess, the above error comes up with.
So What I try to do is to run a shell script that monitors the number of open files and if it exceeds more than 1000, to kill its PID to resolve this error at this stage.
#uwsgimonitor.sh
#!/bin/bash
#filename=/usr/bin/uwsgi
filename=/usr/bin/uwsgi
Cnt= lsof | awk '/uwsgi/ {print $1,$2}' | uniq -c | sort -r | head -1 | awk '{print $1}'
PROCESS_ID = lsof | awk '/uwsgi/ {print $1,$2}' | uniq -c | sort -r | head -1 | awk '{print $2}'
if [ $Cnt gt 1000 ]
then
echo "Found the number of socket open exceeds $Cnt."
kill -9 $PROCESS_ID
else
echo "" #nothing to do.
fi
In crontab, I added this line but it seems not to kill the PID that I meant.
* * * * * sh /home/root/scripts/uwsgimonitor.sh
What am I missing?
Thank you in advance.