Score:0

apt-get upgrade auto restart services

cn flag

I have an unattended script for installing servers. At the beginning of the script there is a sudo apt-get dist-upgrade --yes. The dist upgrade has a nasty user input screen at its end asking to restart services:
enter image description here

Is it possible to autoaccept service restarts or disable this screen? It breaks my whole script. Also Im afraid it might leave my server stuck at some point when updating...

same result with apt-get upgrade

edit: I tried without success:

#!/bin/bash
sudo apt-get update
sudo apt-get remove apt-listchanges --assume-yes --force-yes &&

#using export is important since some of the commands in the script will fire in a subshell
export DEBIAN_FRONTEND=noninteractive &&
export APT_LISTCHANGES_FRONTEND=none &&

#lib6c was an issue for me as it ignored the DEBIAN_FRONTEND environment variable and fired a prompt anyway. This should fix it
echo 'libc6 libraries/restart-without-asking boolean true' | debconf-set-selections &&

echo "executing wheezy to jessie" &&
find /etc/apt -name "*.list" | xargs sed -i '/^deb/s/wheezy/jessie/g' &&

echo "executing autoremove" &&
sudo apt-get -fuy --force-yes autoremove &&

echo "executing clean" &&
sudo apt-get --force-yes clean &&

echo "executing update" &&
sudo apt-get update &&

echo "executing upgrade" &&
sudo apt-get --force-yes -o Dpkg::Options::="--force-confold" --force-yes -o Dpkg::Options::="--force-confdef" -fuyq upgrade &&

echo "executing dist-upgrade" &&
sudo apt-get --force-yes -o Dpkg::Options::="--force-confold" --force-yes -o Dpkg::Options::="--force-confdef" -fuyq dist-upgrade
user535733 avatar
cn flag
See `man needrestart`. There are several options that seem to fit your need.
Score:6
cz flag

Alternatively, I think you can remove the needrestart package itself.

sudo apt-get remove needrestart

I am using this for AWS EC2 provisioning on Ubuntu 22.04. For whatever reason, export DEBIAN_FRONTEND=noninteractive did not seem to work.

sarat avatar
cz flag
Yes, this may not be perfect but the only solution worked for me on AWS EC2 instances.
Score:2
rs flag

Instead of using sed or editing the main config, add your own config file in /etc/needrestart/conf.d/no-prompt.conf:

$nrconf{restart} = 'a';
Score:0
dm flag

To add to the edit the /etc/needrestart/needrestart.conf file from JoeShabadu2000 above - you can create a file containing the configuration value to set in /etc/needrestart/conf.d/. All .conf files in that directory are processed. See the README in the folder. Confirmed working in Ubuntu 22.04.

Example to set to list vs interactive:

sudo tee "/etc/needrestart/conf.d/mynrconf.conf" > /dev/null << SHIRT
\$nrconf{restart} = 'l'
SHIRT
Score:0
ca flag

Try sudo DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade --y, it should prevent any of these prompts

ekydfejj avatar
sg flag
This does not solve the problem, i have been using this for eon's and the prompt in 22.04 is different. try the other solutions.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.