Difference between revisions of "Upstart mythbackend Configuration"

From MythTV Official Wiki
Jump to: navigation, search
(Add LC_ALL/LC_CTYPE following b82c53a5)
m (rm'ed supported versions used for testing)
(9 intermediate revisions by 2 users not shown)
Line 20: Line 20:
 
author          "Mario Limonciello <superm1@ubuntu.com>"
 
author          "Mario Limonciello <superm1@ubuntu.com>"
  
start on (local-filesystems and net-device-up IFACE=lo)
+
start on (local-filesystems and net-device-up IFACE!=lo and started udev-finish) # Note 1.
stop on starting shutdown
+
stop on runlevel [016]
  
 
#expect fork
 
#expect fork
 +
kill timeout 10
 
respawn
 
respawn
 +
respawn limit 2 3600
 +
 +
pre-start script
 +
    [ -x /usr/sbin/mysqld ] || exit 0
 +
    for i in `seq 1 30` ; do
 +
      /usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf ping && exit 0
 +
      sleep .5
 +
    done
 +
end script
  
 
script
 
script
         export LANG=en_US.UTF-8 # See note
+
         ulimit -c unlimited                                                      # Note 2.
         export LC_ALL=$LANG
+
         test -f /etc/default/locale && . /etc/default/locale || true              # Note 3.
         USER=mythtv
+
         ARGS="--logfile /var/log/mythtv/mythbackend.log"                          #
         ARGS="--logfile /var/log/mythtv/mythbackend.log --user $USER"
+
         ARGS="--logpath /var/log/mythtv"                                          # Note 4. (pick 1)
 +
        ARGS="--syslog local7"                                                   #
 +
        sleep 5                                                                  # Note 5.
 
         test -f /etc/default/mythtv-backend && . /etc/default/mythtv-backend || true
 
         test -f /etc/default/mythtv-backend && . /etc/default/mythtv-backend || true
         /usr/bin/mythbackend $ARGS $EXTRA_ARGS
+
         LANG=$LANG exec /usr/bin/mythbackend --user mythtv $ARGS $EXTRA_ARGS
 
end script
 
end script
 
</pre>
 
</pre>
 
}}
 
}}
  
{{note box|A test was added in 0.25pre {{gitcommit|b82c53a5}} to verify that the LANG and (LC_ALL or LC_CTYPE) variables are set.
+
{{Note box | Don't just cut-and-paste the above, read the following and remove the comments (# Note...)}}
Your value and related language settings can be seen by using ''locale'' on the command line.}}
 
  
 +
#For systems with no network interface, use IFACE=lo.
 +
#After 0.24, use <code>ulimit -c unlimited</code> to allow <code>mythbackend</code> core files or <code>ulimit -c 0</code> to inhibit them.
 +
#After 0.24, verify that the <code>LANG</code> and (<code>LC_ALL</code> or <code>LC_CTYPE</code>) variables are set.If <code>/etc/default/locale</code> (or an equivalent) doesn't exist, the value for <code>LANG</code> and related language settings can be seen by typing <code>locale</code> on the command line.
 +
#<code>--logfile</code> is used prior to 0.25, use <code>--logpath</code> or <code>--syslog</code> with 0.25 and above. See [[Logging]].
 +
#IPv6 users may find that <code>net-device-up IFACE</code> does not guarantee that their addresses are available for the backend to bind to and should add a <code>sleep 5</code> before starting it.
  
 
==Delay starting the backend until all tuners have initialised==
 
==Delay starting the backend until all tuners have initialised==

Revision as of 15:23, 17 August 2013

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.
Supports


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 <superm1@ubuntu.com>"

start on (local-filesystems and net-device-up IFACE!=lo and started udev-finish)  # Note 1.
stop on runlevel [016]

#expect fork
kill timeout 10
respawn
respawn limit 2 3600

pre-start script 
    [ -x /usr/sbin/mysqld ] || exit 0
    for i in `seq 1 30` ; do
       /usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf ping && exit 0
       sleep .5
    done
end script

script
        ulimit -c unlimited                                                       # Note 2.
        test -f /etc/default/locale && . /etc/default/locale || true              # Note 3.
        ARGS="--logfile /var/log/mythtv/mythbackend.log"                          #
        ARGS="--logpath /var/log/mythtv"                                          # Note 4. (pick 1)
        ARGS="--syslog local7"                                                    #
        sleep 5                                                                   # Note 5.
        test -f /etc/default/mythtv-backend && . /etc/default/mythtv-backend || true
        LANG=$LANG exec /usr/bin/mythbackend --user mythtv $ARGS $EXTRA_ARGS
end script


Important.png Note: Don't just cut-and-paste the above, read the following and remove the comments (# Note...)

  1. For systems with no network interface, use IFACE=lo.
  2. After 0.24, use ulimit -c unlimited to allow mythbackend core files or ulimit -c 0 to inhibit them.
  3. After 0.24, verify that the LANG and (LC_ALL or LC_CTYPE) variables are set.If /etc/default/locale (or an equivalent) doesn't exist, the value for LANG and related language settings can be seen by typing locale on the command line.
  4. --logfile is used prior to 0.25, use --logpath or --syslog with 0.25 and above. See Logging.
  5. IPv6 users may find that net-device-up IFACE does not guarantee that their addresses are available for the backend to bind to and should add a sleep 5 before starting it.

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/*
do
  for action in added changed removed
  do
    echo "${subsystem}-device-${action}"
  done
done
  • 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)
script
  echo "\n`env`" >> /dev/.initramfs/test.log
end script

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