Difference between revisions of "Mythwelcome"

From MythTV Official Wiki
Jump to: navigation, search
(Mythwelcome/Mythshutdown Settings)
(MythShutdown program)
(32 intermediate revisions by 14 users not shown)
Line 1: Line 1:
 +
= Introduction =
 +
Mythwelcome is an mythTV application that can prevent the backend from shutting down the system
 +
if it is busy commercial flagging, downloading EPG data, transcoding or shutdown has been locked by
 +
a user. Mythwelcome can be very useful if you run both frontend and backend on a single machine and
 +
use [[ACPI_Wakeup]] to automatically shutdown and wakeup your machine. Prior to the introduction of MythWelcome, MythFrontend would always start up, and, therefore, MythBackend would never shut down.
 +
 +
= What is MythWelcome =
 +
MythWelcome is a Myth themed application that shows a welcome/status
 +
information screen that will be shown whenever the frontend is not
 +
running ie. when an automatic startup has occurred to record a program.
 +
It shows some information about what the backend is currently doing
 +
idle, recording, commercial flagging, transcoding or locked by a user etc.).
 +
It also shows what the backend is recording, what the next scheduled recording
 +
is and shows a warning if there are any schedule conflicts. There is also a
 +
push button to start the frontend.
 +
 +
It is useful if you want to setup a dedicated MythTV system that you
 +
don't want to run 24/7 but you want to automatically wake up to record
 +
just like a normal video recorder and shutdown again when it is idle.
 +
 +
Mythwelcome will also prevent the backend from shutting down the system
 +
if it is busy commercial flagging, downloading EPG data, transcoding or
 +
shutdown has been locked by a user.
 +
 +
= Working with mythwelcome =
 
A new addition in 0.19.  This utility program displays a myth themed dialog which shows a welcome/status information screen that is designed to be shown whenever the frontend is not running.
 
A new addition in 0.19.  This utility program displays a myth themed dialog which shows a welcome/status information screen that is designed to be shown whenever the frontend is not running.
  
Line 6: Line 31:
  
 
The Welcome screen will show the status of the backend and wait for you to manually start the frontend with your remote.
 
The Welcome screen will show the status of the backend and wait for you to manually start the frontend with your remote.
 +
 +
== Using MythWelcome/MythShutdown with ACPI ==
 +
 +
See the [[ACPI_Wakeup]] page for details on setting up ACPI Wakeup.
 +
 +
== MythShutdown program ==
 +
 +
The mythshutdown command line utility is a multi-purpose helper program used by
 +
both mythbackend and mythwelcome. The program needs to be configured to
 +
work properly by editing the settings in the GUI.
 +
 +
{{Note box|When performing testing be aware that mythshutdown will never shut down the system if the next wake up time is due soon. The default is 15 minutes.}}
 +
 +
The program can be run with the following parameters:
 +
<pre>
 +
        -w/--setwakeup time
 +
            time - should be in format yyyy-MM-ddThh:mm:ss
 +
 +
    sets the time the next scheduled recording is to start. Does not set the
 +
    time in the bios just sets the value in the database.
 +
            Usually called by the backend's 'Set wakeup time command'.
 +
 +
        -t/--setscheduledwakeup
 +
            sets the time the next scheduled recording is to start. Does not set the
 +
    time in the bios just sets the value in the database. Differs from
 +
            --setwakeup as this will query the database directly so doesn't
 +
            need the time passed to it.
 +
 +
-q/--shutdown
 +
            calls the mythwelcome 'Set Wakeup Time Command' and then runs the
 +
            mythwelcome 'Shutdown command'. Usually called by the backend's 'Server Halt
 +
    command'.
 +
 +
        -x/--safeshutdown
 +
            equal to -c -t -q. Checks shutdown is safe, sets scheduled wakeup time
 +
            in database and shutdown (runs 'Set Wakeup Time Command' then 'Shutdown command')
 +
 +
        -p/--startup
 +
            check how system was started. Will return 0 if system started for a scheduled
 +
            recording or daily wakeup period. Returns 1 if started manually
 +
 +
-c/--check flag
 +
            flag is 0 - don't check recording status
 +
                    1 - do check recording status (default)
 +
 +
    returns 0 safe to shutdown or 1 not safe to shutdown
 +
    this is usually called by the backend as the 'Pre-Shutdown Check command'.
 +
    will return 1 if shutdown is locked, mythcommflag is running, mythtranscode
 +
    is running, mythfilldatabase is running or we are in or about to start a
 +
    daily wakeup/shutdown period.
 +
 +
--lock
 +
    this will prevent mythbackend from shutting down the system even if
 +
    it is idle. It is useful if you want to do some maintenance on the system
 +
    and don't want the backend to shutdown the computer.
 +
 
 +
-u/--unlock
 +
    allows the backend to shutdown when idle
 +
                   
 +
-s/--status flag
 +
            flag is 0 - don't check recording status
 +
                    1 - do check recording status (default)
 +
 +
    returns a value indicating what programs are running that will prevent
 +
    the backend from shutting down. The value is an OR'd flag of the following
 +
    values:
 +
 
 +
    0 - Idle                - free to shutdown
 +
    1 - Transcoding        - mythtranscode is running
 +
    2 - Commercial Flagging - mythcommflag is running
 +
    4 - Grabbing EPG data  - mythfilldatabase is running
 +
    8 - Recording in progress - only valid if flag is 1
 +
  16 - Locked              - shutdown has been locked by a user 
 +
  32 - Has queued or pending jobs  -
 +
  64 - In wakeup period    - In a daily wakeup/shutdown period
 +
  128 - About to start wake - Less than 15 minutes to next wakeup period
 +
  255 - Setup is running... - mythtv-setup is running
 +
 +
   
 +
    used by mythwelcome to display a status message to the user and
 +
    by 'mythshutdown --check' itself to determine if it is safe to shutdown.
 +
 
 +
-v/--verbose debug-level
 +
            debug-level - use -v help for level info
 +
 +
    By default mythshutdown is silent and does not produce any output on the
 +
    console. This is by design because it is called often by mythwelcome and
 +
    mythbackend. You can add this parameter to make mythwelcome output some
 +
    messages to the console.              
 +
</pre>
 +
 +
== Mythwelcome/Mythshutdown Settings ==
 +
 +
Like most of MythTV Mythwelcome and Mythshutdown store their settings
 +
in the myth database. All of the settings are settable from the GUI.
 +
There are two separate settings pages. One is shown by starting
 +
mythwelcome with the -s/--setup parameter or by pressing the
 +
'SHOWSETTINGS' key (defaults to F11 key) in Mythwelcome. You will probably only ever
 +
set these options once when you first setup Mythwelcome.
 +
 +
<pre>
 +
Command to Set Wakeup Time
 +
            Command to run to set the ACPI alarm in bios. The $time variable will contain the next wakeup time
 +
                   
 +
        Wakeup time format
 +
            Format for the time string passed to the 'Set Wakeup Time Command. Set to 'time_t' for seconds
 +
            since epoch.
 +
               
 +
nvram-wakeup Restart Command
 +
            Must be set to a blank value if using ACPI wakeup.
 +
 +
        Command to reboot
 +
            Command used to reboot system.
 +
 +
        Command to shutdown
 +
            Command used to shutdown system.
 +
 +
        Command to run Xterm
 +
            This is the command to use to open an XTerm window.
 +
    Leave blank to disable this feature.
 +
    Tip: If the default font size is too small to see on your
 +
    TV change the default setting to:
 +
    'xterm -fa Courier -fs 14' to change the font style and size.
 +
                                                           
 +
Command to start the Frontend
 +
            This is the command mythwelcome should use to start the FE. It
 +
    is usefull if you want to change the verbose level or add a log
 +
    file to output message etc.
 +
</pre>
 +
 +
[[Image:WelcomeScreen3.jpg]]
 +
 +
The second set of settings are available by pressing 'i/INFO' key in mythwelcome and allows you
 +
to setup the daily wakeup/shutdown periods and control whether to automatically
 +
start the mythfrontend when mythwelcome is started and it is determined that it
 +
was started manually.
 +
 +
<pre>
 +
Period 1 Start Time  - These setting determine a period of time that the master backend
 +
Period 1 End Time      should always wake up for. Set both times to 00:00 to
 +
                      disable this feature.
 +
 +
Period 2 Start Time  - Second wakeup/shutdown period settings.                 
 +
Period 2 End Time      Note: Period 1 and period 2 should be in correct chronological order.
 +
                              So for example if you have two periods 10:00-13:00 and 19:00-22:00 then
 +
                              10:00-13:00 must be period 1 and 19:00-22:00 must be period 2. This is
 +
                              because if  the start times for both daily wakeup periods has passed for
 +
                              today then the next wake time will be set to the first daily wakeup time
 +
                              tomorrow even if the second daily wakeup time is before the first.
 +
 +
Automatically Start  - Normally when mythwelcome starts up it checks to see whether
 +
Mythfrontend          the system was started to record something or because of a
 +
                      wakeup/shutdown period. If not it will automatically start the
 +
                      frontend. You can disable this feature by unchecking this option. 
 +
 +
Shutdown with Master - (Frontend only machines). If set mythwelcome will shutdown this system
 +
Backend                when the master backend shutsdown.
 +
</pre>
 +
 +
A popup menu is available by pressing the 'm/MENU' key in mythwelcome and allows you to lock/unlock the machine
 +
from shutting down, run mythfilldatabase or do a shutdown now.
 +
 +
<pre>
 +
POPUP MENU
 +
If you press the m/MENU key mythwelcome will display a popup menu with the
 +
following options.
 +
 +
Lock Shutdown        -  Prevents the system from shutting down even if it is idle.
 +
 +
Unlock Shutdown      -  Allows the system to shutdown when it is idle.
 +
 +
Run Mythfilldatabase -  Force mythfilldatabase to run now.
 +
 +
Shutdown Now        -  Force the system to shutdown even if it is not idle or is
 +
                        in a wakeup/shutdown period.
 +
 +
                        FE only machines simply shutdown using the 'Poweroff command'
 +
                        that has been setup in settings.
 +
 +
                        Master BE machines will not shutdown if the backend
 +
                        is recording or is about to start recording otherwise
 +
                        mythwelcome sets the time of the next wakeup and shuts down
 +
                        the system.
 +
 +
                        Requires sudo to be setup properly to allow mythwelcome to call
 +
                        the mythshutdown program with root privileges. See above.
 +
 +
Exit                -  Exit the mythwelcome application.
 +
 +
Cancel              -  Cancel the popup menu.                                   
 +
</pre>
 +
 +
Don't forget: you will most likely need to [[Mythwelcome#Allow_a_user_to_run_the_MythShutdown_program_with_root_privileges | set up sudo]], as well.
 +
 +
== Start xterm ==
 +
 +
There is a hidden feature that allows you to start an xterm from the mythwelcome
 +
screen. Useful if you need to do some trouble shooting. You can access it by
 +
pressing the F12 key (default key binding). You can change the command that will
 +
be used to start the xterm on the Mythshutdown settings page (F11 key).
 +
 +
== evilwm ==
 +
 +
mythwelcome is known to have focus problems with evilwm.  If you are experiencing any
 +
problems try running mythwelcome under a xterm, i.e.
 +
 +
xterm -e mythwelcome
 +
 +
== Configuring the Cases Power Button to Shutdown via Mythwelcome (optional) ==
 +
 +
Reconfiguring the cases power button to kill the mythfrontend is an easy way to trigger a clean/managed shutdown from a hardware control. By killing mythfrontend, mythwelcome will manage a clean shutdown (i.e when mythbackend is not busy recording... or locked e.t.c.).
 +
 +
The following was tested on Mythbuntu / Ubuntu 11.04 32bit
 +
 +
Step 1: Backup the following (in case you need to revert):
 +
sudo cp -p /etc/acpi/powerbtn.sh /etc/acpi/powerbtn.sh.orig
 +
 +
Step 2: Comment out (or remove) the following line in /etc/acpi/powerbtn.sh
 +
/sbin/shutdown -h now "Power button pressed"
 +
 +
Step 3: Directly under the commented out line, add:
 +
/usr/bin/killall mythfrontend.real
 +
 +
= Archive: Using mythwelcome with nvram-wakeup =
 +
 +
{{Note box|This section is archival in nature and may not be up to date..}}
  
 
== Configuration ==
 
== Configuration ==
Line 18: Line 269:
 
Change your system startup to run mythwelcome instead of mythfrontend.
 
Change your system startup to run mythwelcome instead of mythfrontend.
 
 
 
 
Change the Shutdown/Wakeup Options in mythtv-setup to call the mythshutdown program.
+
Change the General=>Shutdown/Wakeup Options in mythtv-setup (MythTV Backend Setup) to call the mythshutdown program.
  
 
[[Image:Mythtvsetup-start.png]]
 
[[Image:Mythtvsetup-start.png]]
 
 
 
 
If your mythtv user is not root you will need to run Mythshutdown with root privileges,see section below on root privileges  
+
If your mythtv user is not root you will need to run Mythshutdown with root privileges, see the section below on root privileges  
  
 
And if you start wondering why it doesn't work, come back and read the
 
And if you start wondering why it doesn't work, come back and read the
 
rest of this article.
 
rest of this article.
  
== What is MythWelcome ==
 
 
MythWelcome is a Myth themed application that shows a welcome/status
 
information screen that will be shown whenever the frontend is not
 
running ie. when an automatic startup has occurred to record a program.
 
It shows some information about what the backend is currently doing
 
idle, recording, commercial flagging, transcoding or locked by a user etc.).
 
It also shows what the backend is recording, what the next scheduled recording
 
is and shows a warning if there are any schedule conflicts. There is also a
 
push button to start the frontend.
 
 
It is useful if you want to setup a dedicated MythTV system that you
 
don't want to run 24/7 but you want to automatically wake up to record
 
just like a normal video recorder and shutdown again when it is idle.
 
 
Mythwelcome will also prevent the backend from shutting down the system
 
if it is busy commercial flagging, downloading EPG data, transcoding or
 
shutdown has been locked by a user.
 
 
 
 
 
 
== Prerequisites ==
 
== Prerequisites ==
Line 115: Line 348:
 
                          lilo users should use something like this
 
                          lilo users should use something like this
 
                          "lilo -R PowerOff"       
 
                          "lilo -R PowerOff"       
 +
 +
                                OpenSUSE Users should use "/usr/sbin/grubonce x" (run as root)
 +
                                where x is the menu entry in your grub boot menu.
 +
                                If you run "grubonce" with no prarameters it will print out boot the menu list
 
                         
 
                         
 
  Poweroff Command      - The command mythshutdown should use to poweroff the computer.
 
  Poweroff Command      - The command mythshutdown should use to poweroff the computer.
Line 164: Line 401:
 
</pre>
 
</pre>
  
=== Using MythWelcome/MythShutdown with ACPI ===
 
 
MythShutdown assumes that it is using nvram-wakeup to set the wakeup time, although the command used is configurable.  MythShutdown then executes this command with "--settime <time_t>" appended to the command-line.  The time parameter is a 32-bit signed value, and is the number of seconds since the UNIX epoch, local time.  This must be converted by whatever command is executed into the format required by ACPI and then writen to /proc/acpi/alarm as described on the [[ACPI_Wakeup]] page.
 
 
My Perl/Bash skills are very basic at best, but by trade I work in C most of the time, so I wrote a C program to perform the conversion and write the wakeup time to /proc/acpi/alarm.  My application also converts the local time value provided by MythShutdown into a UTC value, as my BIOS uses UTC.  The application is available at [http://www.jamesandsiantelfer.com/mythtv/mythtvtoacpitime.tar.gz] as a tarball.  Note that this application must be executed as root, and your BIOS clock must be set to UTC time for this to work.
 
 
The poweroff command can then be set to whatever command you use to put your machine to sleep, in my case a script which stops a number of services and unloads a number of drivers before putting the system to sleep.
 
  
Addendum - the above link to the conversion program is currently dead. However there is a drop-in replacement at [http://www.mythtv.org/pipermail/mythtv-users/2007-July/187585.html] for nvram-wakeup that calls on acpi.
 
  
 
== MythBackend setup options ==
 
== MythBackend setup options ==
Line 195: Line 424:
 
and nvram-wakeup all of which require root privileges if you don't run the mythbackend
 
and nvram-wakeup all of which require root privileges if you don't run the mythbackend
 
as root you will have to use sudo to give mythshutdown root privileges and change the
 
as root you will have to use sudo to give mythshutdown root privileges and change the
Server Halt command to 'sudo mythshutdown --shutdown'.
+
Server Halt command to 'sudo -H mythshutdown --shutdown'.
 
 
 
You will have to restart the backend for the new settings to take effect.
 
You will have to restart the backend for the new settings to take effect.
+
 
 
== Bootloader setup ==
 
== Bootloader setup ==
 
 
Line 239: Line 468:
 
See the nvram-wakeup documentation for more info on how to setup lilo.
 
See the nvram-wakeup documentation for more info on how to setup lilo.
  
== MythShutdown program ==
+
 
 
The mythshutdown command line utility is a multi-purpose helper program used by
 
both mythbackend and mythwelcome. The program needs to be configured to
 
work properly by editing the settings in the GUI. (See 'Mythwelcome/Mythshutdown
 
Settings' above).
 
 
The program can be run with the following parameters:
 
<pre>
 
-l/--lock
 
    this will prevent mythbackend from shutting down the system even if
 
    it is idle. It is useful if you want to do some maintenance on the system
 
    and don't want the backend to shutdown the computer.
 
 
 
-u/--unlock
 
    allows the backend to shutdown when idle
 
 
 
-c/--check
 
    returns 0 safe to shutdown or 1 not safe to shutdown
 
    this is usually called by the backend as the 'Pre-Shutdown Check command'.
 
    will return 1 if shutdown is locked, mythcommflag is running, mythtranscode
 
    is running, mythfilldatabase is running or we are in or about to start a
 
    daily wakeup/shutdown period.
 
 
 
-w/--setwakeup "yyyy-MM-ddThh:mm"
 
    sets the time the next scheduled recording is to start. Does not set the
 
    time in the bios. Usually called by the backend's 'Set wakeup time command'.
 
 
 
-q/--shutdown
 
    does all the hard work of determining when the next wakeup should be.
 
    calls nvram-wakeup to set the time in the bios and calls grub/lilo to reboot
 
    the system if required. Usually called by the backend's 'Server Halt
 
    command'. You probably need to run this with root privileges.
 
     
 
-s/--status
 
    returns a value indicating what programs are running that will prevent
 
    the backend from shutting down. The value is an OR'd flag of the following
 
    values:
 
 
 
    0 - Idle                - free to shutdown
 
    1 - Transcoding        - mythtranscode is running
 
    2 - Commercial Flagging - mythcommflag is running
 
    4 - Grabbing EPG data  - mythfilldatabase is running
 
    8 - not currently used
 
  16 - Locked              - shutdown has been locked by a user 
 
  32 - not currently used  -
 
  64 - In wakeup period    - In a daily wakeup/shutdown period
 
  128 - About to start wake - Less than 15 minutes to next wakeup period
 
        up period
 
   
 
    used by mythwelcome to display a status message to the user and
 
    by 'mythshutdown --check' itself to determine if it is safe to shutdown.
 
 
 
-v/--verbose
 
    By default mythshutdown is silent and does not produce any output on the
 
    console. This is by design because it is called often by mythwelcome and
 
    mythbackend. You can add this parameter to make mythwelcome output some
 
    messages to the console.
 
 
 
-d/--debug
 
    Add this parameter to show more debug messages             
 
</pre>    
 
  
 
== Allow a user to run the MythShutdown program with root privileges ==
 
== Allow a user to run the MythShutdown program with root privileges ==
Line 309: Line 477:
 
run reboot, poweroff, grub/lilo and nvram-wakeup.  
 
run reboot, poweroff, grub/lilo and nvram-wakeup.  
 
 
Add the following line to your '/etc/sudoers' file:
+
Add the following line to the end of your '/etc/sudoers' file.
+
 
mythtv localhost = NOPASSWD: /usr/bin/mythshutdown
+
'''Note:'''
 +
This file must be edited by using the command:
 +
 
 +
sudo visudo
  
then in mythtv-setup change the "setwakeup time command" to
 
sudo mythshutdown --setwakeup $time
 
 
 
Change mythtv to the user you use to run mythwelcome and the mythshutdown program.
 
Change mythtv to the user you use to run mythwelcome and the mythshutdown program.
 
You may also have to change the path to mythshutdown to suit your setup.
 
You may also have to change the path to mythshutdown to suit your setup.
 
== Daily wakeup/shutdown periods ==
 
 
You can optionally set one or two periods in a day that you would like your
 
Myth system to wake up for. The periods are set on the mythwelcome
 
settings screen (press i/INFO key). The mythshutdown program will wakeup
 
the system and prevent it shutting down during these periods even if it is idle.
 
 
 
Note: currently the settings do not handle periods that cross midnight. For
+
%mythtv localhost = NOPASSWD: /usr/bin/mythshutdown
example you cannot define a period of 19.00 to 01.00.
 
 
<pre>
 
POPUP MENU
 
If you press the m/MENU key mythwelcome will display a popup menu with the
 
following options.
 
 
Lock Shutdown        -  Prevents the system from shutting down even if it is idle.
 
 
Unlock Shutdown      -  Allows the system to shutdown when it is idle.
 
 
Run Mythfilldatabase -  Force mythfilldatabase to run now.
 
 
Shutdown Now        -  Force the system to shutdown even if it is not idle or is
 
                        in a wakeup/shutdown period.
 
 
                        FE only machines simply shutdown using the 'Poweroff command'
 
                        that has been setup in settings.
 
 
                        Master BE machines will not shutdown if the backend
 
                        is recording or is about to start recording otherwise
 
                        mythwelcome sets the time of the next wakeup and shuts down
 
                        the system.
 
 
                        Requires sudo to be setup properly to allow mythwelcome to call
 
                        the mythshutdown program with root privileges. See above.
 
 
Exit                -  Exit the mythwelcome application.
 
 
Cancel              -  Cancel the popup menu.                                   
 
</pre>
 
  
== Start xterm ==
+
This is another example sudo setup:
+
  # this defaults setting is reported to be required on fedora.
There is an hidden feature that allows you to start an xterm from the mythwelcome
+
  # check sudoers(5) for what the default is on your system
screen. Useful if you need to do some trouble shooting. You can access it by
+
  Defaults:mythtv !requiretty
pressing the F12 key (default key binding). You can change the command that will
+
 
be used to start the xterm on the Mythshutdown settings page (F11 key).
+
  Cmnd_Alias    SHUTDOWN = /usr/bin/mythshutdown, /bin/sh -c /usr/bin/setwakeup.sh [0-9]*, /sbin/shutdown
+
  mythtv localhost = NOPASSWD: SHUTDOWN
== To do ==
 
 
Make the wakeup/shutdown periods a little more flexible by allowing periods to cross
 
midnight.
 
 
== evilwm ==
 
  
mythwelcome is known to have focus problems with evilwm. If you are experiencing any
+
Then in mythtv-setup change the "setwakeup time command" to  
problems try running mythwelcome under a xterm, i.e.
+
  sudo -H mythshutdown --setwakeup $time
 
+
xterm -e mythwelcome
 
  
[[Category:Utilities]]
+
[[Category:MythTV_Software]]

Revision as of 06:39, 25 September 2014

Introduction

Mythwelcome is an mythTV application that can prevent the backend from shutting down the system if it is busy commercial flagging, downloading EPG data, transcoding or shutdown has been locked by a user. Mythwelcome can be very useful if you run both frontend and backend on a single machine and use ACPI_Wakeup to automatically shutdown and wakeup your machine. Prior to the introduction of MythWelcome, MythFrontend would always start up, and, therefore, MythBackend would never shut down.

What is MythWelcome

MythWelcome is a Myth themed application that shows a welcome/status information screen that will be shown whenever the frontend is not running ie. when an automatic startup has occurred to record a program. It shows some information about what the backend is currently doing idle, recording, commercial flagging, transcoding or locked by a user etc.). It also shows what the backend is recording, what the next scheduled recording is and shows a warning if there are any schedule conflicts. There is also a push button to start the frontend.

It is useful if you want to setup a dedicated MythTV system that you don't want to run 24/7 but you want to automatically wake up to record just like a normal video recorder and shutdown again when it is idle.

Mythwelcome will also prevent the backend from shutting down the system if it is busy commercial flagging, downloading EPG data, transcoding or shutdown has been locked by a user.

Working with mythwelcome

A new addition in 0.19. This utility program displays a myth themed dialog which shows a welcome/status information screen that is designed to be shown whenever the frontend is not running.

The mythWelcome Screen

This has been introduced for those people that want to use scheduled wakeup and shutdown to record scheduled shows to save on power consumption. Prior to this the Frontend would always start up which in turn meant that the backend would never shutdown when the recording had finished thus defeating the whole purpose.

The Welcome screen will show the status of the backend and wait for you to manually start the frontend with your remote.

Using MythWelcome/MythShutdown with ACPI

See the ACPI_Wakeup page for details on setting up ACPI Wakeup.

MythShutdown program

The mythshutdown command line utility is a multi-purpose helper program used by both mythbackend and mythwelcome. The program needs to be configured to work properly by editing the settings in the GUI.


Important.png Note: When performing testing be aware that mythshutdown will never shut down the system if the next wake up time is due soon. The default is 15 minutes.

The program can be run with the following parameters:

 	
        -w/--setwakeup time
            time - should be in format yyyy-MM-ddThh:mm:ss

	    sets the time the next scheduled recording is to start. Does not set the
	    time in the bios just sets the value in the database. 
            Usually called by the backend's 'Set wakeup time command'.

        -t/--setscheduledwakeup
            sets the time the next scheduled recording is to start. Does not set the
	    time in the bios just sets the value in the database. Differs from
            --setwakeup as this will query the database directly so doesn't
            need the time passed to it.

	-q/--shutdown
            calls the mythwelcome 'Set Wakeup Time Command' and then runs the
            mythwelcome 'Shutdown command'. Usually called by the backend's 'Server Halt
	    command'.

        -x/--safeshutdown
            equal to -c -t -q. Checks shutdown is safe, sets scheduled wakeup time
            in database and shutdown (runs 'Set Wakeup Time Command' then 'Shutdown command')

        -p/--startup
            check how system was started. Will return 0 if system started for a scheduled
            recording or daily wakeup period. Returns 1 if started manually

	-c/--check flag
            flag is 0 - don't check recording status
                    1 - do check recording status (default)

	    returns 0 safe to shutdown or 1 not safe to shutdown
	    this is usually called by the backend as the 'Pre-Shutdown Check command'.
	    will return 1 if shutdown is locked, mythcommflag is running, mythtranscode
	    is running, mythfilldatabase is running or we are in or about to start a
	    daily wakeup/shutdown period.
	
	--lock
	    this will prevent mythbackend from shutting down the system even if
	    it is idle. It is useful if you want to do some maintenance on the system
	    and don't want the backend to shutdown the computer.
	   
	-u/--unlock
	    allows the backend to shutdown when idle
	   	   	         	  	       
	-s/--status flag
            flag is 0 - don't check recording status
                    1 - do check recording status (default)

	    returns a value indicating what programs are running that will prevent
	    the backend from shutting down. The value is an OR'd flag of the following
	    values:
 	   
	    0 - Idle                - free to shutdown
 	    1 - Transcoding         - mythtranscode is running
 	    2 - Commercial Flagging - mythcommflag is running
 	    4 - Grabbing EPG data   - mythfilldatabase is running
 	    8 - Recording in progress - only valid if flag is 1
 	   16 - Locked              - shutdown has been locked by a user   
 	   32 - Has queued or pending jobs  - 
 	   64 - In wakeup period    - In a daily wakeup/shutdown period
 	  128 - About to start wake - Less than 15 minutes to next wakeup period
 	  255 - Setup is running... - mythtv-setup is running

 	     
 	    used by mythwelcome to display a status message to the user and
 	    by 'mythshutdown --check' itself to determine if it is safe to shutdown.
 	   
 	-v/--verbose debug-level
            debug-level - use -v help for level info

 	    By default mythshutdown is silent and does not produce any output on the
 	    console. This is by design because it is called often by mythwelcome and
 	    mythbackend. You can add this parameter to make mythwelcome output some
 	    messages to the console. 	    	           

Mythwelcome/Mythshutdown Settings

Like most of MythTV Mythwelcome and Mythshutdown store their settings in the myth database. All of the settings are settable from the GUI. There are two separate settings pages. One is shown by starting mythwelcome with the -s/--setup parameter or by pressing the 'SHOWSETTINGS' key (defaults to F11 key) in Mythwelcome. You will probably only ever set these options once when you first setup Mythwelcome.

 		
	Command to Set Wakeup Time 
            Command to run to set the ACPI alarm in bios. The $time variable will contain the next wakeup time
	                     
        Wakeup time format
             Format for the time string passed to the 'Set Wakeup Time Command. Set to 'time_t' for seconds
             since epoch.
                 	
 	nvram-wakeup Restart Command
             Must be set to a blank value if using ACPI wakeup.

        Command to reboot
             Command used to reboot system.

        Command to shutdown
             Command used to shutdown system.

        Command to run Xterm
             This is the command to use to open an XTerm window.
 	     Leave blank to disable this feature.
 	     Tip: If the default font size is too small to see on your
 	     TV change the default setting to:
 	     'xterm -fa Courier -fs 14' to change the font style and size. 
 	 	                                                            	 	 	
 	Command to start the Frontend
             This is the command mythwelcome should use to start the FE. It
 	     is usefull if you want to change the verbose level or add a log
 	     file to output message etc.

WelcomeScreen3.jpg

The second set of settings are available by pressing 'i/INFO' key in mythwelcome and allows you to setup the daily wakeup/shutdown periods and control whether to automatically start the mythfrontend when mythwelcome is started and it is determined that it was started manually.

 		
	Period 1 Start Time  - These setting determine a period of time that the master backend
	Period 1 End Time      should always wake up for. Set both times to 00:00 to
	                       disable this feature.
	
	Period 2 Start Time  - Second wakeup/shutdown period settings.                   
 	Period 2 End Time      Note: Period 1 and period 2 should be in correct chronological order.
                               So for example if you have two periods 10:00-13:00 and 19:00-22:00 then
                               10:00-13:00 must be period 1 and 19:00-22:00 must be period 2. This is
                               because if  the start times for both daily wakeup periods has passed for 
                               today then the next wake time will be set to the first daily wakeup time 
                               tomorrow even if the second daily wakeup time is before the first. 
 	
 	Automatically Start  - Normally when mythwelcome starts up it checks to see whether
	Mythfrontend           the system was started to record something or because of a
	                       wakeup/shutdown period. If not it will automatically start the
	                       frontend. You can disable this feature by unchecking this option.   
	
	Shutdown with Master - (Frontend only machines). If set mythwelcome will shutdown this system
	Backend                when the master backend shutsdown.

A popup menu is available by pressing the 'm/MENU' key in mythwelcome and allows you to lock/unlock the machine from shutting down, run mythfilldatabase or do a shutdown now.

 		
	POPUP MENU
 	If you press the m/MENU key mythwelcome will display a popup menu with the
 	following options.
 	
 	Lock Shutdown        -  Prevents the system from shutting down even if it is idle.
 	
 	Unlock Shutdown      -  Allows the system to shutdown when it is idle.
 	
 	Run Mythfilldatabase -  Force mythfilldatabase to run now.
 	
 	Shutdown Now         -  Force the system to shutdown even if it is not idle or is
 	                        in a wakeup/shutdown period.
 	
 	                        FE only machines simply shutdown using the 'Poweroff command'
 	                        that has been setup in settings.
 	
 	                        Master BE machines will not shutdown if the backend
 	                        is recording or is about to start recording otherwise
 	                        mythwelcome sets the time of the next wakeup and shuts down
 	                        the system.
 	
 	                        Requires sudo to be setup properly to allow mythwelcome to call
 	                        the mythshutdown program with root privileges. See above.
 	
 	Exit                 -  Exit the mythwelcome application.
 	
 	Cancel               -  Cancel the popup menu.                                     

Don't forget: you will most likely need to set up sudo, as well.

Start xterm

There is a hidden feature that allows you to start an xterm from the mythwelcome screen. Useful if you need to do some trouble shooting. You can access it by pressing the F12 key (default key binding). You can change the command that will be used to start the xterm on the Mythshutdown settings page (F11 key).

evilwm

mythwelcome is known to have focus problems with evilwm. If you are experiencing any problems try running mythwelcome under a xterm, i.e.

xterm -e mythwelcome

Configuring the Cases Power Button to Shutdown via Mythwelcome (optional)

Reconfiguring the cases power button to kill the mythfrontend is an easy way to trigger a clean/managed shutdown from a hardware control. By killing mythfrontend, mythwelcome will manage a clean shutdown (i.e when mythbackend is not busy recording... or locked e.t.c.).

The following was tested on Mythbuntu / Ubuntu 11.04 32bit

Step 1: Backup the following (in case you need to revert): sudo cp -p /etc/acpi/powerbtn.sh /etc/acpi/powerbtn.sh.orig

Step 2: Comment out (or remove) the following line in /etc/acpi/powerbtn.sh /sbin/shutdown -h now "Power button pressed"

Step 3: Directly under the commented out line, add: /usr/bin/killall mythfrontend.real

Archive: Using mythwelcome with nvram-wakeup

Important.png Note: This section is archival in nature and may not be up to date..

Configuration

REALLY-QUICK START

If you're in a desperate hurry:

Run mythwelcome --setup from a terminal and edit the settings to suit your setup.

Mythwelcome-setup.png

Change your system startup to run mythwelcome instead of mythfrontend.

Change the General=>Shutdown/Wakeup Options in mythtv-setup (MythTV Backend Setup) to call the mythshutdown program.

Mythtvsetup-start.png

If your mythtv user is not root you will need to run Mythshutdown with root privileges, see the section below on root privileges

And if you start wondering why it doesn't work, come back and read the rest of this article.


Prerequisites

You should have already installed and have a working nvram-wakeup setup including modifying your bootloader menu to add a Poweroff menu option if your bios requires a reboot when setting the wakeup time in the bios.

Mythwelcome/Mythshutdown Settings

Like most of MythTV Mythwelcome and Mythshutdown store their settings in the myth database. All of the settings are settable from the GUI. There are two separate settings pages. One is shown by starting mythwelcome with the -s/--setup parameter or by pressing the 'SHOWSETTINGS' key (defaults to F11 key) in Mythwelcome. You will probably only ever set these options once when you first setup Mythwelcome.

 		
	nvram-wakeup command -  command to set wakeup time in bios
	                        
                            ''recent changes(post 0.20.2) to the time format code cause problems''
                            
                             nvram-wakeup only accepts time_t (seconds since
                             unix epoch) as a date/time format. mythshutdown only uses
                             ISO-8601 (yyyy-MM-ddThh:mm:ss). Both programs now use the 
                             same setting name in the database for their format
                             token. Since getting the wakeup time in the BIOS involves
                             using both programs, it's now impossible.
                             
                             You can get around this like this
                             
                             "date -d "`echo $time | sed "s/T/ /"`" +%s | xargs nvram-wakeup -s"
                             
                             Replace the preset arguments on the end with the ones that work
                             for you.
                             
                             The sed is in there to strip the "T" because gnu date can't parse ISO-8601 format
                             properly (a bug known for at least 3 years), despite being
                             able to produce it.
                             

	                        if you are really lucky nvram-wakeup will be able
	                        to recognise your M/B automatically
	                        "/usr/sbin/nvram-wakeup"
	
	                        if you need to explicitly set the info-writer use
	                        something like this
	                        "/usr/sbin/nvram-wakeup -A -I aopen_ax37"
 	
 	                        if you need to use a custom config file use something
 	                        like this
 	                        "/usr/sbin/nvram-wakeup -A -C /etc/nvram-wakeup.conf"
                                
                               Note that Mythwelcome will append "--settime xxxxxxxxxx" to this command
                               where xxxxxxxxxx is the next wakeup time in UTC format.
 	
 	nvram-wakeup restart  - command to set which bootloader menu option to use
 	command                 after next reboot. This command is run if your bios
 	                        requires you to reboot to allow nvram-wakeup settings
 	                        to take effect. Leave blank if your bios doesn't require a reboot.
 	
 	                        older versions of grub require something like this
 	                        "echo 'savedefault --default=1 --once quit' | /sbin/grub"
                                (Note use: \' for the single quotes when entering the command else it wont save)
 	                       
 	                        newer versions of grub can use something like this
 	                        "grub-set-default 1"
 	                       
 	                        lilo users should use something like this
 	                        "lilo -R PowerOff"       

                                OpenSUSE Users should use "/usr/sbin/grubonce x" (run as root)
                                where x is the menu entry in your grub boot menu.
                                If you run "grubonce" with no prarameters it will print out boot the menu list
 	                       
 	Poweroff Command      - The command mythshutdown should use to poweroff the computer.
                                e.g. "/sbin/poweroff"
 	
 	Reboot Command        - The command mythshutdown should use to reboot the computer.
 	                        Used when your BIOS requires a reboot to allow nvram-wakeup
 	                        settings to take effect.
                                e.g. "/sbin/reboot"   - if bios requires a reboot.
                                e.g. "/sbin/poweroff" - important to include this if bios does not require 
                                                        a reboot.
 	
 	Start XTerm Command   - This is the command to use to open an XTerm window.
 	                        Leave blank to disable this feature.
 	                        Tip: If the default font size is too small to see on your
 	                        TV change the default setting to:
 	                        'xterm -fa Courier -fs 14' to change the font style and size.   
 	
 	Start Frontend Command - This is the command mythwelcome should use to start the FE. It
 	                         is usefull if you want to change the verbose level or add a log
 	                         file to output message etc.

The second set of settings are available by pressing 'i/INFO' key in mythwelcome and allows you to setup the daily wakeup/shutdown periods and control whether to automatically start the mythfrontend when mythwelcome is started and it is determined that it was started manually.

 		
	Period 1 Start Time  - These setting determine a period of time that the master backend
	Period 1 End Time      should always wake up for. Set both times to 00:00 to
	                       disable this feature.
	
	Period 2 Start Time  - Second wakeup/shutdown period settings.                   
 	Period 2 End Time      Note: Period 1 and period 2 should be in correct chronological order.
                               So for example if you have two periods 10:00-13:00 and 19:00-22:00 then
                               10:00-13:00 must be period 1 and 19:00-22:00 must be period 2. This is
                               because if  the start times for both daily wakeup periods has passed for 
                               today then the next wake time will be set to the first daily wakeup time 
                               tomorrow even if the second daily wakeup time is before the first. 
 	
 	Automatically Start  - Normally when mythwelcome starts up it checks to see whether
	Mythfrontend           the system was started to record something or because of a
	                       wakeup/shutdown period. If not it will automatically start the
	                       frontend. You can disable this feature by unchecking this option.   
	
	Shutdown with Master - (Frontend only machines). If set mythwelcome will shutdown this system
	Backend                when the master backend shutsdown.


MythBackend setup options

The mythbackend needs to co-operate with mythwelcome to work as intended. It does this by calling the helper program 'mythshutdown' to check whether it is safe to shutdown, to set the time to wake up for the next scheduled recording and to do the actual shutdown.

You should run mythtv-setup and on the Shutdown/Wakeup Options page set the following settings:

 		
	    Block shutdown before
	    client connected:           should be checked
	    Idletimeout (secs):         any value greater that 0
	    Wakeup time format:         yyyy-MM-ddThh:mm
	    Set wakeup time command:    mythshutdown --setwakeup $time
	    Server Halt command:        mythshutdown --shutdown
	    Pre shutdown check command: mythshutdown --check 

Because 'mythshutdown --shutdown' needs to run grub/lilo, reboot, poweroff and nvram-wakeup all of which require root privileges if you don't run the mythbackend as root you will have to use sudo to give mythshutdown root privileges and change the Server Halt command to 'sudo -H mythshutdown --shutdown'.

You will have to restart the backend for the new settings to take effect.

Bootloader setup

If your motherboard/bios requires a reboot after changing the startup time in the bios with nvram-wakeup you should configure grub/lilo with a special menu boot option to reboot and immediately shutdown.

In addition, if your /boot directory is in another filesystem it may not be mounted automatically to protect the kernel. In these cases, instead of calling grub-set-default directly, you're going to need to use a shell script that mounts the /boot filesystem first.

Grub Users Only

Simply add the following menu boot option to your grub.conf file:

 	
	    title=PowerOff
	        savedefault 0
                cat /boot/grub/default
	        halt

You should change the '0' to the menu item number you want to boot normally by default. Also add 'default saved' towards the top of the file. The command to read the file is to force grub to sync the file to disk. Some versions have a bug which means they do not do this before the halt executes.

Set the nvram-wakeup restart command to '/sbin/grub-set-default 1'. The 1 should be the menu item number of the PowerOff menu item you added above starting from 0.

Lilo Users Only

As part of nvram-wakeup you can download some kernel images that do nothing but shutdown the system. (see http://sourceforge.net/project/showfiles.php?group_id=35022&package_id=91149)

Add a boot option to the lilo.conf file such as:

 		
	    image=/boot/bzimage.poweroff
	    label=PowerOff

Change the nvram-wakeup restart command to 'lilo -R PowerOff'

See the nvram-wakeup documentation for more info on how to setup lilo.


Allow a user to run the MythShutdown program with root privileges

Because you would normally run mythwelcome and the mythshutdown script as a normal user without root privileges you will need to setup sudo to allow you to run the mythshutdown --shutdown as the root user to allow it to run reboot, poweroff, grub/lilo and nvram-wakeup.

Add the following line to the end of your '/etc/sudoers' file.

Note: This file must be edited by using the command:

sudo visudo

Change mythtv to the user you use to run mythwelcome and the mythshutdown program. You may also have to change the path to mythshutdown to suit your setup.

%mythtv localhost = NOPASSWD: /usr/bin/mythshutdown

This is another example sudo setup:

 # this defaults setting is reported to be required on fedora.
 # check sudoers(5) for what the default is on your system
 Defaults:mythtv !requiretty
 
 Cmnd_Alias     SHUTDOWN = /usr/bin/mythshutdown, /bin/sh -c /usr/bin/setwakeup.sh [0-9]*, /sbin/shutdown
 mythtv localhost = NOPASSWD: SHUTDOWN

Then in mythtv-setup change the "setwakeup time command" to

sudo -H mythshutdown --setwakeup $time