bas-t / ffdecsawrapper

FFdecsa empowered softcam for MythTV
GNU General Public License v3.0
17 stars 9 forks source link

upstart #18

Closed sjuk closed 10 years ago

sjuk commented 10 years ago

On systems with upstart mythbackend starts before ffdecsawrapper is ready for use. And because of that mythbackend cannot interact with the tv-tuner. => No recordings, no live TV.

To prevent this issue I use the following upstart configurations (see down).

The interesting part is the addition of "and started ffdecsawrapper" in the "start on" line of the mythtv-backend.conf, which lets mythbackend wait before starting until ffdecsawrapper has been started.

Perhaps this is of any use for you or other users.

/etc/init/ffdecsawrapper.conf:

description "DVB Loopback adapter with FFdecsa decryption"

start on runlevel [2345]
stop  on runlevel  [016]

emits ffdecsawrapper-started
emits ffdecsawrapper-stopped

console log

respawn
respawn limit 5 60

script
    . /etc/default/ffdecsawrapper

    rmmod dvbloopback 2> /dev/null || true
    sleep $DELAY
    modprobe dvbloopback num_adapters=$NUMADAPTERS
    sleep $DELAY

    cmd="/usr/bin/ffdecsawrapper $JOIN $OPTS --cam-dir $CAMDIR"
    echo "Starting ffdecsawrapper:"
    echo "$cmd"
    exec sudo -u $USER $cmd
end script

post-start script
    #sleep until listening and ready to start mythbackend
    while [ "`netstat -lnt | grep -c 5456`" != "1" ]; do
        sleep 1s
    done
    logger "ffdecsawrapper is listening..."
    initctl emit --no-wait ffdecsawrapper-started
end script

post-stop script
    rmmod dvbloopback 2> /dev/null || true
    initctl emit --no-wait ffdecsawrapper-stopped
end script

/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 and started ffdecsawrapper)
stop on runlevel [016]

#should die within 5 seconds, but we don't want data loss, so set it to 30
#before we send SIGKILL
kill timeout 30

#if we crash, but not quickly
respawn
respawn limit 2 3600

#because we're daemonizing to avoid logging to upstart log
expect fork

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 >/dev/null && exit 0
       sleep .5
    done
end script

script
    test -f /etc/default/locale && . /etc/default/locale || true
    LANG=$LANG exec /usr/bin/mythbackend --syslog local7 --user mythtv --daemon
end script
bas-t commented 10 years ago

Systems like ubuntu are perfectly capable of running normal init scripts. My init script has been taking care of your issue for a long time now. One more thing: this is not a forum and your issue is not FFdecsawrapper related.