Last active
October 19, 2015 09:00
-
-
Save pfichtner/57e3756eb65512202186 to your computer and use it in GitHub Desktop.
mythbackend scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# (file must be present on master and slave(s)) | |
OK_TO_SHUTDOWN=0 | |
DO_NOT_SHUTDOWN=1 | |
DISABLE_AUTO_SHUTDOWN=3 | |
xpathQuery() { | |
xpath -q -e "$2" "$1" | awk -F "[<>]" '{print $3}' | |
} | |
mysqlExec() { | |
mysql --host $host $database -u$user -p$password -se "$1" | |
} | |
isMasterBackend() { | |
hostname=`hostname` | |
masterServerIP=`mysqlExec "select data from settings where value = 'MasterServerIP' and hostname is null"` | |
thisBackendServerIP=`mysqlExec "select data from settings where value = 'BackendServerIP' and hostname = '$hostname'"` | |
[ "$masterServerIP" = "$thisBackendServerIP" ] && return 0 | |
return 1 | |
} | |
minUptimeNotReached() { | |
[ `expr $minUptimeMinutes \* 60` -ge `cat /proc/uptime | cut -d'.' -f1` ] && return 1 | |
return 0 | |
} | |
areUsersLoggedIn() { | |
[ `w -h | wc -l` -ge 0 ] && return 1 | |
return 0 | |
} | |
config=~/.mythtv/config.xml | |
host=`xpathQuery $config Configuration/Database/Host` | |
database=`xpathQuery $config Configuration/Database/DatabaseName` | |
user=`xpathQuery $config Configuration/Database/UserName` | |
password=`xpathQuery $config Configuration/Database/Password` | |
# never shutdown the MBE | |
isMasterBackend && exit $DISABLE_AUTO_SHUTDOWN | |
areUsersLoggedIn || exit $DO_NOT_SHUTDOWN | |
minUptimeMinutes=60 | |
minUptimeNotReached || exit $DO_NOT_SHUTDOWN | |
exit $OK_TO_SHUTDOWN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# (file must be present on master) | |
# SCRIPT MUST BE PRESENT OTHERWISE SHUTDOWN IS CANCELED :-/ | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# (file must be present on slave(s)) | |
# make sure the following lines exists in /etc/sudoers (use visudo to add them) | |
# # Allow mythtv users to shut down this machine | |
# %mythtv ALL = NOPASSWD: /sbin/poweroff | |
/usr/bin/sudo /sbin/poweroff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment