45

I have newly installed Ubuntu 22.04 LTS recently and I found that every time when I using apt to install or update packages, it will ask me about Which service should be restarted ?, I don't konw which should be restared and actually I don't want to restart any service when I'm using it.

This annoys me and I want to know how to disable this when using apt in Ubuntu 22?

enter image description here

hash070
  • 641
  • 1
  • 3
  • 8

1 Answers1

57

This is new in Ubuntu 22.04. The trouble in this case is with the needrestart command, which is part of the apt-get upgrade process in Ubuntu now. 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.

Source: https://askubuntu.com/questions/1367139/apt-get-upgrade-auto-restart-services

Tobias
  • 812
  • 4
  • 7
  • Doesn't sound like as if scripts are interrupted because of that: `# ATTENTION: If needrestart is configured to run in interactive mode but is run # non-interactive (i.e. unattended-upgrades) it will fallback to list only mode.` (Comment is from needrestart.conf) – René K Sep 15 '22 at 08:30
  • 2
    Here's the command that you are looking for: `sed "/#\$nrconf{restart} = 'i';/s/.*/\$nrconf{restart} = 'a';/" /etc/needrestart/needrestart.conf` – Raphael Setin Dec 02 '22 at 03:27
  • 9
    I forgot to add the `-i` in the sed command in order to automatically edit the file instead of outputting the result to the standard output. So the entire command would be: `sed -i "/#\$nrconf{restart} = 'i';/s/.*/\$nrconf{restart} = 'a';/" /etc/needrestart/needrestart.conf` – Raphael Setin Dec 05 '22 at 20:54