1 | # Try to see if the system should stay up. The reasons for startup are: |
---|
2 | # Power On Button (least likely) |
---|
3 | # Secret keyboard code |
---|
4 | # Wake on LAN (likely) |
---|
5 | # Scheduled startup by mythbackend (most likely) |
---|
6 | # |
---|
7 | # The system should shutdown if: |
---|
8 | # MythTV Backend is idle, (implies the combined Frontend isn't running) |
---|
9 | # The Network Control port isn't in use |
---|
10 | # The Diskless Client isn't up |
---|
11 | # |
---|
12 | |
---|
13 | SHUTDOWN_LOG="/var/log/mythtv/LocalPreShutdownTests.log" |
---|
14 | DATE=`date +'%x %X'` |
---|
15 | |
---|
16 | # See if mythbackend thinks its ok to shutdown |
---|
17 | # 0 OK to shutdown |
---|
18 | # 1 Don't shutdown |
---|
19 | |
---|
20 | mythshutdown --quiet --syslog none --nodblog --check |
---|
21 | MYTH_SD=$? |
---|
22 | |
---|
23 | # See if port 6546 is active |
---|
24 | # 0 = Active, Don't shutdown |
---|
25 | # 1 = Inactive, OK to shutdown |
---|
26 | |
---|
27 | netstat -an | grep "192.168.1.204:6546.*192.168.1.20[1-9]:.*ESTABLISHED" 2>&1 > /dev/null |
---|
28 | NC=$? |
---|
29 | |
---|
30 | # See if the diskless client is running |
---|
31 | # 0 its running (don't shutdown) |
---|
32 | # !0 it isn't (OK to shutdown) |
---|
33 | |
---|
34 | FE=1 |
---|
35 | for FEHOST in fe1 |
---|
36 | do ping -c1 -q -t4 -w1 ${FEHOST} 2>&1 > /dev/null |
---|
37 | if [ $? = 0 ]; then |
---|
38 | FE=0 |
---|
39 | fi |
---|
40 | done |
---|
41 | |
---|
42 | # See if the slave backend is active |
---|
43 | # 0 = Active, Don't shutdown |
---|
44 | # 1 = Inactive, OK to shutdown |
---|
45 | |
---|
46 | netstat -an | grep "192.168.1.204:6543.*192.168.1.200:.*ESTABLISHED" 2>&1 > /dev/null |
---|
47 | SBE=$? |
---|
48 | |
---|
49 | # Now adjust this script's return code for mythbackend's use. |
---|
50 | |
---|
51 | if [ $MYTH_SD -eq 0 -a $NC = 1 -a $FE != 0 -a $SBE -eq 1 ]; then |
---|
52 | echo "$DATE: SD=$MYTH_SD, 0=OK, NETCTL=$NC, 1=OK, DC=$FE, !0=OK, SBE=$SBE, 1=OK, OK To Shutdown." >> ${SHUTDOWN_LOG} |
---|
53 | exit 0 |
---|
54 | else #echo "$DATE: SD=$MYTH_SD, 0=OK, NETCTL=$NC, 1=OK, DC=$FE, !0=OK, SBE=$SBE, 1=OK Don't Shutdown." >> ${SHUTDOWN_LOG} |
---|
55 | exit 1 |
---|
56 | fi |
---|