Page 1 of 9 123 ... LastLast
Results 1 to 10 of 86

Thread: ACPI wakeup on mythbuntu 9.04

  1. #1
    Join Date
    Apr 2009
    Beans
    10

    [HOW-TO]:ACPI wakeup on mythbuntu 9.04

    the acpi wiki's tends to be difficult to follow in places as they cater for multiple scenario's mostly at older versions. Here is my attempt at a HOW-TO for mythbuntu 9.04

    Assumptions/Prequisites
    - mythbuntu 9.04
    - front end and back end on same machine
    - bios clock using UTC (not local time)

    What to expect
    At completion of this how-to your system should suspend after the machine idle for predetermined period, it will shutdown. When it is time to do something, the machine will automatically restart and perform the activity required. Once complete and idle once more it will shutdown. The automatic shutdown can be overiden enabling the user uninterupted viewing.

    How it works
    Mythbackend is running and monitors activity. If it is idle for predetermined timeframe it will run a command mythshutdown with various switches and parameters.
    In summary if idle it runs the following commands.
    mythshutdown --check (this checks for activity). If a user is logged in, it will prevent shutdown by returning 1; if OK to shutdown will return a 0 (same as exit 0)
    mythshutdown --settime $time (this stores the time for next wakeup, it does not write to bios h/w clock )
    mythshutdown --shutdown (this triggers a script that sets time to wakeup in bios h/w clock and then shutdown/power off the computer)

    When you boot the machine, the mythwelcome screen will be displaye. The mythwelcome program monitors activity and displays status of the backend. If the machine is idle for a preset time (noted by a countdown in mythwelcome, it will automatically shutdown the computer)

    If whilst mythwecome is running, the user presses select/enter on remote/keyboard, the mythfrontend application will be started enabling the user to watch tv etc. If the mythfrontend is running, the machine will prevented from shutting down. To enable automatic shutdown/wake capability, the user must return to the mythwelcome screen by entering stop/end. THIS IS IMPORTANT!

    STEP 1 - check bios clock is UTC
    to check if bios clock is running UTC, start a command line session, then
    Code:
    $cat /proc/driver/rtc
    the rtc_time should be a UTC time

    STEP 2 - create MythWakeSet script
    Code:
    $mkdir ~/myscripts
    $cd ~/myscripts
    sudo apt-get install gedit
    gedit MythWakeSet
    The cut and paste following code (taken from acpi wake page https://help.ubuntu.com/community/My...tNext/ACPIWake)

    Note: if you have gedit installed already, there is no need to reinstall it; if you are not sure type gedit to determine if it installed.

    Code:
    #!/bin/sh
     
    # inspired from http://www.mythtv.org/wiki/index.php/ACPI_Wakeup
    # and https://help.ubuntu.com/community/MythTV/Install/WhatNext/ACPIWake
    #
    # MythWakeSet
    #
    # set mythtv wake-up time with UTC-adjusted time
    #
    # use: MythWakeSet date time      
    # ex.: MythWakeSet 2008-11-02 20:15:00
    # See also 'man date' for date/time-formats.
     
    # TimeZone, use +0100 for GMT+1
    #TZ="+0100"
    TZ=$(date +%z)
     
    LOG=/var/log/mythtv/mythbackend.log
     
    DATE=$(date -d "$1 $2 $TZ" "+%F %H:%M:%S" -u)
    SECS=$(date -d "$1 $2" "+%s")
     
    echo Running $0 to set the wakeup time to $1 $2 >>$LOG
     
    if [ -e /sys/class/rtc/rtc0/wakealarm ]; then
      echo 0 > /sys/class/rtc/rtc0/wakealarm
      echo $SECS > /sys/class/rtc/rtc0/wakealarm
      echo "echo 0 > /sys/class/rtc/rtc0/wakealarm" >>$LOG
      echo "echo $SECS > /sys/class/rtc/rtc0/wakealarm" >>$LOG
      cat /proc/driver/rtc  >>$LOG
    else
      if [ -e /proc/acpi/alarm ]; then
        echo $DATE > /proc/acpi/alarm
        echo "echo $DATE > /proc/acpi/alarm" >>$LOG
      else
        echo "ERROR, Wakeup not set, no /sys/class/rtc/rtc0/wakealarm and no /proc/acpi/alarm found" >>$LOG
      fi
    fi
    save the script
    now make the script executable and put it in /usr/bin

    Code:
    $ chmod +x MythWakeSet
    $ sudo cp MythWakeSet /usr/bin
    Brief explanation of script: the scripts takes the time in yyyy-MM-dd hh:mm:ss and converts it secs since 19.. in UTC. It then writes the time to bios hw clock (not sure). This done by echo $SECS > /sys/class/rtc/rtc0/wakealarm command. The /prco/acpi/alarm is legacy and is not used in 9.04.


    STEP 3 - configure backend to sleep/wake
    Stop the backend and setup

    Code:
    $ sudo /etc/init.d/mythtv-backend stop
    $ mythtv-setup
    Proceed to general>Shutdown/Wakeup Options
    untick Block shutdown before client connected
    Set idle shutdown timeout (secs): 120
    Set Max. wait for recordings (min): 15
    Set Startup before rec (secs): 200
    Set Wakeup time format: yyyy-MM-dd hh:mm:ss
    Set Command to set Wakeup Time: sudo -H mythshutdown --setwakeup "$time"
    Set Server Halt command: sudo -H mythshutdown --shutdown
    Set pre shutdown check-command: mythshutdown --check

    Note: if you are using EIT; you need to set the idle time to less that 5 minutes. If set longer, the EIT scan will interupt the idle time and it will never expire and hence the box will not shut down. In have set it to 120 secs here.

    STEP 4 - get mythwelcome to run a startup

    Now you need to get mythwelcome working

    Code:
    $sudo cp  /etc/mythtv/session-settings /etc/mythtv/session-settings.old
    $sudo gedit /etc/mythtv/session-settings
    modify line from
    Code:
    #MYTHWELCOME=true
    to
    Code:
    MYTHWELCOME=true
    save the file

    STEP 5 - configure mythwelcome

    run setup for mythwelcome
    Code:
    $mythwelcome --setup
    update the setup page as follows:

    set nvram-wakeup Command: sudo -H /usr/bin/MythWakeSet "$time"
    set nvram-wakeup Restart Command: leave blank!
    set Command to reboot: sudo -H shutdown -h -r now
    set Command to shutdown: sudo -H shutdown -h -P now

    exit mythwelcome setup.

    STEP 6 - get everything working
    reboot system by
    Code:
    $sudo reboot
    now the system will start with mythwelcome then load mythfrontend.

    STEP 7 - prevent mythfrontend from starting on restart
    To prevent frontend from starting at next reboot, exit mythfrontend and return to mythwelcome.

    Prior to doing this step. You may need lock the system by selecting "m" on the keyboard and selecting lock shutdown. This will prevent the machine from shutting down whilst you are within mythwelcome. Remember to unlock after you are finished otherwise the machine will never shutdown.

    Hit "i" on keyboard and untick Automatically Start Myth Frontend. This will prevent mythfrontend from starting next time you reboot

    STEP 8 - TEST
    Now to test

    reboot as before

    you should be at the mythwelcome screen
    hit select/enter on remote/keyboard to start mythfrontend and schedule a program to record about 30 minutes in the future (not less the 15 minutes).
    now return to mythwelcome by pressing stop/Esc button few times

    the machine should automatically shutdown in approximately 2 minutes (see count down). If mythwelecome indicates that there are jobs in the queue being processed, it will not shutdown until jobs are complete. You will need to perform a retest after the jobs are completed.

    Aproximately 2 minutes prior to the time, the machine should restart and start mythwelcome. The machine should record and on completion and idle, it will shutdown.

    Note: you can prevent shutdown at any time by starting mythfrontend within 2 minutes of boot from mythwelcome. But to recommence shutdown, you must return to mythwelcome.

    Hope this helps.

    This information was taken from a number of sources including

    http://www.mythtv.org/wiki/ACPI_Wakeup
    and
    https://help.ubuntu.com/community/My...tNext/ACPIWake

    a more detailed explanation can be at these sites.

    Note: I had an issue with frontend starting before the backend was ready. For solution see this:
    http://ubuntuforums.org/showthread.php?t=1176303
    Last edited by zaprat; June 3rd, 2009 at 08:49 AM.

  2. #2
    Join Date
    Oct 2006
    Beans
    Hidden!

    Re: ACPI wakeup on mythbuntu 9.04

    I tried your script and it works perfectly! I never got the ACPI wakeup to work actually.

    I used a script before which uses the RTC alarm in the bios. It's configured on a fixed date which the script knows (2008-12-31 23:59:59). When the computer shuts down it calculates the number of seconds before the computer has to wake, it subtracts those seconds of the configured time in the bios. When to computer starts, it restores the old time by adding those subtracted seconds back. It really worked until Jaunty because now all the services are booting at the same time. The time is restored after some services were already started, including mythbackend which thought it was 2008-12-31.

    Anyway, i was looking for a solution and this made everything running perfect.

  3. #3
    Join Date
    Apr 2009
    Beans
    10

    Re: ACPI wakeup on mythbuntu 9.04

    I noted an error with one of the mythshutdown parameters (missing - for --shutdown). I have corrected it. I have edited/corrected in the original post. I have also added some additional wording to make things flow better.

  4. #4
    Join Date
    Apr 2005
    Location
    Petoskey, MI
    Beans
    346
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: ACPI wakeup on mythbuntu 9.04

    Oh, this is great! I cannot wait to implement this configuration over the weekend. I am trying to "go green" in my home and try to have only one PC turned on 24/7, which is my web/file server, right now my Mythbuntu box runs 24/7 as well, which is not necessary since I moved all the Video, Pictures, and Music shares off of it.

    Thank you VERY much for writing this.
    -user error

    | I enjoy Linux! | Using 64bit Ubuntu! |

  5. #5
    Join Date
    Apr 2005
    Location
    Petoskey, MI
    Beans
    346
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: ACPI wakeup on mythbuntu 9.04

    Odd,

    I must not be doing something right. Mine is not doing a count down, ever.

    if try to run the first script manually, i can only run it as sudo and i get this error:

    Code:
    date: invalid date `  -0400'
    -user error

    | I enjoy Linux! | Using 64bit Ubuntu! |

  6. #6
    Join Date
    Nov 2008
    Beans
    3

    Re: ACPI wakeup on mythbuntu 9.04

    Hi Zaprat, thanks for your tutorial.
    I tried your script too but with no success.
    When I go out from frontend I can see the Mythwelcome screen, countdown start but, at 10s from the shutdown It restart!! so contdown restart ciclically untill I press "Start Frontend" or exit from the contextual menu.
    Can you help me?
    Thanks

  7. #7
    Join Date
    Aug 2007
    Beans
    11

    Re: ACPI wakeup on mythbuntu 9.04

    Quote Originally Posted by electrogulp View Post
    Hi Zaprat, thanks for your tutorial.
    I tried your script too but with no success.
    When I go out from frontend I can see the Mythwelcome screen, countdown start but, at 10s from the shutdown It restart!! so contdown restart ciclically untill I press "Start Frontend" or exit from the contextual menu.
    Can you help me?
    Thanks
    I'm having the same problem- Mythwelcome counts down, gets to 0, then starts counting again from the start. However, it occasionally works

    Can you run up mythwelcome and mythbackend in terminal, and copy/paste what it says? For me, MythWelcome says (once it gets to "0", can't copy and paste it 'cos it managed to shut down this time):

    Code:
    NOTE: some of the terminal was off the screen- I was using VNC, this is off a screenshot, so some of the commands might be missing at the end- i'll have another look when it boots
    
    CheckShutdownServer returned - OK to shutdown
    Running the command to set the next scheduled wakeup time:
    sudo -H mythshutdown --setwakeup "2009-07-22 15:26:40"
    2009-07-22 15:09:45.670 Running the command to shutdown this computer :
    sudo -H mythshutdown --shutdown
    
    date: invalid date '1248247600 +0800'
    date: invalid date '1248247600 '
    MythBackend just gives a "The system will power off now!" message

    Any help would be appreciated!

    EDIT: Had to manually boot it back up
    Last edited by Mitch72; July 22nd, 2009 at 08:30 AM.

  8. #8
    Join Date
    Apr 2007
    Beans
    Hidden!

    Re: ACPI wakeup on mythbuntu 9.04

    Hey,

    Im trying to set this up now too and have come across loads or problems but am pretty close now.

    I had the problem with the countdown reaching 0 and then restarting, which for me was cause by mythtv asking for the sudo password in the background and being unable to actually ask for it nothing happened.

    To fix it i opened terminal and typed sudo visudo

    And at the bottom on the file i added

    %mythtv ALL = NOPASSWD: /usr/bin/MythWakeSet, /sbin/shutdown, /bin/sh, /usr/bin/setwakeup.sh

    And that seems to have worked.

  9. #9
    Join Date
    Aug 2007
    Beans
    11

    Re: ACPI wakeup on mythbuntu 9.04

    Thanks Sniper, looks like that was the problem I was having, I'll have to look into it

    EDIT: Yep, it was. Thanks! Needed to change it slightly, had to include /usr/bin/mythshutdown (although it might not be needed...)

    Still having problems with the system starting up though

    EDIT: K, I've been able to have the system successfully wake up by using the commands here.

    By looking at 'cat /proc/driver/rtc/' in the mythtv log, the alrm_date is coming up as ****-07-25, even though the epoch time listed seems correct. From the info in the ACPI Wakeup wiki, i'm guessing that it's being set to a time in the past?
    Last edited by Mitch72; July 25th, 2009 at 09:43 AM.

  10. #10
    Join Date
    Nov 2008
    Location
    Karlsruhe
    Beans
    21
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: ACPI wakeup on mythbuntu 9.04

    Ok, after some changes the shutdown is working. I also added /usr/bin/mythshutdown with sudo visudo. Now the system is going down.

    Wake up isn´t still working correctly. I have to do some work on it.

    Thanks for your script Zaprat
    Last edited by TVtalker; July 28th, 2009 at 05:07 PM. Reason: update

Page 1 of 9 123 ... LastLast

Tags for this Thread

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
  •