Skip to content

Instantly share code, notes, and snippets.

@pfichtner
Last active October 19, 2015 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfichtner/57e3756eb65512202186 to your computer and use it in GitHub Desktop.
Save pfichtner/57e3756eb65512202186 to your computer and use it in GitHub Desktop.
mythbackend scripts
#! /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
#! /bin/sh
# (file must be present on master)
# SCRIPT MUST BE PRESENT OTHERWISE SHUTDOWN IS CANCELED :-/
exit 0
#! /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