Mythshutdown is an mythTV application which can report whether it is safe to shutdown the computer (ie if a TV program is being recorded or not), and shutdown the computer when safe to do so. Mythshutdown is also used to set the next wake-up time and shutdown the computer when idle from Mythwelcome
The full command-line options are (taken from version 0.29.0 output):
Setting wakeup times
Mythshutdown can note when the computer should next wakeup with the following settings:
-w/--setwakeup <time> <time> should be in the format yyyy-MM-ddThh:mm:ss (ie pass the date using the format string +%FT%T) -t/--setscheduledwakeup
Neither of these commands write anything to the BIOS.
Both commands just record the time that the computer should be scheduled to wakeup in the "settings" table in the database (under the value "MythShutdownNextScheduled"). This is usually called by the backend's 'Set wakeup time command'.
"setscheduledwakeup" differs from "setwakeup" because it will query the database for the next scheduled recording (plus the pre-recording startup time) so it doesn't need a time parameter to be passed to it.
Querying the system status
Mythshutdown can report on the machine's current status using the following options. These are more useful on a backend:
-c/--check [flag] [flag] is optional and can be: 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. -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 -s/--status [flag] [flag] is optional and can be: 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 returned 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 daily 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.
Shutdown the computer
Mythshutdown's more obvious requirement is to perform or prevent the computer shutdown:
-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') --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
Using Mythshutdown to block shutdown
Mythshutdown can be used to block an automatic shutdown whilst a script is running (ie perhaps whilst doing a backup).
Since 0.21 it is possible to call mythshutdown --lock from each script so that shutdown will remain blocked until the last script has terminated and called mythshutdown --unlock.
See, Mythwelcome for more information on using MythShutdown.