Linux System suspend with xbmc and tvheadend
#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.
Reply
#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).
Reply
#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.
Reply
#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
Reply
#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.
Reply
#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.
Reply
#7
Ok, this is 2 years old thread but having similar problem so why not post here. Using Linux Mint 17.1 64 bit Mate

My lspci gives this:
Code:
01:09.2 Multimedia controller: Conexant Systems, Inc. CX23880/1/2/3 PCI Video and Audio Decoder [MPEG Port] (rev 05)
01:09.4 Multimedia controller: Conexant Systems, Inc. CX23880/1/2/3 PCI Video and Audio Decoder [IR Port] (rev 05)

In reboot it works fine, but after suspend it does not wake up.

Earlier (with Mint 17 / 32bit) all that was needed, was:
Code:
sudo invoke-rc.d tvheadend restart

http://localhost:9981/extjs.html status-page tells me this is "Conexant CX22702 DVB-T" and location / dev/dvb/adapter0. Signal strength is 56% before and after suspend.

When I command:
Code:
sudo /etc/init.d/tvheadend restart
Terminal says
Code:
* Restarting Tvheadend tvheadend                                        [ OK ]
BUT in tvheadend web control page log (at the bottom) it does not show "lost connection" or anything else indicating that it is truly sopped/started. My older Mint 17 / 32bit it did show "connection lost"-info when restarting.

How do I proceed from here?
Reply
#8
Nevermind, I installed tvheadend from correct repo and now everything works out of the box.
Reply
#9
I had the same problem but solutions from that topic didn't worked for me. I found a solution. I know it's an old topic but the trouble is still here.

Firstly, install pm-utils.
Code:
sudo apt-get install pm-utils

Secondly create a file named /etc/pm/sleep.d/50_tvheadend and write inside:
Code:
#!/bin/sh

case "${1}" in
  hibernate|suspend)
        service tvheadend stop
        modprobe -r dvb_usb_dib0700
        ;;
  resume|thaw)
        modprobe dvb_usb_dib0700
        service tvheadend start
        ;;
  *)
    ;;
esac
We have to stop tvheadend before unload module otherwise there is an error : "modprobe: FATAL: Module dvb_usb_dib0700 is in use." I tried to stop tvheadend with /etc/init.d/tvheadend stop but it's not working.
Reply
#10
My system stopped working couple of days ago (original problem came back), and this helped, THANKS!
Reply
#11
Hi

Since many years, I have lost almost all my hairs trying to build a stable and efficient HTPC with WINDOWS.
But today, I'am done. Confused
So I give a try with LINUX. Blush

So I have installed UBUNTU, KODI and TVHEADEND.

Configuring TVHEADEND is not that obvious.
But my TV card had been recognized and it works! it is a TERRATEC CYNERGY PCIE DUAL T
I can play TV with KODI.

But I encounter that SUSPEND issue and fall into that thread.
I had also this anomaly with WINDOWS at the begining, few years ago, and after months waiting TERRATEC had produced a new driver.
The root cause is the same and solution also.
they are primary given here: http://www.linuxtv.org/wiki/index.php/Te..._PCIe_dual
Quote:Known Issues

The cx25840 driver does not work after suspend/hibernate. To fix this issue you should unload the following modules before suspend and load it after wake up. And automated way to do this are the pm-utils hooks or systemctls sleep hooks for systemd systems.
cx23885 cx25840

The solution given at the top of this thread works, BUT ONLY ONCE Sad
I mean, if I reboot then I suspend once, TV plays at resume.
But if I suspend a second time, TV does NOT play and I have a message on KODI : "TVHEADEND HTSP client : no input detected".

I need HELP, PLEASE.
What could I look for?
Reply
#12
Additionnal infos:

I have look into /var/log/pm-suspend.log
During the 1st SUSPEND, cx23885 and cx25840 are unloaded successfully:
Code:
Unloading kernel module cx23885...Done.
Unloading kernel module cx25840...Done.
/usr/lib/pm-utils/sleep.d/75modules suspend suspend: success.

But NOT during the 2nd SUSPEND:
Code:
Unloading kernel module cx23885...modprobe: FATAL: Module cx23885 is in use.
/usr/lib/pm-utils/sleep.d/75modules: 89: /usr/lib/pm-utils/sleep.d/75modules: log: not found
Failed.
Unloading kernel module cx25840...modprobe: FATAL: Module cx25840 is in use.
/usr/lib/pm-utils/sleep.d/75modules: 89: /usr/lib/pm-utils/sleep.d/75modules: log: not found
Failed.
/usr/lib/pm-utils/sleep.d/75modules suspend suspend: success.

although tvheadend is successfully unloaded just before:
Code:
Running hook /etc/pm/sleep.d/50_tvheadend suspend suspend:
* Stopping Tvheadend tvheadend
   ...done.
/etc/pm/sleep.d/50_tvheadend suspend suspend: success.

Something is using those tv drivers, but WHAT?Huh
Reply

Logout Mark Read Team Forum Stats Members Help
System suspend with xbmc and tvheadend2