Project

General

Profile

Unable to stop tvheadend service

Added by Oz Ra almost 7 years ago

Good Day,

Thank you very much for all the hard work that goes into Tvheadend.

TVheadend works brilliantly but I need some help with the following problem:

Running Ubuntu 12.04 LTS and also tested on brand new config Ubuntu 12.10
Install tvheadend 3.2.18 from Ubuntu PPA together with dvbhdhomerun-dkms dvbhdhomerun-utils

All works brilliantly with the following modification in init:

/etc/init/tvheadend.conf

#Comment out the existing 'start on' line. See comments in my example, with my changes:

#Replaced start line to force wait until dvbhdhomerun-utils has completed
#at which time it emits dvbhdhomerun
#start on (local-filesystems and net-device-up and started udev-finish)
start on dvbhdhomerun
stop on runlevel [!2345]

expect fork
respawn

#Added an extra 30 second wait before starting tvheadend, as the userhdhomerun
#process in dvbhdhomerun-utils needs to finish completely for tuner discovery

script

sleep 30
followed by existing code

end script

My problem is in trying to stop the service:

stop tvheadend = hang at command prompt. The service never stops.
kill (pid of tvheadend) = works but respawns (as it should)

My biggest problem is that when I reboot my tvheadend server, it hangs at "Asking all other services to terminate"
This fails after 2 to 5 minutes and only then the server reboots.
If I uninstall tvheadend, the server reboots within 2 seconds after giving the reboot command.

If I do the following, tvheadend stops correctly instead of hanging:

stop dvbhdhomerun-utils
stop tvheadend

Server now reboots instantly when asked to.
How can I get a graceful but quick reboot?
How can I get "stop tvheadend" to stop tvheadend gracefully and quickly?

Is there any way that if I give the "stop tvheadend" command, I can get the command to first "stop dvbhdhomerun-utils" then "stop tvheadend" ?

For rebooting, is there any way that I can get ubuntu to first stop dvbhdhomerun-utils and then stop tvheadend when restarting the server?

It seems that the "stop on runlevel [!2345]" in the above script is not working, or as a matter of fact, I cannot get the stop tvheadend command to work.

It just hangs and tvheadend continues to run.

Any advice/help appreciated.

Thank You


Replies (9)

RE: Unable to stop tvheadend service - Added by durandal therogue over 5 years ago

1 Year later, still no answer.

I have the same probem, and I cannot imagine we're the only ones.
Is this a known issue, and if not, where can I file a bug/issue report?

RE: Unable to stop tvheadend service - Added by Adam Sutton over 5 years ago

Not a known issue, works just fine here.

Adam

RE: Unable to stop tvheadend service - Added by durandal therogue over 5 years ago

I found more people experiencing the same problem, Adam, in the other thread: https://tvheadend.org/boards/14/topics/3368?r=10147

Any way, I tracked this problem down. I'll bet all people with problems have a delay >0 set in the /etc/default/tvheadend configuration file, and those who don't, don't.

My system is Ubuntu 12.04 LTS x64 server.

Here is what happens:

  1. the delay in the /etc/default/tvheadend config file is set to non-zero,
  2. causing the sleep command to be executed in the /etc/init/tvheadend.conf upstart file,
  3. causing an extra process to be spawned before the upstart file exits,
  4. causing upstart to reference a lower PID (the sleep process) than the actual tvheadend process,
  5. causing upstart to try to kill the lower, now non-existent, process and lock up when it receives a stop command or when the server shuts down.

Solution:

Since the sleep command is the direct cause, either set sleep time to zero in the config file, or remove the sleep reference line in the upstart file.
I opt for the latter option, so no future misstakes:

Comment the line with sleep out in /etc/init/default.conf upstart file, or delete the line.

#  [ ! -z "$TVH_DELAY" ] && sleep $TVH_DELAY

But apparently a sleep delay was required since it's in the config file, not?

Any sleep command in an upstart script is usually indicative of a bad design somewhere. Upstart is an event driven system and as such sleeps should not be necessary; a job/service starts when all dependencies are met.

In my case, I am running HDHomerun tuners, which has some software started with an upstart script also. When that is done, TVHeadend can start. So, lets tell that to the upstart script.

Change /etc/init/tvheadend.conf

#start on (local-filesystems and net-device-up and started udev-finish)
start on dvbhdhomerun

Done. Problem fixed after a (hard) reboot.

references:
http://upstart.ubuntu.com/cookbook/#id160
http://stackoverflow.com/questions/12610335/how-to-set-environment-variable-in-pre-start-in-upstart-script

I found the issue manager and created a bug report:
https://tvheadend.org/issues/1888

If you want more info just ask, and finally thanks for this cool piece of software ;)

RE: Unable to stop tvheadend service - Added by Rog Konti almost 5 years ago

I think the reason why the delay is used, is because of the definition of "started". The proces started by dvbhdhomerun stars and emits rather fast. It does so before it had the time to initialize. That's why you can't depend on the "start on".

RE: Unable to stop tvheadend service - Added by Robert Barbiaux almost 5 years ago

same problem here, solved by adding a delay in dvhdhomerun init (in the post-start script) :
modify /etc/init/dvbhdhomerun-utils.conf

...
post-start script
    sleep 20
    initctl emit dvbhdhomerun
end script

Problem fixed after reboot :)

RE: Unable to stop tvheadend service - Added by Rog Konti almost 5 years ago

How long does it take for your system to shutdown?

RE: Unable to stop tvheadend service - Added by Robert Barbiaux almost 5 years ago

It's takes less than 10 seconds (my hardware : Intel NUC DN2820, HDHomeRun HDHR3-EU).
Before tweaking (and with a delay specified in tvheadend defaults), it took more than a minute.

RE: Unable to stop tvheadend service - Added by Rog Konti almost 5 years ago

Robert Barbiaux wrote:

It's takes less than 10 seconds (my hardware : Intel NUC DN2820, HDHomeRun HDHR3-EU).
Before tweaking (and with a delay specified in tvheadend defaults), it took more than a minute.

Wow, i'm having troubels with this now for months! Would you mind sharing some more details about your configuration?
Maybe share your dvbhdhomerun-utils.conf, tvheadend.conf and maybe other tweaks you've done?

RE: Unable to stop tvheadend service - Added by Robert Barbiaux almost 5 years ago

I'm using tvheadend 3.4.2 and dvbhdhomerun 0.0.16 over lubuntu 14.10.
durandal's analysis is essentially correct, the problem is (well, was for me) with the sleep call in tvheadend init script that breaks init pid handling, so in /etc/default/tvheadend, make sure the delay is set to "" (the default value) :

# TVH_DELAY 
#   if set startup will be delayed N seconds to allow hardware init
TVH_DELAY="" 

If you added sleep elsewhere in tvheadend.conf (e.g. the start script), just remove it.

The only tweak required (that is, in my setup...) is to add some delay after dvbhdhomerun start, so I added it in the post-start script in /etc/init/dvbhdhomerun-utils.conf :

post-start script
    sleep 20
    initctl emit dvbhdhomerun
end script

I attached my complete files just in case,
hope this helps.

    (1-9/9)