Ubuntu – How does apt upgrade running programs

apt

I wonder how apt upgrade does upgrade running programs.

Does it wait until the program terminates?

Does it simply overwrite the files while the program is running? Doesn't this interfere the running program?

And what about shared libraries?

Best Answer

Does it wait until the program terminates?

Maybe, depending on the package.

Does it simply overwrite the files while the program is running? Doesn't this interfere the running program?

It can, depending on the program and the files.

And what about shared libraries?

It depends on whether it has been loaded into memory yet. https://stackoverflow.com/a/7767402/1212596


Full answer

Apt (actually, the underlying dpkg) runs scripts when uninstalling and installing a package. If the package includes a long-running program (daemon), it is usually stopped when the old version of the package is removed, and started when the new version of the package is installed.

preinst This script is executed before the package it belongs to is unpacked from its Debian archive (".deb") file. Many 'preinst' scripts stop services for packages which are being upgraded until their installation or upgrade is completed (following the successful execution of the 'postinst' script).

postinst This script typically completes any required configuration of the package foo once foo has been unpacked from its Debian archive (".deb") file. Often, 'postinst' scripts ask users for input, and/or warn them that if they accept default values, they should remember to go back and re-configure that package as needed. Many 'postinst' scripts then execute any commands necessary to start or restart a service once a new package has been installed or upgraded.

prerm This script typically stops any daemons which are associated with a package. It is executed before the removal of files associated with the package.

postrm This script typically modifies links or other files associated with foo, and/or removes files created by the package. (Also see What is a Virtual Package?, Section 7.8.)

https://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.en.html

It is of course up to the package maintainer to start and stop services in postinst and prerm.

Related Question