APT Upgrade – How to Manually Restart Services Affected by APT Upgrades

aptpostgresqlrestartservicesupgrade

How can I issue apt upgrades without automatically stopping/starting daemons? I'd like to manually restart services.

To cite a specific example:

I'll revisit a long-running machine and run sudo apt-get update && time sudo apt-get dist-upgrade. This is a very straight-forward means of seeing all available upgrades, followed by a simple Enter keypress to get the systems fully patched.

If I see postgresql-9.1 in the upgrade list, I abort the upgrade. In that case, apt would stop the service early in the process, apply several non-critical operations, then restart the service much later. A routine upgrade could cause minutes of downtime.

I'd like to say "yes" to the upgrade to get all patches applied, then manually restart the service at a convenient time.

Best Answer

You can prevent service restarts with the Debian policy layer which works on Ubuntu as well.

Example: Create a file named /usr/sbin/policy-rc.d with following content (don't forget to make the file executable):

#!/bin/sh

exit 101

No serviceĀ¹ would be automatically started/stopped/restarted anymore. See /usr/share/doc/sysv-rc/README.policy-rc.d.gz for details and how to adjust it to just ignore a single service.

1. as long as the installation scripts follow the Debian guidelines and use invoke-rc.d for service restarts

Related Question