From 33ef1232fb208defd790c16a83fc50562c79bb4d Mon Sep 17 00:00:00 2001 From: Gregor Fuis Date: Mon, 27 Feb 2012 19:10:01 +0100 Subject: [PATCH 1/2] xbmc & xbmc-pvr: redesign of poweroff and reboot. --- packages/mediacenter/xbmc-pvr/init.d/93_xbmc | 23 +++++++++++++-- packages/mediacenter/xbmc-pvr/install | 1 + .../xbmc-pvr/scripts/wait_on_xbmc_exit | 29 +++++++++++++++++++ packages/mediacenter/xbmc/init.d/93_xbmc | 23 +++++++++++++-- packages/mediacenter/xbmc/install | 1 + .../xbmc/scripts/wait_on_xbmc_exit | 29 +++++++++++++++++++ .../ConsoleKit/scripts/ck-system-restart | 3 ++ .../ConsoleKit/scripts/ck-system-stop | 3 ++ 8 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 packages/mediacenter/xbmc-pvr/scripts/wait_on_xbmc_exit create mode 100644 packages/mediacenter/xbmc/scripts/wait_on_xbmc_exit diff --git a/packages/mediacenter/xbmc-pvr/init.d/93_xbmc b/packages/mediacenter/xbmc-pvr/init.d/93_xbmc index 655c4f04f..176dc6344 100644 --- a/packages/mediacenter/xbmc-pvr/init.d/93_xbmc +++ b/packages/mediacenter/xbmc-pvr/init.d/93_xbmc @@ -71,22 +71,39 @@ fi cpupower frequency-set -g ondemand > /dev/null 2>&1 )& +# prevent restrating XBMC at reboot or shutdown + XBMC_LOCKED="/storage/xbmc_locked" + [ -f $XBMC_LOCKED ] && rm -f $XBMC_LOCKED & + # starting XBMC usleep $XBMC_STARTDELAY while true; do + while [ -f $XBMC_LOCKED ]; do + usleep 250000 + done + DISPLAY=:0.0 /usr/lib/xbmc/xbmc.bin $XBMC_ARGS > /dev/null 2>&1 RET=$? case "$RET" in 0) - poweroff -f + if [ ! $(pidof console-kit-daemon) ]; then + touch $XBMC_LOCKED + poweroff -f + fi ;; 64) - poweroff -f + if [ ! $(pidof console-kit-daemon) ]; then + touch $XBMC_LOCKED + poweroff -f + fi ;; 66) - reboot + if [ ! $(pidof console-kit-daemon) ]; then + touch $XBMC_LOCKED + reboot + fi ;; 255) echo "Abnormal Exit. Exited with code $RET" diff --git a/packages/mediacenter/xbmc-pvr/install b/packages/mediacenter/xbmc-pvr/install index 731dc18ce..572f934e6 100755 --- a/packages/mediacenter/xbmc-pvr/install +++ b/packages/mediacenter/xbmc-pvr/install @@ -27,6 +27,7 @@ PYTHON_LIBDIR="`ls -d $INSTALL/usr/lib/python*`" mkdir -p $INSTALL/usr/bin cp $PKG_DIR/scripts/cputemp $INSTALL/usr/bin cp $PKG_DIR/scripts/gputemp $INSTALL/usr/bin + cp $PKG_DIR/scripts/wait_on_xbmc_exit $INSTALL/usr/bin cp $PKG_BUILD/tools/EventClients/Clients/XBMC\ Send/xbmc-send.py $INSTALL/usr/bin/xbmc-send mkdir -p $INSTALL/usr/lib/xbmc diff --git a/packages/mediacenter/xbmc-pvr/scripts/wait_on_xbmc_exit b/packages/mediacenter/xbmc-pvr/scripts/wait_on_xbmc_exit new file mode 100644 index 000000000..f786a6312 --- /dev/null +++ b/packages/mediacenter/xbmc-pvr/scripts/wait_on_xbmc_exit @@ -0,0 +1,29 @@ +#!/bin/sh + +################################################################################ +# Copyright (C) 2009-2010 OpenELEC.tv +# http://www.openelec.tv +# +# This Program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This Program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with OpenELEC.tv; see the file COPYING. If not, write to +# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +# http://www.gnu.org/copyleft/gpl.html +################################################################################ + +count=0 + +while [ $(pidof xbmc.bin) -a $count -le 20 ]; do + usleep 250000 + logger -t wait_on_xbmc_exit "### Waiting for XBMC to Exit - $count ###" + count=$((count+1)) +done diff --git a/packages/mediacenter/xbmc/init.d/93_xbmc b/packages/mediacenter/xbmc/init.d/93_xbmc index b8af6b2b3..3a198e27f 100644 --- a/packages/mediacenter/xbmc/init.d/93_xbmc +++ b/packages/mediacenter/xbmc/init.d/93_xbmc @@ -71,22 +71,39 @@ fi cpupower frequency-set -g ondemand > /dev/null 2>&1 )& +# prevent restrating XBMC at reboot or shutdown + XBMC_LOCKED="/storage/xbmc_locked" + [ -f $XBMC_LOCKED ] && rm -f $XBMC_LOCKED & + # starting XBMC usleep $XBMC_STARTDELAY while true; do + while [ -f $XBMC_LOCKED ]; do + usleep 250000 + done + DISPLAY=:0.0 /usr/lib/xbmc/xbmc.bin $XBMC_ARGS > /dev/null 2>&1 RET=$? case "$RET" in 0) - poweroff -f + if [ ! $(pidof console-kit-daemon) ]; then + touch $XBMC_LOCKED + poweroff -f + fi ;; 64) - poweroff -f + if [ ! $(pidof console-kit-daemon) ]; then + touch $XBMC_LOCKED + poweroff -f + fi ;; 66) - reboot + if [ ! $(pidof console-kit-daemon) ]; then + touch $XBMC_LOCKED + reboot + fi ;; 255) echo "Abnormal Exit. Exited with code $RET" diff --git a/packages/mediacenter/xbmc/install b/packages/mediacenter/xbmc/install index 731dc18ce..572f934e6 100755 --- a/packages/mediacenter/xbmc/install +++ b/packages/mediacenter/xbmc/install @@ -27,6 +27,7 @@ PYTHON_LIBDIR="`ls -d $INSTALL/usr/lib/python*`" mkdir -p $INSTALL/usr/bin cp $PKG_DIR/scripts/cputemp $INSTALL/usr/bin cp $PKG_DIR/scripts/gputemp $INSTALL/usr/bin + cp $PKG_DIR/scripts/wait_on_xbmc_exit $INSTALL/usr/bin cp $PKG_BUILD/tools/EventClients/Clients/XBMC\ Send/xbmc-send.py $INSTALL/usr/bin/xbmc-send mkdir -p $INSTALL/usr/lib/xbmc diff --git a/packages/mediacenter/xbmc/scripts/wait_on_xbmc_exit b/packages/mediacenter/xbmc/scripts/wait_on_xbmc_exit new file mode 100644 index 000000000..f786a6312 --- /dev/null +++ b/packages/mediacenter/xbmc/scripts/wait_on_xbmc_exit @@ -0,0 +1,29 @@ +#!/bin/sh + +################################################################################ +# Copyright (C) 2009-2010 OpenELEC.tv +# http://www.openelec.tv +# +# This Program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This Program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with OpenELEC.tv; see the file COPYING. If not, write to +# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +# http://www.gnu.org/copyleft/gpl.html +################################################################################ + +count=0 + +while [ $(pidof xbmc.bin) -a $count -le 20 ]; do + usleep 250000 + logger -t wait_on_xbmc_exit "### Waiting for XBMC to Exit - $count ###" + count=$((count+1)) +done diff --git a/packages/sysutils/ConsoleKit/scripts/ck-system-restart b/packages/sysutils/ConsoleKit/scripts/ck-system-restart index 003c35227..4c77c37e7 100755 --- a/packages/sysutils/ConsoleKit/scripts/ck-system-restart +++ b/packages/sysutils/ConsoleKit/scripts/ck-system-restart @@ -20,4 +20,7 @@ # http://www.gnu.org/copyleft/gpl.html ################################################################################ +XBMC_LOCKED="/storage/xbmc_locked" +touch $XBMC_LOCKED +wait_on_xbmc_exit reboot diff --git a/packages/sysutils/ConsoleKit/scripts/ck-system-stop b/packages/sysutils/ConsoleKit/scripts/ck-system-stop index a6e24e838..cc93d11f2 100755 --- a/packages/sysutils/ConsoleKit/scripts/ck-system-stop +++ b/packages/sysutils/ConsoleKit/scripts/ck-system-stop @@ -20,4 +20,7 @@ # http://www.gnu.org/copyleft/gpl.html ################################################################################ +XBMC_LOCKED="/storage/xbmc_locked" +touch $XBMC_LOCKED +wait_on_xbmc_exit poweroff From 7e8f0340e3ea157f8b77fadd1b2b01c570d72e67 Mon Sep 17 00:00:00 2001 From: Gregor Fuis Date: Mon, 27 Feb 2012 21:32:59 +0100 Subject: [PATCH 2/2] xbmc & xbmc-pvr: redesign of poweroff and reboot. Change lock file location --- packages/mediacenter/xbmc-pvr/init.d/93_xbmc | 13 +++++++------ .../mediacenter/xbmc-pvr/scripts/wait_on_xbmc_exit | 0 packages/mediacenter/xbmc/init.d/93_xbmc | 13 +++++++------ packages/mediacenter/xbmc/scripts/wait_on_xbmc_exit | 0 .../sysutils/ConsoleKit/scripts/ck-system-restart | 5 +++-- packages/sysutils/ConsoleKit/scripts/ck-system-stop | 5 +++-- 6 files changed, 20 insertions(+), 16 deletions(-) mode change 100644 => 100755 packages/mediacenter/xbmc-pvr/scripts/wait_on_xbmc_exit mode change 100644 => 100755 packages/mediacenter/xbmc/scripts/wait_on_xbmc_exit diff --git a/packages/mediacenter/xbmc-pvr/init.d/93_xbmc b/packages/mediacenter/xbmc-pvr/init.d/93_xbmc index 176dc6344..4477d39a2 100644 --- a/packages/mediacenter/xbmc-pvr/init.d/93_xbmc +++ b/packages/mediacenter/xbmc-pvr/init.d/93_xbmc @@ -72,14 +72,15 @@ fi )& # prevent restrating XBMC at reboot or shutdown - XBMC_LOCKED="/storage/xbmc_locked" - [ -f $XBMC_LOCKED ] && rm -f $XBMC_LOCKED & + LOCKDIR="/var/lock/" + LOCKFILE="xbmc.disabled" + [ -f "$LOCKDIR/$LOCKFILE" ] && rm -f "$LOCKDIR/$LOCKFILE" & # starting XBMC usleep $XBMC_STARTDELAY while true; do - while [ -f $XBMC_LOCKED ]; do + while [ -f "$LOCKDIR/$LOCKFILE" ]; do usleep 250000 done @@ -89,19 +90,19 @@ fi case "$RET" in 0) if [ ! $(pidof console-kit-daemon) ]; then - touch $XBMC_LOCKED + touch "$LOCKDIR/$LOCKFILE" poweroff -f fi ;; 64) if [ ! $(pidof console-kit-daemon) ]; then - touch $XBMC_LOCKED + touch "$LOCKDIR/$LOCKFILE" poweroff -f fi ;; 66) if [ ! $(pidof console-kit-daemon) ]; then - touch $XBMC_LOCKED + touch "$LOCKDIR/$LOCKFILE" reboot fi ;; diff --git a/packages/mediacenter/xbmc-pvr/scripts/wait_on_xbmc_exit b/packages/mediacenter/xbmc-pvr/scripts/wait_on_xbmc_exit old mode 100644 new mode 100755 diff --git a/packages/mediacenter/xbmc/init.d/93_xbmc b/packages/mediacenter/xbmc/init.d/93_xbmc index 3a198e27f..97d672337 100644 --- a/packages/mediacenter/xbmc/init.d/93_xbmc +++ b/packages/mediacenter/xbmc/init.d/93_xbmc @@ -72,14 +72,15 @@ fi )& # prevent restrating XBMC at reboot or shutdown - XBMC_LOCKED="/storage/xbmc_locked" - [ -f $XBMC_LOCKED ] && rm -f $XBMC_LOCKED & + LOCKDIR="/var/lock/" + LOCKFILE="xbmc.disabled" + [ -f "$LOCKDIR/$LOCKFILE" ] && rm -f "$LOCKDIR/$LOCKFILE" & # starting XBMC usleep $XBMC_STARTDELAY while true; do - while [ -f $XBMC_LOCKED ]; do + while [ -f "$LOCKDIR/$LOCKFILE" ]; do usleep 250000 done @@ -89,19 +90,19 @@ fi case "$RET" in 0) if [ ! $(pidof console-kit-daemon) ]; then - touch $XBMC_LOCKED + touch "$LOCKDIR/$LOCKFILE" poweroff -f fi ;; 64) if [ ! $(pidof console-kit-daemon) ]; then - touch $XBMC_LOCKED + touch "$LOCKDIR/$LOCKFILE" poweroff -f fi ;; 66) if [ ! $(pidof console-kit-daemon) ]; then - touch $XBMC_LOCKED + touch "$LOCKDIR/$LOCKFILE" reboot fi ;; diff --git a/packages/mediacenter/xbmc/scripts/wait_on_xbmc_exit b/packages/mediacenter/xbmc/scripts/wait_on_xbmc_exit old mode 100644 new mode 100755 diff --git a/packages/sysutils/ConsoleKit/scripts/ck-system-restart b/packages/sysutils/ConsoleKit/scripts/ck-system-restart index 4c77c37e7..35aa9e976 100755 --- a/packages/sysutils/ConsoleKit/scripts/ck-system-restart +++ b/packages/sysutils/ConsoleKit/scripts/ck-system-restart @@ -20,7 +20,8 @@ # http://www.gnu.org/copyleft/gpl.html ################################################################################ -XBMC_LOCKED="/storage/xbmc_locked" -touch $XBMC_LOCKED +LOCKDIR="/var/lock/" +LOCKFILE="xbmc.disabled" +touch "$LOCKDIR/$LOCKFILE" wait_on_xbmc_exit reboot diff --git a/packages/sysutils/ConsoleKit/scripts/ck-system-stop b/packages/sysutils/ConsoleKit/scripts/ck-system-stop index cc93d11f2..edaa2b308 100755 --- a/packages/sysutils/ConsoleKit/scripts/ck-system-stop +++ b/packages/sysutils/ConsoleKit/scripts/ck-system-stop @@ -20,7 +20,8 @@ # http://www.gnu.org/copyleft/gpl.html ################################################################################ -XBMC_LOCKED="/storage/xbmc_locked" -touch $XBMC_LOCKED +LOCKDIR="/var/lock/" +LOCKFILE="xbmc.disabled" +touch "$LOCKDIR/$LOCKFILE" wait_on_xbmc_exit poweroff