[mythtv-users] anacron time change after upgrade to Ubuntu 18.04

Stephen Worthington stephen_agent at jsw.gen.nz
Wed Nov 7 16:43:28 UTC 2018


On Wed, 7 Nov 2018 06:45:17 -0500, you wrote:

>
>On 11/6/18 9:59 AM, Stephen Worthington wrote:
>> On Tue, 6 Nov 2018 09:39:12 -0500, you wrote:
>>
>>> On 11/6/18 7:46 AM, Stephen Worthington wrote:
>>>> On Tue, 6 Nov 2018 06:59:31 -0500, you wrote:
>>>>
>>>>> On my backend I have 2 cron jobs I put into /etc/cron.daily for database
>>>>> backup and optimization. The scripts email when done with the date and time.
>>>>>
>>>>> On Ubuntu 16.04 it ran around 7:35 am. After the 'do-release-upgrade' it
>>>>> runs at 12:10 am.
>>>>>
>>>>> I always wondered why 7:35am with a /etc/crontab entry like the one
>>>>> below, but I really can't figure out 12:10 am based on it.
>>>>>
>>>>> Any ideas?
>>>>>
>>>>> 25 6    * * *    root    test -x /usr/sbin/anacron || ( cd / &&
>>>>> run-parts --report /etc/cron.daily )
>>>>>
>>>>> Jim A
>>>> If you read that crontab code carefully, you will see that what it is
>>>> doing is testing to see if an anacron executable is present, and if
>>>> so, it does not run the cron.daily tasks from crontab.  As Ubuntu does
>>>> have an anacron executable present, those crontab entries do nothing,
>>>> and it is left to anacron to run the /etc/cron.daily, /etc/cron.weekly
>>>> and /etc/cron.monthly tasks.  The /etc/cron.hourly tasks, however are
>>>> run from crontab.
>>>>
>>>> In Ubuntu 18.04, anacron is now run from systemd.  There are two
>>>> systemd units:
>>>>
>>>> /lib/systemd/system/anacron.service
>>>> /lib/systemd/system/anacron.timer
>>>>
>>>> The main unit that actually runs anacron is anacron.service.  The
>>>> anacron.service unit is run when the PC starts up (as long as mains
>>>> power is available) and when it wakes up from a sleep mode.  The
>>>> anacron.timer unit runs anacron.service every hour, and
>>>> anacron.service runs anacron.  Here is what is in those two unit
>>>> files:
>>>>
>>>> root at mypvr:/lib/systemd/system# cat anacron.service
>>>> [Unit]
>>>> Description=Run anacron jobs
>>>> After=time-sync.target
>>>> ConditionACPower=true
>>>> Documentation=man:anacron man:anacrontab
>>>>
>>>> [Service]
>>>> ExecStart=/usr/sbin/anacron -dsq
>>>> IgnoreSIGPIPE=false
>>>>
>>>> [Install]
>>>> WantedBy=multi-user.target
>>>> root at mypvr:/lib/systemd/system# cat anacron.timer
>>>> [Unit]
>>>> Description=Trigger anacron every hour
>>>>
>>>> [Timer]
>>>> OnCalendar=hourly
>>>> RandomizedDelaySec=5m
>>>> Persistent=true
>>>>
>>>> [Install]
>>>> WantedBy=timers.target
>>>>
>>>> So in 18.04, you will get the cron.{daily,weekly,monthly} jobs being
>>>> run about 5 minutes after the PC starts up, and after that at about 5
>>>> past midnight.  The 5 minutes bit is because after anacron it started,
>>>> it wait 5 minutes before it does anything.  That is very useful as it
>>>> allows you to kill the anacron task immediately after you reboot your
>>>> MythTV box, so it will then run anacron at the usual time instead of
>>>> immediately.  You only need to kill anacron if the day has changed
>>>> since anacron was last run, as anacron uses timestamps stored in files
>>>> in /var/spool/anacron to tell it when its jobs were last run and will
>>>> not run them again on the same day (or week or month).  The time that
>>>> anacron gets run at has a variable extra delay of up to 5 minutes
>>>> because of the "RandomizedDelaySec=5m" line in anacron.timer.  So
>>>> anacron will run its tasks 5 minutes after boot, and 5-10 minutes
>>>> after the hour after the day changes ie 5-10 minutes after midnight.
>>>>
>>>> In earlier Ubuntu versions, before anacron was run from systemd, it
>>>> was run from cron using the file /etc/cron.d/anacron.  That started
>>>> anacron at 07:30.  Now, the /etc/cron.d/anacron file will only run
>>>> anacron if systemd is not being used.
>>>>
>>>> I found the change in timing from 07:30 to midnight to be a big
>>>> problem.  I have a huge database, and my backup and database check
>>>> jobs take over half an hour, during which mythfrontend is not very
>>>> usable for long periods.  And if I have more than one recording
>>>> happening, I can get bad recordings.  Since I often have multiple
>>>> recordings happening at midnight, and I am also likely to be watching
>>>> a programme, it was very annoying to have anacron running then.  So I
>>>> have changed anacron back to being run at 07:30 only.  I consider that
>>>> anacron being run every hour is actually a bug - it does not run the
>>>> cron.hourly jobs, so it only needs to be run once a day.
>>>>
>>>> To change it back to how it used to be, I created a systemd override
>>>> file for anacron.timer:
>>>>
>>>> root at mypvr:/etc/systemd/system# ll -d ana*
>>>> drwxr-xr-x 2 root root 4096 Oct 21 01:13 anacron.timer.d/
>>>> root at mypvr:/etc/systemd/system# cd anacron.timer.d/
>>>> root at mypvr:/etc/systemd/system/anacron.timer.d# ll
>>>> total 12
>>>> drwxr-xr-x  2 root root 4096 Oct 21 01:13 ./
>>>> drwxr-xr-x 27 root root 4096 Oct 23 23:45 ../
>>>> -rw-r--r--  1 root root  166 Oct 21 01:13 anacron-timer-override.conf
>>>> root at mypvr:/etc/systemd/system/anacron.timer.d# cat
>>>> anacron-timer-override.conf
>>>> [Unit]
>>>> Description=Trigger anacron at 07:30, as happened before the Ubuntu
>>>> 18.04 upgrade.
>>>>
>>>> [Timer]
>>>> OnCalendar=
>>>> OnCalendar=07:30
>>>> RandomizedDelaySec=0s
>>>> Persistent=true
>>>>
>>>> If you want to create an override file like mine, the easy way is to
>>>> do this command:
>>>>
>>>> sudo systemctl edit anacron.timer
>>>>
>>>> and paste my override file into it.  The systemctl edit command is
>>>> only available in newer versions of systemd, but it is very useful as
>>>> it sets up the override directory and .conf file with the right
>>>> ownership and permissions automatically.
>>>>
>>>> I have filed a bug report about this problem, but I have not had any
>>>> response to it yet:
>>>>
>>>> https://bugs.launchpad.net/ubuntu/+source/anacron/+bug/1799361
>>>
>>> This is a great explanation and very helpful.  I've duplicated what you
>>> did and will look for the changes to take affect tomorrow.
>>>
>>> Thanks,
>>>
>>> Jim A
>> You can check to see what is going to happen by using:
>>
>> sudo systemctl status anacron.timer
>> sudo systemctl status anacron
>
>Well something went wrong. Both jobs ran a 12:07AM install of 7:35AM.
>
>It's now about 6:35AM.
>
>I just ran the 2 systemctl commands and their output is below:
>
>jim at mythbuntu:~$*sudo systemctl status anacron.timer*
>[sudo] password for jim:
>? anacron.timer - Trigger anacron at 07:30, as happened before the Ubuntu
>    Loaded: loaded (/lib/systemd/system/anacron.timer; bad; vendor 
>preset: enable
>   Drop-In: /etc/systemd/system/anacron.timer.d
>            ??override.conf
>    Active: active (waiting) since Tue 2018-11-06 15:36:31 EST; 15h ago
>   Trigger: Wed 2018-11-07 07:01:40 EST; 24min left
>
>Nov 06 15:36:31 mythbuntu systemd[1]: Started Trigger anacron at 07:30, 
>as happe
>Nov 07 06:37:18 mythbuntu systemd[1]: 
>/etc/systemd/system/anacron.timer.d/overri
>jim at mythbuntu:~$
>jim at mythbuntu:~$ *sudo systemctl status anacron*
>? anacron.service - Run anacron jobs
>    Loaded: loaded (/lib/systemd/system/anacron.service; enabled; vendor 
>preset:
>    Active: inactive (dead) since Wed 2018-11-07 06:05:27 EST; 33min ago
>      Docs: man:anacron
>            man:anacrontab
>   Process: 7771 ExecStart=/usr/sbin/anacron -dsq (code=exited, 
>status=0/SUCCESS)
>  Main PID: 7771 (code=exited, status=0/SUCCESS)
>
>Nov 07 06:05:27 mythbuntu systemd[1]: Started Run anacron jobs.
>Nov 07 06:05:27 mythbuntu anacron[7771]: Anacron 2.3 started on 2018-11-07
>Nov 07 06:05:27 mythbuntu anacron[7771]: Normal exit (0 jobs run)
>jim at mythbuntu:~$
>
>I got some advice from the Ubuntu forum to not use anacron for precise 
>timing stuff but use cron.  I've haven't explored what that person meant.
>
>"That doesn't alter anacron's behavior of only supporting 24 hour 
>resolution in jobs.
>
>If you need control to the minute, use cron."
>
>Jim A

Anacron is still being run every hour, according to the results of the
status commands.  So it looks like the systemctl edit command did not
do everything necessary for the new override to take effect.  Please
do these commands and see if anacron.timer is then scheduled for
07:30:

sudo systemctl stop anacron.timer
sudo systemctl daemon-reload
sudo systemctl start anacron.timer
sudo systemctl status anacron.timer
sudo systemctl status anacron


More information about the mythtv-users mailing list