Upstart mythbackend Configuration

From MythTV Official Wiki
Revision as of 16:15, 24 April 2011 by Baylink (talk | contribs) (Add a lede; pages should be self-standing, without getting ridiculous)

Jump to: navigation, search

Some newer Linux distributions replace the traditional initscript startup management process with a program called upstart, which does things differently; here are some notes on how to make MythTV play nicely with upstart.

Default configuration

Author Mario Limonciello
Description Upstart configuration file for starting mythbackend.

Save the configuration file below in /etc/init/mythtv-backend.conf and create a symlink referencing the upstart-job binary in /etc/init.d or /etc/rc.d/init.d.

ln -s /lib/init/upstart-job /etc/init.d/mythtv-backend

Script.png /etc/init/mythtv-backend.conf

# MythTV Backend service

description     "MythTV Backend"
author          "Mario Limonciello <>"

start on (local-filesystems and net-device-up IFACE=lo)
stop on starting shutdown

#expect fork

        ARGS="--logfile /var/log/mythtv/mythbackend.log --user $USER"
        test -f /etc/default/mythtv-backend && . /etc/default/mythtv-backend || true
        /usr/bin/mythbackend $ARGS
end script

Delay starting the backend until all tuners have initialised

Some tuners take a long time to initialise and may therefore not yet be available when the backend starts. Since the backend only tests the presence of tuners upon startup, tuner initialisation needs to have completed before the backend is started.

This is accomplished by adding additional events to the and clauses in the start on stanza. An example follows:

Script.png start on stanza in /etc/init/mythtv-backend.conf

start on (local-filesystems and net-device-up IFACE=lo and pvrusb2-device-added KERNEL=sn-7157879 and pvrusb2-device-added KERNEL=sn-7117063)

Consult the Upstart Intro, Cookbook and Best Practices for details about how to determine the correct events. Briefly:

  • Use the following command to list all possible event types on your system:
for subsystem in /sys/class/*
  for action in added changed removed
    echo "${subsystem}-device-${action}"
  • Determine which of these event types correspond with your tuners. For example, when a Hauppauge HVR-1900 tuner finishes initialisation this results in a pvrusb2-device-added event.
  • If you have only one tuner, or only one tuner of each type, then you are done: just add the corresponding events to your start on stanza without additional parameters.
  • If you however have multiple tuners that result in the same event type upon initialisation, then you want to delay starting the backend until they have all initialised. You therefore need to find a way to tell the tuner initialisation events apart. In the above example this is done by noting that the KERNEL environment variable contains the tuner's serial number when the event is triggered.
  • In order to find out which environment variables are available when an event is triggered, create a test Upstart configuration file such as the following, which logs the environment to a file:

Script.png /etc/init/test.conf

start on (pvrusb2-device-added)
  echo "\n`env`" >> /dev/.initramfs/test.log
end script

Don't forget to delete the test Upstart config file when you are done.