forked from taniguti/ProfileManager_Helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pms_auto_restart
executable file
·48 lines (43 loc) · 1.11 KB
/
pms_auto_restart
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
43
44
45
46
47
48
#!/bin/sh
MYNAME=`basename $0`
MYDIR=`dirname $0`
KEY="exited with code 255"
PHPFPMLOG=/var/log/devicemgr/php-fpm.log
FLAG=/var/tmp/$MYNAME
WORKLOG=/tmp/${MYNAME}.log
RESTARTER="${MYDIR}/pms_full_restart"
IAM=`whoami`
if [ $IAM != "root" ]; then
echo "use me with sudo"
exit 0
fi
current=`tail -3 "$PHPFPMLOG" | grep "$KEY" | tail -1 | tr -d ']' | awk '{print $2}'`
if [ "${current}X" = X ]; then
echo "`date`: working good." >> "$WORKLOG"
if [ -e "$FLAG" ] ;then rm -rf "$FLAG" ;fi
exit 0
fi
if [ -f $FLAG ]; then
previous=`cat $FLAG`
echo "`date`: current: $current // previous: $previous" >> "$WORKLOG"
if [ "$current" = "$previous" ]; then
DoRestart=no
else
DoRestart=yes
fi
else
echo $current > $FLAG
echo "`date`: current: $current" >> "$WORKLOG"
DoRestart=no
fi
echo "`date`: DoRestart: $DoRestart" >> "$WORKLOG"
if [ $DoRestart = yes ]; then
if [ -x "$RESTARTER" ]; then
"$RESTARTER" >> "$WORKLOG" 2>&1
rm -f $FLAG
mv "$WORKLOG" "${WORKLOG}.previous"
else
echo "Not found $RESTARTER" >> "$WORKLOG"
exit 1
fi
fi