From MythTV Official Wiki
Jump to: navigation, search

When enabling unattended-upgrades on a machine running MythTV, a decision has to be made when to allow the upgrades to take place. If mythbackend were to be upgraded whilst a recording was taking place, the recording would be stopped.

If the machine runs 24/7, then, for instance, the output of mythtv-status could be parsed and the upgrade allowed if the next recording was not planned in the next x minutes.

If the machine is allowed to shutdown and wakeup between recordings, then the obvious solution is to upgrade before shutting down.

However, when I simply enabled the "upgrade on shutdown" option in unattended-upgrades, the shutdown was not delayed, and thus took place in the middle of the upgrade, requiring the upgrade to be fixed manually.

Therefore, I created the following at /usr/bin/shutdown-after-upgrade.sh

/usr/bin/mythtv-status --email root --email-only-on-alert
# if we upgraded something, then reboot
# can't just grep for 'No packages', this doesn't catch blacklisted packages
/usr/bin/unattended-upgrade -d | grep -Eq 'Packages that will be upgraded: $|No packages'
if [ $? -eq 0 ]
 # Give it 60s to email the log from unattended-upgrades
 /sbin/shutdown -h
 /sbin/shutdown -r

I found that some upgrading some packages (particularly kernel packages) messed up the wake-up time in the BIOS, so the above restarts the machine if anything was upgraded. Obviously, if it were clear that only kernel packages caused this problem, then the script could be refined appropriately.

I added /usr/bin/shutdown-after-upgrade.sh to /etc/sudoers

The above initially only worked for packages from the Ubuntu repositories. In order to include the packages from the MythTV PPA on launchpad, I editted /etc/apt/apt.conf.d/50unattended-upgrades and added




I discovered the above by looking in /var/lib/apt/lists/ppa.launchpad.net_mythbuntu_0.29_ubuntu_dists_xenial_InRelease, and picking out the Origin: line.

Obviously and finally, /usr/bin/shutdown-after-upgrade.sh has to be used in mythtv-setup or mythwelcome -s as the command to shutdown the machine.