Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
derhelge opened this issue Feb 17, 2022 · 5 comments
Labels

Comments

@derhelge
Copy link

derhelge commented Feb 17, 2022

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

@hmoffatt
Copy link

hmoffatt commented Mar 16, 2022

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 liske added the question label Mar 16, 2022
@liske
Copy link
Owner

liske commented Mar 16, 2022

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

@hmoffatt
Copy link

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

@derhelge
Copy link
Author

derhelge commented Mar 16, 2022

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
Copy link
Owner

liske commented May 16, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants