scripts/lighttpd_restart_oom.sh

27 lines
582 B
Bash
Executable file

#!/usr/bin/env bash
# Author: Oliver Ladner <oli@lugh.ch>
# License: LGPL
#
# Monitors if lighttpd uses too much mem, and if so, restarts it
# 100MB
MAXRAM=200000
while true; do
CHECK=$(ps auxww | grep 'lighttpd -f' | grep -v grep | awk '{print $6}')
sleep 5
if [ $CHECK -gt $MAXRAM ]; then
logger "lighttpd OOM ($CHECK KB used)"
/etc/init.d/lighttpd stop
sleep 15
/etc/init.d/lighttpd start
sleep 5
elif [ -z $CHECK ]; then
logger "lighttpd not running, starting"
/etc/init.d/lighttpd start
sleep 15
else
logger "lighttpd normal ($CHECK KB used)"
fi
done