<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 24, 2019 at 7:20 AM Daryl McDonald <<a href="mailto:darylangela@gmail.com">darylangela@gmail.com</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"><div dir="auto"><br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Wed, Apr 24, 2019, 1:21 AM Stephen Worthington <<a href="mailto:stephen_agent@jsw.gen.nz" target="_blank">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 Tue, 23 Apr 2019 22:28:26 -0400, you wrote:<br>
<br>
>On Tue, Apr 23, 2019 at 8:44 PM <a href="mailto:jam@tigger.ws" rel="noreferrer" target="_blank">jam@tigger.ws</a> <<a href="mailto:jam@tigger.ws" rel="noreferrer" target="_blank">jam@tigger.ws</a>> wrote:<br>
><br>
>><br>
>><br>
>> On 24 Apr 2019, at 4:24 am, <a href="mailto:mythtv-users-request@mythtv.org" rel="noreferrer" target="_blank">mythtv-users-request@mythtv.org</a> wrote:<br>
>><br>
>><br>
>> Having the script in /etc/cron.daily doesn't seem to be functional, I'd<br>
>> like to have the database optimize itself just before the nightly<br>
>> auto-shutdown. What is a good way to accomplish this?  It's mythtv fixes<br>
>> 0.29 on Ubuntu desktop 18.04.  TIA  Daryl<br>
>><br>
>><br>
>> You say having the script in /etc/cron.daily is not functional, but you<br>
>> haven't entirely explained what you mean by that.<br>
>><br>
>><br>
>> I’ve run mythtv for many years<br>
>> I’ve some thousands of videos<br>
>> I’ve some tens of recordings and some 100s of deleted<br>
>> I’ve never run optimise.<br>
>><br>
>> I ran optimise and it completed in 15 odd seconds, so why not have<br>
>>  an ordinary reboot cron entry?<br>
>><br>
>> James<br>
>> ______________________________________<br>
>><br>
><br>
>After a few days of normal use, I start seeing momentary freeze ups in<br>
>playback, while the optimize script is in cron.daily. Running it from the<br>
>terminal clears things up, doing it automatically, after the days<br>
>recordings would be ideal.<br>
<br>
If the optimize_db (database optimise/repair) or mythtv-database<br>
(database backup) scripts are allowed to run at the same time as you<br>
are playing something in mythfrontend, then you can get significant<br>
slowdown in the response times from mythfrontend, and in the worst<br>
case you can get playback pauses.  It depends on the size of the<br>
database, and what is stored where.  If you are trying to play a<br>
recording that is on the same disk as the database, you will get the<br>
worst effects.  With a huge database like mine, you can get problems<br>
with recordings as well.  If I have more than one recording running<br>
while those scripts are running, I will get damaged recordings.  I am<br>
not sure of the exact mechanism, but it may be due to writes to the<br>
database (especially to the recordedseek table) not working properly.<br>
<br>
Since my MythTV box is on 24x7, I have scheduled the scripts to run at<br>
a time when I will never be watching anything and when it is very<br>
unlikely that there will be more than one recording happening.  In<br>
Ubuntu 18.04, that required that I fix a bug that changed when anacron<br>
was running things - they started being run just after midnight, which<br>
is often a time when I have several recordings happening.  Anacron<br>
used to be run at a much better time, 07:30, in older versions of<br>
Ubuntu.<br>
<br>
Originally, anacron was run from the /etc/cron.d/anacron script.  That<br>
script still exists and is still run at 07:30, but does nothing as it<br>
now has a check to see if systemd is being used and if so it exits<br>
without running anacron.  In Ubuntu 18.04, anacron is now run from<br>
these two systemd units:<br>
<br>
/lib/systemd/system/anacron.timer<br>
/lib/systemd/system/anacron.service<br>
<br>
The anacron.timer unit runs the anacron.service unit once per hour,<br>
with a randomised 5 minute delay.  The anacron program itself does a 5<br>
minute delay before it does anything, and it also checks to see if it<br>
has already been run today before it runs the daily scripts (and<br>
similarly for the weekly and monthly scripts).  It does that by<br>
storing the last time it ran those scripts in files in<br>
/var/spool/anacron (cron.daily, cron.weekly, cron.monthly).<br>
<br>
The net result is that in Ubuntu 18.04 (and later???) anacron normally<br>
gets run once per hour and it will normally only do its daily tasks<br>
the first time it is run on any given day.  If the PC is running 24x7,<br>
that means anacron is run at a time randomly selected within 5 minutes<br>
after midnight, and 5 minutes after it is started it will run the<br>
daily scripts in /etc/cron.daily.  If your PC is not on 24x7, the<br>
first time it is booted after midnight, anacron will be started after<br>
a randomised delay of up to 5 minutes after it boots, and it will then<br>
delay 5 minutes before it runs the daily scripts.  That is not a good<br>
way to run optimize_db and mythtv-database, as it means they will<br>
normally be run while a recording is happening, or while you are<br>
trying to watch a recording.<br>
<br>
To make anacron work the same way it used to in earlier versions of<br>
Ubuntu, you need to override the anacron.timer file with a systemd<br>
override file.  The easy way to do that now is to do this command:<br>
<br>
sudo systemctl edit anacron.timer<br>
<br>
which will bring up your system editor to create a file in<br>
/etc/systemd/system/anacron.timer.d.  In that file, put something like<br>
what I have:<br>
<br>
[Unit]<br>
Description=Trigger anacron at 09:30.<br>
<br>
[Timer]<br>
OnCalendar=<br>
OnCalendar=09:30<br>
RandomizedDelaySec=0s<br>
Persistent=true<br>
<br>
I have chosen to run anacron at 09:30 daily, as that is an even better<br>
time for me than the original 07:30.  You can choose any time you like<br>
in the above settings, and anacron will be run at that exact time.<br>
When anacron runs, it will delay doing anything by its usual 5<br>
minutes.<br></blockquote></div></div></blockquote><div><br></div><div>I just removed the system event and implemented this fix, usually my system starts for the 6pm news and records at will untill 11pm, the box logs on automatically, so it is ready for us in the evenings and I log off before retiring for the night. There is normally a gap between 7 amd 8 pm so I chose 19:30 for anacron.</div><div><br></div><div>   /etc/systemd/system/anacron.timer.d/.#override.confd50a7936adc6c1fe           </div><div><br></div><div>[Unit]</div><div><br></div><div>Description=Trigger anacron at 19:30</div><div><br></div><div><br></div><div>[Timer]</div><div>OnCalendar=</div><div>OnCalendar=19:30</div><div>RandomizedDelaySec=0</div><div>Persistent=true</div><div> </div><div>When I wrote out I wasn't offered the path I expected (/etc/systemd/system/anacron.timer.d.) rather an alpha/numeric sequence, I now suspect they were the tailing sequence: (#override.confd50a7936adc6c1fe)</div><div><br></div><div>I'll know if this is indeed the solution in a week or so by the presence or absence of momentary freeze ups. Thanks to all!</div></div></div></div></div></div>