Project

General

Profile

Stopped TVHeadEnd using Webmin, now it won't auto-restart after crash, why?

Added by K Shea almost 10 years ago

I was doing some system updates that required stopping TVHeadEnd so I went into Webmin's "Bootup and Shutdown" section (yes that is the correct place to access startup scripts in Webmin) and stopped TVHeadEnd, and did what I needed to do, but after rebooting I found it would not start automatically at bootup, even if I specifically enabled that in Webmin. However I then applied an update to TVHeadEnd (I am running the unstable branch) and now it does start at boot again, but today the system crashed when I attempted to tune a "problem" channel (insufficient signal strength) and TVHeadEnd did not restart itself. I will include the startup script that Webmin thinks should be used at bootup and shutdown at the end of this post.

I can't imagine that Webmin did anything to alter the startup, it basically just takes what it thinks is the standard init script and uses that, but maybe when I disabled it temporarily it didn't get re-enabled correctly or something, but I don't know how to tell. Is there some Linux command I can use to check this? It seems to me as though in the past I have always seen two processes associated with TVHeadEnd, but now when I run ps -ax I see only this one:

/usr/bin/tvheadend -f -u hts -g video

Is there another "watchdog" type process that should be running (I always thought there was one called just tvh or hts or something like that, I thought it had a shorter name but maybe I'm imagining things), and if so how can I get it to start again?

I am running TVHeadEnd under Debian Wheezy, and before anyone gives me grief about using Webmin, I use it because it helps me with a lot of Linux-y stuff that I don't really understand otherwise, and I have never had a problem with stopping or starting processes in Webmin prior to this. This is the startup/shutdown script that Webmin thinks it should use. As I understand it, when you stop a process in Webmin all it does is call this script with the "stop" option, however I don't know how it removes it from or adds it to the list of startup items. Also Webmin doesn't even show a tvh or hts process in its list of available processes (normally it shows even disabled processes in the list).

#! /bin/sh
### BEGIN INIT INFO
# Provides:          tvheadend
# Required-Start:    $local_fs $remote_fs udev
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO

# Author: Andreas Öman

# Do NOT "set -e" 

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/usr/sbin:/usr/bin:/sbin:/bin
DESC="Tvheadend" 
NAME=tvheadend
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Configure command line options
[ "$TVH_ENABLED" = "1" ] || exit 0

ARGS="-f" 
[ -z "$TVH_USER"      ] || ARGS="$ARGS -u $TVH_USER" 
[ -z "$TVH_GROUP"     ] || ARGS="$ARGS -g $TVH_GROUP" 
[ -z "$TVH_CONF_DIR"  ] || ARGS="$ARGS -c $TVH_CONF_DIR" 
[ -z "$TVH_ADAPTERS"  ] || ARGS="$ARGS -a $TVH_ADAPTERS" 
[ "$TVH_IPV6" = "1"   ] && ARGS="$ARGS -6" 
[ -z "$TVH_HTTP_PORT" ] || ARGS="$ARGS --http_port $TVH_HTTP_PORT" 
[ -z "$TVH_HTTP_ROOT" ] || ARGS="$ARGS --http_root $TVH_HTTP_ROOT" 
[ -z "$TVH_HTSP_PORT" ] || ARGS="$ARGS --htsp_port $TVH_HTSP_PORT" 
[ -z "$TVH_ARGS"      ] || ARGS="$ARGS $TVH_ARGS" 
[ "$TVH_DEBUG" = "1"  ] && ARGS="$ARGS -s" 

# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
    # Return
    #   0 if daemon has been started
    #   1 if daemon was already running
    #   2 if daemon could not be started
        udevadm settle
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
        || return 1
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
        $ARGS \
        || return 2
}

#
# Function that stops the daemon/service
#
do_stop()
{
    # Return
    #   0 if daemon has been stopped
    #   1 if daemon was already stopped
    #   2 if daemon could not be stopped
    #   other if a failure occurred
    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
    RETVAL="$?" 
    [ "$RETVAL" = 2 ] && return 2
    # Many daemons don't delete their pidfiles when they exit.
    rm -f $PIDFILE
    return "$RETVAL" 
}

case "$1" in
  start)
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" 
    do_start
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  stop)
    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" 
    do_stop
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  restart|force-reload)
    #
    # If the "reload" option is implemented then remove the
    # 'force-reload' alias
    #
    log_daemon_msg "Restarting $DESC" "$NAME" 
    do_stop
    case "$?" in
      0|1)
        do_start
        case "$?" in
            0) log_end_msg 0 ;;
            1) log_end_msg 1 ;; # Old process is still running
            *) log_end_msg 1 ;; # Failed to start
        esac
        ;;
      *)
          # Failed to stop
        log_end_msg 1
        ;;
    esac
    ;;
  *)
    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
    exit 3
    ;;
esac

:

Replies (2)

RE: Stopped TVHeadEnd using Webmin, now it won't auto-restart after crash, why? - Added by Prof Yaffle almost 10 years ago

You should only have one tvheadend process, so that looks normal. If I check my system, for example:

hts@Romulus:~$ ps -eaf | grep tvh
hts      26247 26209  0 20:40 pts/16   00:00:00 grep --color=auto tvh
hts      29676     1  1  2014 ?        04:19:26 tvheadend -f -u hts -g video

i.e. just the tvh process plus the grep command itself.

On Debian, Webmin should just issue a 'sudo service tvheadend stop' and 'sudo service tvheadend start'.

It might be a Webmin issue. I run Webmin on my headless backup server, but that's not my tvheadend box, so I can't immediately check for a comparison for you.

I would guess that, if you can add or remove startup items, then Webmin is playing with the scripts in /etc/init.d, since that's where the file you quote above belongs. It looks entirely normal to me, btw, that's the normal (package) script. Ideally, Webmin would use the commands above to call that script, although it may be using the (older) init method to call the script directly - perhaps that's the issue...?

RE: Stopped TVHeadEnd using Webmin, now it won't auto-restart after crash, why? - Added by K Shea almost 10 years ago

Thanks, Prof Yaffle. Maybe everything is functioning as it should be then, I was just surprised that tuning a weak signal could cause TVHeadEnd to go out to lunch and force me to reboot the system before it would become responsive again. I could probably have restarted it without rebooting, but I wanted to make sure it came back up in the "normal" manner.

Even the web interface was unresponsive. I wonder if there is some way to detect when it's in that state and force a "sudo service tvheadend stop" followed by a "sudo service tvheadend start." It's not that this has happened often but it worries me a bit that it could happen when I'm depending on it to record something.

    (1-2/2)