Bug #1776
Upstart Configuration is uses "expect" stanza incorrectly
0%
Description
The upstart configuration in the latest TVH package (3.4.27~gfbda802~quantal) uses the "expect fork" stanza incorrectly based on the behavior of the tvheadend executable. The result is that "stop tvheadend" will hang, as may any subsequent "start tvheadend" invocations. This causes the machine to not reboot or suspend promptly under certain common circumstances.
TVH doesn't use fork() the way upstart expects it to within the context of the "expect XXX" stanzas. Therefore, its use should be abandoned. The existing upstart configuration file should be replaced by the following:
# tvheadend - DVB/IPTV streaming server # # Tvheadend is a TV streaming server for Linux supporting DVB, ATSC, IPTV, # and Analog video (V4L) as input sources. description "Tvheadend DVB/IPTV streaming server" author "Adam Sutton <[email protected]>" start on (local-filesystems and net-device-up and started udev-finish) stop on starting shutdown setuid hts setgid video respawn script [ -r /etc/default/tvheadend ] && . /etc/default/tvheadend if [ "$TVH_ENABLED" != "1" ] ; then stop exit 0 fi CONF="$(readlink -f ~hts/.hts/tvheadend)" [ -n "$TVH_CONF_DIR" ] && CONF="$TVH_CONF_DIR" ARGS="-c ${CONF}" [ -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" [ "$TVH_DEBUG" = "1" ] && ARGS="$ARGS -s" [ ! -z "$TVH_DELAY" ] && sleep $TVH_DELAY exec tvheadend $ARGS $TVH_ARGS end script
This new configuration has the drawback that the user TVH runs as is no longer configurable in /etc/default/tvheadend (due to the use of setuid/setgid stanzas which are non-dynamic in upstart). The username is also hardcoded in the declaration of the CONF variable (~hts/...). If anyone (XBMCbuntu) is interested in changing this out, they'll have to edit the script directly. Or simply follow the standard pattern of letting TVH run as the hts user.
Cheers!
History
Updated by Adam Sutton over 11 years ago
- Status changed from New to Rejected
As pointed out on the other issue, your statement is incorrect. TVH does indeed fork() once and only once (in relation to startup). It does this indirectly via the daemon call which is designed specifically for daemons, i.e. processes that fork and the parent is immediately terminated (within the daemon() call).
I've been using the upstart script pretty much since I wrote it, well over a year, and have never witnessed a problem with it locking up. Plenty of others use it as well. If the delay option causes a problem as reported on #1718, that might be a different issue and tbh that option will be removed soon (hopefully).
Adam
Updated by Diego Rivera over 11 years ago
Well, my statement on the number of fork() invocations is based on the output from an strace log. Admittedly, I did not look for daemon() invocations, which is where the confusion might spring.
There will need to be an analog for the wait option. Perhaps a middle ground that requires less work?
I've created a "pre-start" script section whose sole job is to run the wait cycle. Upon experimentation, it appears that this resolves both issues while keeping the flexibility:
# tvheadend - DVB/IPTV streaming server # # Tvheadend is a TV streaming server for Linux supporting DVB, ATSC, IPTV, # and Analog video (V4L) as input sources. description "Tvheadend DVB/IPTV streaming server" author "Adam Sutton <[email protected]>" start on (local-filesystems and net-device-up and started udev-finish) stop on starting shutdown expect fork respawn pre-start script [ -r /etc/default/tvheadend ] && . /etc/default/tvheadend if [ "$TVH_ENABLED" != "1" ] ; then stop exit 0 fi [ -z "$TVH_DELAY" ] || sleep $TVH_DELAY end script script [ -r /etc/default/tvheadend ] && . /etc/default/tvheadend if [ "$TVH_ENABLED" != "1" ] ; then stop exit 0 fi ARGS="-f" [ -z "$TVH_USER" ] || ARGS="$ARGS -u $TVH_USER" [ -z "$TVH_GROUP" ] || ARGS="$ARGS -g $TVH_GROUP" [ -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" [ "$TVH_DEBUG" = "1" ] && ARGS="$ARGS -s" [ -z "$TVH_CONF_DIR" ] || ARGS="$ARGS -c $TVH_CONF_DIR" exec tvheadend $ARGS $TVH_ARGS end script
This script solves both problems. Admittedly, it offers up the potential delay before startup, but there may be DVB device setups that require this.
Anyhow, hopefully this at least bridges the gap. And I'm not the only one seeing this problem - lots of people out there are seeing it, but they probably lack the wherewithal to find a cause, let alone a solution.
Cheers.