<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 12, 2019 at 4:10 AM Stephen Worthington <<a href="mailto:stephen_agent@jsw.gen.nz">stephen_agent@jsw.gen.nz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, 11 Jul 2019 12:14:49 -0700, you wrote:<br>
<br>
>CTRL-ALT-BS is disabled by default but can be enabled with XKBOPTIONS="terminate:ctrl_alt_bksp" in /etc/default/keyboard The problem with CTRL-ALT-BS and Myth is that when the system restarts, a new instance of Myth is created. In testing I could get 10 instances of Myth running.  The solution is to start Myth but not as a service. This change can be made in the GUI by editing the auto start command.<br>
>On my system, CTRL-ALT-BS does the identical thing as systemctl restart lightdm from all outward appearances. I see the same text on the terminal and they both take just a second or so to restart. I have also read that what the CTRL-ALT-BS function does is restart the X session so I don't think just restarting X another way is going to solve the problem. I believe I will still get the 5 minute delay especially considering shutdown now had the delay.<br>
>Any idea what is hanging up the shutdown? More to the point, how do I keep it from doing it?<br>
<br>
I am not sure exactly what you are talking about here - what are you<br>
getting multiple instances of?  "Myth" is not a very specific term.<br>
Mythfrontend on a Ubuntu system is actually the file<br>
"/usr/bin/mythfrontend.real", and is run by a script<br>
"/usr/bin/mythfrontend", which will automatically restart<br>
"/usr/bin/mythfrontend.real" if it crashes.  So when you kill things<br>
(such as using Ctrl-Alt-BS), you have to be careful that the<br>
"/usr/bin/mythfrontend" script gets killed before<br>
"/usr/bin/mythfrontend.real", or the script will start a new copy of<br>
"/usr/bin/mythfrontend.real".  So you may need to modify the script,<br>
or you may need to run "/usr/bin/mythfrontend.real" directly instead<br>
of using the script, and manually restart it when it crashes.<br>
<br>
>Obviously this is a difficult problem to troubleshoot as I have to wait for<br>
>another lock up. But I did a bit of looking and have modified this file<br>
> /etc/systemd/system.conf<br>
>And added this line<br>
>DefaultTimeoutStopSec=4s<br>
>The default is 90 seconds<br>
><br>
>My thought is that there were 3 or 4 things that had to time out so it took<br>
>5 minutes. With this change it might take only 12 to 16 seconds.<br>
><br>
><br>
>Allen<br>
<br>
A good thought.  Mythbackend is one of the things that does not shut<br>
down well when asked to.  It can take quite a while, as systemd waits<br>
for it to shut down, presumably using that timer.  So working out how<br>
to get it to shut down rapidly and modifying its systemd settings for<br>
shutdown would help.  I have suspected for a while that mythbackend<br>
may have the same problem as mythfrontend, and need to be sent two<br>
SIGKILL signals before it will shut down.  But I had never bothered to<br>
test it and find out.  With a bit of searching, I found the "Quickly<br>
terminate mythbackend" section towards the end of this page:<br>
<br>
<a href="https://www.mythtv.org/wiki/Systemd_mythbackend_Configuration" rel="noreferrer" target="_blank">https://www.mythtv.org/wiki/Systemd_mythbackend_Configuration</a><br>
<br>
which suggests a way to send two SIGTERMs (kill -15) to mythbackend.<br>
Based on that, and on this:<br>
<br>
<a href="https://lists.debian.org/debian-user/2016/10/msg00422.html" rel="noreferrer" target="_blank">https://lists.debian.org/debian-user/2016/10/msg00422.html</a><br>
<br>
I did what I think is a better version of that.  I created a<br>
/usr/local/bin/mythbackendstop.sh file:<br>
<br>
#!/bin/bash<br>
PID=$(systemctl show -p MainPID mythtv-backend.service 2>/dev/null |<br>
cut -d= -f2)<br>
if [ "$PID" != "0" ]; then<br>
    kill -15 $PID<br>
    sleep 1<br>
    kill -15 $PID<br>
fi<br>
<br>
(The PID= line is all one long line - my email client wraps long<br>
lines)<br>
<br>
And then added this to my mythtv-backend systemd override.conf file:<br>
<br>
[Service]<br>
ExecStop=/usr/local/bin/mythbackendstop.sh<br>
<br>
It seems to work pretty well, but I have only tested it on my testing<br>
PC so far.<br>
<br>
Having too short a timeout for DefaultTimeoutStopSec can be a problem<br>
though - you do want to things like the MySQL/MariaDB database to be<br>
able to shut down safely when asked to do so, and it will not be asked<br>
to stop until mythbackend has stopped.  So it would probably be better<br>
to identify the things that are not shutting down and are being killed<br>
by the DefaultTimeoutStopSec timer, and then adjusting their systemd<br>
units to stop them properly, rather than using a very small<br>
DefaultTimeoutStopSec value.<br>
_______________________________________________<br><br></blockquote><div><br></div><div>Regarding CTRL-ALT-BS:</div><div>If you let Mythfrontend run as a service you get multiple instances of it after doing a series of CTRL-ALT-BS restarts just as you say. To prevent this, I do not run it as a service. We discussed this in another thread <a href="https://lists.gt.net/mythtv/users/624109">https://lists.gt.net/mythtv/users/624109</a> The bottom line is I do not run mythfrontend with the --service option.</div><div><br></div><div>Regarding shutdown timer:</div><div>The evidence is that the standard shutdown timer is 90 seconds and I am experiencing about 5 minutes for a shutdown. That suggests that there are multiple things hung up and that they are being forced to shutdown in series. I don't see a particular difference between forcing a hung program to shutdown after 90 seconds or 4 seconds. The question then is there a program that will shutdown gracefully and take more than 4 seconds to do so.  The other evidence I have is that doing CTRL-ALT-BS restarts in less than 4 seconds. That suggests that there is not a program that takes longer than 4 seconds to gracefully shutdown and the 4 second timer should be fine.</div><div><br></div><div>Allen</div><div><br></div></div></div>