Ticket #10347: LocalPreShutdownTests.sh

File LocalPreShutdownTests.sh, 1.6 KB (added by Bill Meek <keemllib@…>, 9 years ago)

Yes, I was following along on http://irc.mythtv.org/ircLog/channel/1/2012-02-17 ;)

Line 
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
13SHUTDOWN_LOG="/var/log/mythtv/LocalPreShutdownTests.log"
14DATE=`date +'%x %X'`
15
16# See if mythbackend thinks its ok to shutdown
17#    0 OK to shutdown
18#    1 Don't shutdown
19
20mythshutdown --quiet --syslog none --nodblog --check
21MYTH_SD=$?
22
23# See if port 6546 is active
24#    0 = Active, Don't shutdown
25#    1 = Inactive, OK to shutdown
26
27netstat -an | grep "192.168.1.204:6546.*192.168.1.20[1-9]:.*ESTABLISHED" 2>&1 > /dev/null
28NC=$?
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
34FE=1
35for FEHOST in fe1
36do  ping -c1 -q -t4 -w1 ${FEHOST} 2>&1 > /dev/null
37    if [ $? = 0 ]; then
38        FE=0
39    fi
40done
41
42# See if the slave backend is active
43#    0 = Active, Don't shutdown
44#    1 = Inactive, OK to shutdown
45
46netstat -an | grep "192.168.1.204:6543.*192.168.1.200:.*ESTABLISHED" 2>&1 > /dev/null
47SBE=$?
48
49# Now adjust this script's return code for mythbackend's use.
50
51if [ $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
54else    #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
56fi