Linux : Redémarrage automatique des services après upgrade
De www.yakakliker.org
As others mentioned, the trouble in this case is with the needrestart command, which is part of the apt-get upgrade process in Ubuntu now (specifically 22.04 which is what I am using). By default this is set to "interactive" mode which causes the interruption of scripts.
To change this behavior, we can edit the /etc/needrestart/needrestart.conf file, changing the line:
#$nrconf{restart} = 'i';
to
$nrconf{restart} = 'a'; (if we want to restart the services automatically) or $nrconf{restart} = 'l'; to simply list the services that need restart.
If you are running a script and want to make this edit without using an interactive editor like vim, you can do so using sed, something like:
sudo sed -i 's/#$nrconf{restart} = '"'"'i'"'"';/$nrconf{restart} = '"'"'a'"'"';/g' /etc/needrestart/needrestart.conf
It looks ugly because of the single quotes in the config file and how sed handles single quotes, but it does work. Please leave a comment if you have a better looking approach.
Liens
https://askubuntu.com/questions/1367139/apt-get-upgrade-auto-restart-services