Difference between revisions of "Systemd mythbackend Configuration"

From MythTV Official Wiki
Jump to: navigation, search
m (Spelling correction)
(Default configuration)
Line 7: Line 7:
  
 
Save the configuration file below in <code>/etc/systemd/system/mythbackend.service</code>
 
Save the configuration file below in <code>/etc/systemd/system/mythbackend.service</code>
 
+
Changes to files in /lib/systemd/system will be over-written when updated.
 
{{Code box|/etc/systemd/system/mythbackend.service|
 
{{Code box|/etc/systemd/system/mythbackend.service|
 
<pre>
 
<pre>
Line 16: Line 16:
 
Description=MythTV backend service
 
Description=MythTV backend service
 
After=network.target mysqld.service
 
After=network.target mysqld.service
 +
# If you intend to use mythweb then
 
# Uncomment to make sure httpd is started if it is not already.
 
# Uncomment to make sure httpd is started if it is not already.
 
# Wants=httpd.service
 
# Wants=httpd.service
Line 21: Line 22:
 
[Service]
 
[Service]
 
Type=simple
 
Type=simple
 +
# if Type=forking you will need to specify a pidfile so systemd knows
 +
# how to find the eventual process PID, otherwise it presumes that the
 +
# process being started will be the remaining process
 +
 
Environment=MYTHCONFDIR=/etc/mythtv
 
Environment=MYTHCONFDIR=/etc/mythtv
 
Environment=HOME=/usr/share/mythtv
 
Environment=HOME=/usr/share/mythtv
 +
# or Environment=HOME=/home/mythtv
 +
# the folder containing the .mythtv subfolder containing the config.xml file
 
User=mythtv
 
User=mythtv
 +
# systemd changes execution from the calling user (possibly root) to this user
 +
# if you have permissions problems or obscure errors try logging in as mythtv
 +
  
 
# Uncomment *one* ExecStart, see the 1st note following this box.
 
# Uncomment *one* ExecStart, see the 1st note following this box.
 
# 0.24 and below:
 
# 0.24 and below:
 
# ExecStart=/usr/bin/mythbackend --logfile /var/log/mythtv/mythbackend.log
 
# ExecStart=/usr/bin/mythbackend --logfile /var/log/mythtv/mythbackend.log
 +
 
# 0.25 and above:
 
# 0.25 and above:
 
# ExecStart=/usr/bin/mythbackend --syslog local7  
 
# ExecStart=/usr/bin/mythbackend --syslog local7  
 
# ExecStart=/usr/bin/mythbackend --logpath /var/log/mythtv
 
# ExecStart=/usr/bin/mythbackend --logpath /var/log/mythtv
 +
# ExecStart=/usr/bin/mythbackend --daemon --logpath /var/log/mythtv --loglevel crit --pidfile /run/mythbackend.pid
 +
 +
Restart=Restart-always
 +
# whether systemd will continue over-watch and restart on any halt
  
 
[Install]
 
[Install]
Line 41: Line 56:
  
 
To enable the backend to start at the next boot, issue the command 'systemctl enable mythbackend.service'.  To start the backend immediately, issue the command 'systemctl start mythbackend.service'.
 
To enable the backend to start at the next boot, issue the command 'systemctl enable mythbackend.service'.  To start the backend immediately, issue the command 'systemctl start mythbackend.service'.
 +
 +
If you specify a log file, all logging will be to that file.
 +
If you specify a logpath each program will write to distinctly named files: much better for debugging. Loglevel determines what is logged. Log messages at lower levels will be discarded: In descending order: emerg, alert, crit, err, warning, notice, info, debug. Defaults to info.
 +
  
 
{{note box|The example runs the backend as user mythtv.  You will need to insure that your files/directories/capture cards can be accessed by the mythtv user, or run the backend as root (not recommended).}}
 
{{note box|The example runs the backend as user mythtv.  You will need to insure that your files/directories/capture cards can be accessed by the mythtv user, or run the backend as root (not recommended).}}

Revision as of 02:29, 6 July 2012

Some newer Linux distributions replace the traditional LSB init script startup management process with a program called systemd, which does things differently; here are some notes on how to make MythTV play nicely with systemd. A cheatsheet from the traditional init scripts to systemd is available on the Fedora wiki pages.

Note that much of the example startup code that follows is based on the rpmfusion packaging of MythTV by Richard Shaw.


Default configuration

Save the configuration file below in /etc/systemd/system/mythbackend.service Changes to files in /lib/systemd/system will be over-written when updated.

Script.png /etc/systemd/system/mythbackend.service


# MythTV backend service

[Unit]
Description=MythTV backend service
After=network.target mysqld.service
# If you intend to use mythweb then
# Uncomment to make sure httpd is started if it is not already.
# Wants=httpd.service

[Service]
Type=simple
# if Type=forking you will need to specify a pidfile so systemd knows
# how to find the eventual process PID, otherwise it presumes that the 
# process being started will be the remaining process

Environment=MYTHCONFDIR=/etc/mythtv
Environment=HOME=/usr/share/mythtv
# or Environment=HOME=/home/mythtv
# the folder containing the .mythtv subfolder containing the config.xml file
User=mythtv
# systemd changes execution from the calling user (possibly root) to this user
# if you have permissions problems or obscure errors try logging in as mythtv


# Uncomment *one* ExecStart, see the 1st note following this box.
# 0.24 and below:
# ExecStart=/usr/bin/mythbackend --logfile /var/log/mythtv/mythbackend.log

# 0.25 and above:
# ExecStart=/usr/bin/mythbackend --syslog local7 
# ExecStart=/usr/bin/mythbackend --logpath /var/log/mythtv
# ExecStart=/usr/bin/mythbackend --daemon --logpath /var/log/mythtv --loglevel crit --pidfile /run/mythbackend.pid

Restart=Restart-always
# whether systemd will continue over-watch and restart on any halt

[Install]
WantedBy=multi-user.target


Important.png Note: Starting with 0.25, there has been a change in the logging. You must adjust the ExecStart line above based on the active release and logging preference (in 0.25 and later.) See: Logging for details.

To enable the backend to start at the next boot, issue the command 'systemctl enable mythbackend.service'. To start the backend immediately, issue the command 'systemctl start mythbackend.service'.

If you specify a log file, all logging will be to that file. If you specify a logpath each program will write to distinctly named files: much better for debugging. Loglevel determines what is logged. Log messages at lower levels will be discarded: In descending order: emerg, alert, crit, err, warning, notice, info, debug. Defaults to info.


Important.png Note: The example runs the backend as user mythtv. You will need to insure that your files/directories/capture cards can be accessed by the mythtv user, or run the backend as root (not recommended).

Delay starting the backend until tuners have initialized

Some tuners take a long time to initialize (typically, firmware loading) and may therefore not yet be available when the backend starts. Since the backend checks for the presence of tuners upon startup, tuner initialization needs to be completed before the backend is started.

This can be accomplished by adding additional Wants= and After= stanza to the unit file, but to have systemd create device units, you must first add a rule to the udev rules directory.


Script.png /etc/udev/rules.d/99-mythbackend

#
# Create systemd device units for capture devices
#
SUBSYSTEM=="video4linux", TAG+="systemd"
SUBSYSTEM=="dvb", TAG+="systemd"
SUBSYSTEM=="firewire", TAG+="systemd"


With the udev rule tag, systemd will create a device unit at startup that one can add to the [Unit] stanza in the startup. Note that one must use the systemd mangled names (generally /dev/some/thing is mangled into dev-some-thing.device). It is highly recommended that you use udev persistent names rather than base names such as /dev/video0.


Script.png device wait code for a typical v4l2 device


Wants=dev-video300.device
After=dev-video300.device


Script.png device wait code for a typical dvb device


Wants=dev-dvb-adapter200-frontend0.device
After=dev-dvb-adapter200-frontend0.device


Systemd has a built-in timeout on device units so that startup will not wait forever for a failed device startup.