-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmemorycheck.sh
More file actions
42 lines (36 loc) · 992 Bytes
/
memorycheck.sh
File metadata and controls
42 lines (36 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
SCRIPTNAME=`basename $0`
export LOCKSYNC="$dirlock/$SCRIPTNAME.lock"
PID=$$
echo "["$(date +"%Y/%m/%d %H:%M:%S")"] Trying to launch script $0"
if [ -f "$LOCKSYNC" ]
then
echo "Wait: lockfile "$LOCKSYNC" is present. we must verify..."
PIDLOCK=`cat $LOCKSYNC`
if [ -f /proc/$PIDLOCK/exe ]
then
echo "The process is currently running. Launching $SCRIPTNAME aborted."
exit
else
echo "The process isn't currently running anymore. Launching $SCRIPTNAME..."
rm $LOCKSYNC
fi
fi
echo "Lockingfile creation... "$LOCKSYNC
echo $PID > $LOCKSYNC
date=$(date)
log="/root/memoryclean.log"
memorythreshold=80
function restart()
{
/etc/init.d/php5.6-fpm reload
}
check=$(free | awk 'FNR == 2 {print 100-(($2-$3)/$2)*100}' |cut -d "." -f1)
if [[ "$check" -gt "$memorythreshold" ]]
then
echo "Problem detected"
restart
echo "$date" >> $log
else
echo "All is OK"
fi