Reboot if any updates were applied

Asked by R. Diez

Is there a way to find out whether any package has bee updated? I do not trust the system after an update, I want to reboot if some package has been updated, even if the systems thinks a reboot is not necessary.

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu unattended-upgrades Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

You can grep /var/log/dpkg.log and perform logic based on the date / time your selected package name(s) were installed

You may want to compare that to the system boot time to see if it has been rebooted since the installation. You can see the date and time of boot with:

dmesg -T | head -n 1 | cut -d"]" -f 1 | cut -c 2-

SHould give you a solid starting point

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#2

grep grep /var/log/dpkg.log

may give this

2015-08-05 05:11:53 install grep:amd64 <none> 2.16-1
2015-08-05 05:11:53 status half-installed grep:amd64 2.16-1
2015-08-05 05:11:53 status unpacked grep:amd64 2.16-1
2015-08-05 05:11:53 status unpacked grep:amd64 2.16-1
2015-08-05 05:12:04 configure grep:amd64 2.16-1 <none>
2015-08-05 05:12:04 status unpacked grep:amd64 2.16-1
2015-08-05 05:12:04 status half-configured grep:amd64 2.16-1
2015-08-05 05:12:04 status installed grep:amd64 2.16-1

You can then use awk, cut and grep to hack the dates out and compare. Was your package installed after the reboot, if so then reboot

Revision history for this message
R. Diez (rdiezmail-ubuntu) said :
#3

Using grep and awk is a very poor solution. Such logic is actually hard to implement, as log output is not well documented, and rather brittle, if the log messages happen to change in next version. Is there no other way?

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#4

What would be a better solution in your opinion? The logs show exactly when packages were installed so grep and awk are ideal here as the logs are text.....

Revision history for this message
R. Diez (rdiezmail-ubuntu) said :
#5

I already explained why a grep/awk solution is never ideal.

A better solution would be something programmatic, like some hook. For example, a special file is created to indicate that the system needs a reboot after an update. I could not find anything in the documentation though about any indication that something was updated, or that some script should be run after an update.

If there is no proper implementation, it is best to acknowledge this fact. I would then create a bug for an enhancement.

Can you help with this problem?

Provide an answer of your own, or ask R. Diez for more information if necessary.

To post a message you must log in.