Results 1 to 8 of 8

Thread: 15.04 suspend script not running and needs sudo privilege for modprobe MythTV

  1. #1
    Join Date
    Oct 2015
    Beans
    3

    15.04 suspend script not running and needs sudo privilege for modprobe MythTV

    I'm running 15.04 along with MythTV. The computer can suspend but freezes on resume. I've traced this down to a problem with mythbackend and module saa7164. I've written a script that I can manually run that will kill mythbackend and then unload module saa7164. The script needs sudo privileges to modprobe saa7164. I've also written a script that reloads module saa7164 and then resumes mythbackend. When I do things manually I can run the first script, then suspend, then resume, run the second script, and everything works fine.
    My problem is I want these to run on suspend/resume automatically and not prompt for a password. I've tried every solution that I could find. I've placed test scripts in /etc/pm/sleep.d and tried the solution posted in this link as well:
    Ubuntu 15.04 Suspend doesn't run `pm-suspend`

  2. #2
    Join Date
    Jun 2005
    Location
    Toronto, Canada
    Beans
    Hidden!
    Distro
    Xubuntu 16.04 Xenial Xerus

    Re: 15.04 suspend script not running and needs sudo privilege for modprobe MythTV

    systemd suspend hooks can still be used. Place your executable file in /lib/systemd/system-sleep using the following template:
    Code:
    #!/bin/sh
    case $1/$2 in
      pre/*)
        echo "Going to sleep/hibernate..."
        #your code here
        ;;
      post/*)
        echo "Waking up from sleep/hibernate..."
        #your code here
        ;;
    esac
    ...this will be run with root privileges so no sudo is needed. Reboot might be required, I'm not sure.

    See also: http://ubuntuforums.org/showthread.php?t=2284724

  3. #3
    Join Date
    Oct 2015
    Beans
    3

    Re: 15.04 suspend script not running and needs sudo privilege for modprobe MythTV

    The script is running after placing into /lib/systemd/system-sleep. I can suspend/resume and the module gets unloaded/reloaded. For whatever reason though mythbackend doesn't resume on "Wake Up".

    Code:
    #!/bin/sh
    case $1/$2 in
        pre/*)
            echo "Entering sleep..." >  /tmp/sleep.log
            echo "Entering sleep"
            killall mythbackend
            sleep 1        
            modprobe -r saa7164
            sleep 5
            echo "After modrobe..." >> /tmp/sleep.log
            ;;
        post/*)
            echo "Waking up..." >> /tmp/sleep.log        
            modprobe saa7164
            sleep 5
            echo "After modprobe..." >> /tmp/sleep.log        
            mythbackend
            sleep 1
            echo "After mythbackend..." >> tmp/sleep.log
            ;;
    esac
    This is the output of tmp/sleep.log

    Entering sleep...
    After modrobe...
    Waking up...
    After modprobe...
    After mythbackend...
    Any other place I can look to see what is actually happening with mythbackend?

  4. #4
    Join Date
    Jun 2005
    Location
    Toronto, Canada
    Beans
    Hidden!
    Distro
    Xubuntu 16.04 Xenial Xerus

    Re: 15.04 suspend script not running and needs sudo privilege for modprobe MythTV

    Try capturing the mythbackend output via:
    Code:
    mythbackend > /tmp/mythbackend.log 2>&1
    ...and after your resume attempt, have a look at the /tmp/mythbackend.log file.

  5. #5
    Join Date
    Oct 2015
    Beans
    3

    Re: 15.04 suspend script not running and needs sudo privilege for modprobe MythTV

    Toz,

    Here is the output of mythbackend.log

    2015-11-19 14:52:41.801329 C mythbackend version: fixes/0.27 [v0.27.5-42-gacd481d] www.mythtv.org2015-11-19 14:52:41.801344 C Qt version: compile: 4.8.6, runtime: 4.8.6
    2015-11-19 14:52:41.801347 N Enabled verbose msgs: general
    2015-11-19 14:52:41.801354 N Setting Log Level to LOG_INFO
    2015-11-19 14:52:41.812460 I Added logging to the console
    2015-11-19 14:52:41.812984 I Setup Interrupt handler
    2015-11-19 14:52:41.812992 I Setup Terminated handler
    2015-11-19 14:52:41.812999 I Setup Segmentation fault handler
    2015-11-19 14:52:41.813006 I Setup Aborted handler
    2015-11-19 14:52:41.813012 I Setup Bus error handler
    2015-11-19 14:52:41.813018 I Setup Floating point exception handler
    2015-11-19 14:52:41.813026 I Setup Illegal instruction handler
    2015-11-19 14:52:41.813033 I Setup Real-time signal 0 handler
    2015-11-19 14:52:41.813061 N Using runtime prefix = /usr
    2015-11-19 14:52:41.813067 N Using configuration directory = //.mythtv
    2015-11-19 14:52:41.813115 I Assumed character encoding: en_US.UTF-8
    2015-11-19 14:52:41.813126 W Cannot locate your home directory. Please set the environment variable HOME
    2015-11-19 14:52:41.813131 C Failed to init MythContext.
    2015-11-19 14:52:41.915726 I New Client: (#1)
    The script in systemd is working. The SAA7164 module is being successfully removed/added. I'm not sure what's wrong with the MythTV side of things.

    On another random but similar note, in 14.04 I had added a command in the "startup applications" menu to run mythbackend on power up. Now, in 15.04, I know that it's starting up, however I need to manually open a terminal and start mythbackend before I can tune channels. Any way that it's the same problem occurring after suspend/resume?

  6. #6
    Join Date
    Sep 2013
    Beans
    1

    Re: 15.04 suspend script not running and needs sudo privilege for modprobe MythTV

    I'm having a similar problem getting tvheadend and saa7164 to suspend and resume. My system uses Ubuntu 15.04 and a Hauppauge 2250 TV tuner. It's interesting that you were able to get saa7164 to successfully stop/start. The TV tuner's driver/module, saa7164, fails to unload everytime I run "modprobe -r saa7164". I started a question on AskUbuntu going over my experience: http://askubuntu.com/q/724052/171608

    Any help getting saa7164 to unload/load is greatly appreciated.

  7. #7
    Join Date
    Apr 2009
    Beans
    4

    Re: 15.04 suspend script not running and needs sudo privilege for modprobe MythTV

    On another random but similar note, in 14.04 I had added a command in the "startup applications" menu to run mythbackend on power up. Now, in 15.04, I know that it's starting up, however I need to manually open a terminal and start mythbackend before I can tune channels
    I had exactly the same problem in 15.04. In my case, and I suspect yours, it is due to the increased efficiency, and parallel operations, of Ubuntu's startup. The desktop, and the startup applications are executed before the boot sequence is completed.

    In short, mythbackend fails because your tuner card has not yet had its firmware installed - mythbackend can't find any tuner cards when it tries to run.

    I'm sure there is a more elegant solution, but my fix was to make the mythtvbackend startup command with a sleep 5; in front. You may need to change the 5 depending on the speed of your machine.

  8. #8
    Join Date
    Apr 2009
    Beans
    4

    Re: 15.04 suspend script not running and needs sudo privilege for modprobe MythTV

    Quote Originally Posted by guttermonk2 View Post
    I'm having a similar problem getting tvheadend and saa7164 to suspend and resume. My system uses Ubuntu 15.04 and a Hauppauge 2250 TV tuner. It's interesting that you were able to get saa7164 to successfully stop/start. The TV tuner's driver/module, saa7164, fails to unload everytime I run "modprobe -r saa7164". I started a question on AskUbuntu going over my experience: http://askubuntu.com/q/724052/171608

    Any help getting saa7164 to unload/load is greatly appreciated.
    I got this working in the last 24 hours. Here is my solution:

    1. I created the following script which I placed in /usr/local/bin named closemyth.sh with a chmod +x to make it executable

    until [ $? -ne 0 ]
    do
    killall -2 mythbackend
    sleep 5
    done
    rmmod saa7164
    bash /home/m/sleep.sh
    modprobe saa7164
    mythbackend

    Explanation: The until loop sends a request to mythbackend to terminate gracefully. We loop until we don't find anything to kill - mythtvbackend has ended
    We remove the saa7164 module, run our desired suspend command (which I have in folder /home/m/sleep.sh - more on that later)
    The next two lines are run after resuming from the suspend - we add the saa7164 module back, and then restart mythbackend

    2. This requires root privileges so I create the file mythtv in /etc/sudoers.d

    m ALL = NOPASSWD: /usr/sbin/rtcwake, /usr/local/bin/closemyth.sh

    where m is the user name of the logged in user (m for mythtv - I'm lazy)

    Make sure you set permissions correctly on this file:
    sudo chmod 0440 /etc/sudoers.d/mythtv

    3. Let's manually test

    First manually create the sleep command script in whatever folder you are using - I had /home/m/sleep.sh above

    sudo /usr/sbin/rtcwake -m mem -s 60

    This will sleep for 60 seconds to memory ( a suspend to RAM) - replace mem with disk if you want to suspend to disk - I prefer mem as I can press any key on the keyboard to wake up near instantaneously - but it does use a little more power.

    now we should be able to type

    closemyth.sh

    and your machine should suspend for 60 seconds and mythtv will work before and after

    4. Finally, let's automate. From a terminal

    mythtv-setup
    (You can continue with the backend running)
    a) Choose 1. General
    b) Next your way to the Shutdown/Wakeup options page
    c) Chose Idle Shutdown timeout (I chose 60 seconds)
    d) Choose maximum wait for recording (I chose 5 mins - but remember I am suspendingto RAM)
    e) Choose startup before recording (I chose 180 seconds)
    f) Wakeup time format - use time_t
    g) Command to set wakeup time - this is where I actually store my sleep command to be executed by the closemyth.sh script - so you need to choose a writeable folder - I just use my home folder, so my command is:
    echo sudo /usr/sbin/rtcwake -m mem -t $time> /home/m/sleep.sh
    h) Server halt command
    sudo /usr/local/bin/closemyth.sh

    Now Next and Finish your way out to save your settings.

    There are probably better and more elegant ways to do this. I'm open to suggested improvements. This works for me.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •