liske/needrestart

Question: set /var/run/reboot-required by DPkg::Post-Invoke for deferred services

Opened this issue · 5 comments

I am using Ubuntu 20.04 with unattended-upgrade & needrestart on various (productive and semi-productive) hosts.

Especially these "semi-productive" servers or redundant systems can be restarted frequently. Therefore, these systems should update themselves as autonomously as possible (with appropriate monitoring, of course).

I know that various services/units cannot be restarted automatically by needrestart, but maybe there is a workaround? My idea was to invoke a simple shell-script in /etc/apt/apt.conf.d/100if-deferred-set-reboot-required:

DPkg::Post-Invoke {"/usr/local/sbin/checkneedrestart.sh";};
#!/bin/sh

# if nagios check for needrestart is not OK and
# /var/run/reboot-required is not already set,
# create /var/run/reboot-required
needrestart -p 2>&1 >/dev/null
retVal=$?
if [ $retVal -ne 0 -a ! -f /var/run/reboot-required ]; then
    touch /var/run/reboot-required
fi

Is this a bad idea or not even possible?

Best
Helge

This seems to work OK. When unattended-upgrade runs and triggers package installs, the new post-invoke writes the reboot-required and then unattended-upgrade triggers the reboot.

I named the file 99needrestart-reboot, as I don't think 100if-* will do what you want - they are executed in alphabetical order, so 100 comes before 11.

liske commented

This sounds like a valid approach. The script could even be shortened:

#!/bin/sh

# if nagios check for needrestart is not OK and
# /var/run/reboot-required is not already set,
# create /var/run/reboot-required
if [ ! -f /var/run/reboot-required ]; then
    needrestart -p 2>&1 || exec touch /var/run/reboot-required
fi

Would this make a good built-in feature for needrestart?

I've had it running for a few weeks now and don't see any problems. Thank you for pointing out the alphabetical sorting. I had not considered that.

An inclusion in the normal version would be great, sure. Of course with a configurable toogle switch.

liske commented

Would this make a good built-in feature for needrestart?

Maybe. I wonder under which conditions (depending on the run mode, kernel and microcode status etc.) the reboot-required should be set or how to make the condition configurable to match all use cases.