Ubuntu Apt Which Services Should Be Restarted
When installing packages (sudo apt install -y
…) in Ubuntu Linux, you may get a prompt to select “Which services should be restarted?”. This can keep scripts from executing successfully, instead causing them to hang perpetually, waiting for user input.
This can be fixed by going to the needrestart config file anf editing the $nrconf{restart}
line to:
$nrconf{restart} = 'l';
The default value of i
is to interactively ask the user, a
is to auto-restart, and l
is to simply list the services.
This can be changed via a script using sed
:
sed -i "s/$nrconf{restart} = 'i';/$nrconf{restart} = 'l';/" /etc/needrestart/needrestart.conf
It’s also possible to set the environment variable NEEDRESTART_MODE to l or a, or NEEDRESTART_SUSPEND to 1.
Some other prompts may need the DEBIAN_FROTNEND environment variable to be set to noninteractive to work from within a script.
sudo NEEDRESTART_MODE=l apt install -y ...
If it annoys you to do this each time, you can also remove the needrestart package entirely with:
sudo apt remove -y needrestart