Difference between revisions of "Mythshutdown"

From MythTV Official Wiki
Jump to: navigation, search
(Expanding the page, including data from Mythwelcome (which should be kept here and removed from Mythwelcome?))
m (Usage: - Updated from 0.27.3 --> 0.29.0)
 
Line 8: Line 8:
  
 
= Usage =
 
= Usage =
The full command-line options are (taken from version 0.27.3 output):
+
The full command-line options are (taken from version 0.29.0 output):
 
{{Code box|mythshutdown --help|<pre>
 
{{Code box|mythshutdown --help|<pre>
 
Misc. Options:
 
Misc. Options:
Line 32: Line 32:
 
--logpath                    Writes logging messages to a file in the directory logpath with filenames in the format: applicationName.date.pid.log.
 
--logpath                    Writes logging messages to a file in the directory logpath with filenames in the format: applicationName.date.pid.log.
 
                               This is typically used in combination with --daemon, and if used in combination with --pidfile, this can be used with log rotators, using the HUP call to inform MythTV to reload the file
 
                               This is typically used in combination with --daemon, and if used in combination with --pidfile, this can be used with log rotators, using the HUP call to inform MythTV to reload the file
--nologserver                Disable all logging but console.
 
 
-q OR --quiet                Don't log to the console (-q).  Don't log anywhere (-q -q)
 
-q OR --quiet                Don't log to the console (-q).  Don't log anywhere (-q -q)
 
--syslog                      Set the syslog logging facility.
 
--syslog                      Set the syslog logging facility.
 
                               Set to "none" to disable, defaults to none.
 
                               Set to "none" to disable, defaults to none.
 +
--systemd-journal            Use systemd-journal instead of syslog.
 
-v OR --verbose              Specify log filtering. Use '-v help' for level info.
 
-v OR --verbose              Specify log filtering. Use '-v help' for level info.
  
 
</pre>}}
 
</pre>}}
 
  
 
= Setting wakeup times =
 
= Setting wakeup times =

Latest revision as of 07:19, 5 December 2017

Incomplete.png Incomplete, needs to be expanded. Please help to fill the gaps or discuss the issue on the talk page

Introduction

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


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.

Usage

The full command-line options are (taken from version 0.29.0 output):

Script.png mythshutdown --help
Misc. Options:
-c OR --check                 Check whether shutdown is possible
--localtime                   Specify that the wakeup time is in local time
--lock                        disable shutdown
-x OR --safeshutdown          Check if shutdown is possible, and shutdown
-t OR --setscheduledwakeup    Set wakeup time to the next scheduled recording
-w OR --setwakeup             Set the wakeup time (yyyy-MM-ddThh:mm:ss) default is in local time
-h OR --help OR --usage       Display this help printout, or give detailed information of selected option.
--version                     Display version information.
--shutdown                    Apply wakeup time to nvram and shutdown.
-p OR --startup               Check startup status
-s OR --status                check current status
-u OR --unlock                enable shutdown
--utc                         Specify that the wakeup time is in utc

Logging Options:
--enable-dblog                Enable logging to database.
--loglevel                    Set the logging level.  All log messages at lower levels will be discarded.
                              In descending order: emerg, alert, crit, err, warning, notice, info, debug
                              defaults to err
--logpath                     Writes logging messages to a file in the directory logpath with filenames in the format: applicationName.date.pid.log.
                              This is typically used in combination with --daemon, and if used in combination with --pidfile, this can be used with log rotators, using the HUP call to inform MythTV to reload the file
-q OR --quiet                 Don't log to the console (-q).  Don't log anywhere (-q -q)
--syslog                      Set the syslog logging facility.
                              Set to "none" to disable, defaults to none.
--systemd-journal             Use systemd-journal instead of syslog.
-v OR --verbose               Specify log filtering. Use '-v help' for level info.

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.


Script.png script.sh
#!/bin/bash
# Unlock if the script is terminated for any reason
trap "/usr/local/bin/mythshutdown --unlock" 0 SIGHUP SIGINT SIGQUIT SIGABRT SIGKILL SIGALRM SIGSEGV SIGTERM

# Lock shutdown
/usr/local/bin/mythshutdown --lock

# Do script stuff


See, Mythwelcome for more information on using MythShutdown.