Linux - System suspend with xbmc and tvheadend

  Thread Rating:
  • 2 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
joethefox Offline
Team-Kodi Member
Posts: 1,313
Joined: Nov 2010
Reputation: 22
Post: #1
(Yes. Suspend is working on linux Big Grin)

My system is an ubuntu 12.04 but I think is the same for 11.10.

Prerequisite: pm-utils

Code:
$ sudo apt-get install pm-utils

on ubuntu systems.

The issue in my case was because the dvb_usb_dib0700 and budget_ci modules needed to be suspended before the suspend action. tvheadend needs to be stopped as well.

Under /etc/pm/sleep.d create a file named, for example, 50_tvheadend and write inside:

Code:
#!/bin/sh

case "${1}" in
  hibernate|suspend)
    /etc/init.d/tvheadend stop
        ;;
  resume|thaw)
    /etc/init.d/tvheadend start
        ;;
  *)
    ;;
esac

ALTERNATE: If you have monit installed (yes, I've installed monit to control when very occasionally tvheadend crashes Big Grin) to monitor tvheadend change the content of 50_tvheadend with:
Code:
#!/bin/sh

case "${1}" in
  hibernate|suspend)
    /etc/init.d/monit stop
    /etc/init.d/tvheadend stop
        ;;
  resume|thaw)
    /etc/init.d/monit start
    /etc/init.d/tvheadend start
        ;;
  *)
    ;;
esac

save and close the file and set the correct file permissions:
Code:
$ sudo chmod 755 50_tvheadend

Then create under /etc/pm/config.d a file named modules and write inside:
Code:
SUSPEND_MODULES="dvb_usb_dib0700 budget_ci"

if your dvb modules are different, place the correct ones and save and close the file.

Done. Big Grin Now suspend should work.

Hope this can be useful for someone.
find quote
Serafean Offline
Junior Member
Posts: 17
Joined: Nov 2011
Reputation: 0
Post: #2
Hi, very nice, I have one nifty addition : if there are planned recordings, set the rct alarm to wake the PC up in time for the recording. I have written this script that should do just that.
Code:
#!/bin/bash

date=`date +%s`
echo $date

while read lne;do
  echo $lne
  if [ $lne -gt $date ];then
    latest=$lne
    echo "bigger"
  else
    break;
  fi

done < `cat $dir/* | grep \"start\" | cut -d ":" -f 2 | sed "s/^ \([0-9][0-9]*\),$/\1/" | sort -r`
echo  $(($latest-60)) > /sys/class/rtc/rtc0/wakealarm
This wakes up the PC 60 seconds befor the recording is supposed to start, that should be enough time for any housekeeping.
$dir is the ~/.hts/tvheadend/dvr/log/ directory (where tvheadend keeps its dvr logs).

Note that I haven't tested it in its current form, the time setting works fine, the $dir redirection is untested (I'm not on my tvheadend machine, so I used a pre-parsed file).
(This post was last modified: 2012-03-21 16:30 by Serafean.)
find quote
esofron Offline
Junior Member
Posts: 5
Joined: Feb 2011
Reputation: 0
Post: #3
(2012-03-21 16:10)Serafean Wrote:  Hi, very nice, I have one nifty addition : if there are planned recordings, set the rct alarm to wake the PC up in time for the recording. I have written this script that should do just that.
Code:
#!/bin/bash

date=`date +%s`
echo $date

while read lne;do
  echo $lne
  if [ $lne -gt $date ];then
    latest=$lne
    echo "bigger"
  else
    break;
  fi

done < `cat $dir/* | grep \"start\" | cut -d ":" -f 2 | sed "s/^ \([0-9][0-9]*\),$/\1/" | sort -r`
echo  $(($latest-60)) > /sys/class/rtc/rtc0/wakealarm
This wakes up the PC 60 seconds befor the recording is supposed to start, that should be enough time for any housekeeping.
$dir is the ~/.hts/tvheadend/dvr/log/ directory (where tvheadend keeps its dvr logs).

Note that I haven't tested it in its current form, the time setting works fine, the $dir redirection is untested (I'm not on my tvheadend machine, so I used a pre-parsed file).

Hi can you give us some details, where to save the file etc ?

thanks.
find quote
Snippo Offline
Senior Member
Posts: 142
Joined: Dec 2011
Reputation: 4
Post: #4
I also was having the problem that suspend wouldn't work. This topic helped me to fix it but I had to change a few things. I'm using a TBS6981 card which uses the cx23885 module. Adding it to the file in config.d wouldn't work for me. I also had the problem that oscam stopped working after suspending the machine. I managed to fix it by creating a file "99_tvheadend" in /etc/pm/sleep.d with the following content:

Code:
#!/bin/sh

case "${1}" in
  hibernate|suspend)
    /etc/init.d/tvheadend stop
    /etc/init.d/oscam stop
    sudo modprobe -r cx23885
    sudo modprobe -r ftdi_sio
        ;;
  resume|thaw)
    sudo modprobe cx23885
    sudo modprobe ftdi_sio
    /etc/init.d/oscam start
    /etc/init.d/tvheadend start
        ;;
  *)
    ;;
esac

If named "50_tvheadend" it didn''t work because the cx23885 wouldn't unload properly. With the above it works fine though Smile
find quote
joethefox Offline
Team-Kodi Member
Posts: 1,313
Joined: Nov 2010
Reputation: 22
Post: #5
@snippo, thanks for sharing your experience. I think that despite the insertion of the removal of the module at the end of the other tasks (99_ instead of 50_) works at 99.99% of the time, if we let pm decide when suspending the modules perhaps we can cover the remaining 0.01% of cases. Just for curiosity, Instead of using /etc/pm/sleep.d/modules creating the file /etc/pm/sleep.d/config and always putting inside
Code:
SUSPEND_MODULES="cx23885 ftdi_sio"
maybe should work.
find quote
Serafean Offline
Junior Member
Posts: 17
Joined: Nov 2011
Reputation: 0
Post: #6
(2012-04-12 09:23)esofron Wrote:  Hi can you give us some details, where to save the file etc ?

thanks.


Sorry, forgot to subscribe....

Put the file anywhere you want, just make sure that this script is run at suspend time, and that should do the trick.Also make sure that you set the $dir variable in the script.
find quote