-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestart_hhvm.sh
executable file
·49 lines (42 loc) · 1.26 KB
/
restart_hhvm.sh
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/bash
if [ "$1" == "" ]; then
DEFAULT_HHVM_SERVICES=""
while read fn; do
svcname="`basename $fn`"
if [[ "`rc-status | grep -e "^ $svcname\s"`" != "" ]]; then
DEFAULT_HHVM_SERVICES="`echo "$DEFAULT_HHVM_SERVICES"`$svcname "
fi
done < <(find -L /etc/init.d/ -samefile /etc/init.d/hhvm)
echo "Restarting $DEFAULT_HHVM_SERVICES"
for svc in $DEFAULT_HHVM_SERVICES; do
$0 $svc
done
exit 1
fi
SVCNAME=$1
if [[ "`find -L /etc/init.d/ -samefile /etc/init.d/hhvm | grep /etc/init.d/${SVCNAME}`" == "" ]]; then
# Allow short parameter as hhvm.$1
if [[ "`find -L /etc/init.d/ -samefile /etc/init.d/hhvm | grep /etc/init.d/hhvm.${SVCNAME}`" != "" ]]; then
SVCNAME=hhvm.$SVCNAME
else
echo "FATAL: $SVCNAME is not a HHVM service!"
exit 1
fi
fi
TIMEOUT=${2:-10}
PID="`cat /var/run/hhvm/${SVCNAME}.pid`"
if [ "$PID" == "" ]; then
echo No PID, starting up
/etc/init.d/${SVCNAME} restart
else
/etc/init.d/${SVCNAME} restart
sleep $TIMEOUT
NEWPID="`cat /var/run/hhvm/${SVCNAME}.pid`"
if [ "$NEWPID" == "$PID" ]; then
NEWPID=
fi
if ! kill -0 $NEWPID 2> /dev/null; then
kill -9 $PID
/etc/init.d/${SVCNAME} restart
fi
fi